aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2020-10-27 20:48:14 -0700
committerGitHub <noreply@github.com>2020-10-27 20:48:14 -0700
commita6a1722cfa94caa5db98848679b99377bc5a0112 (patch)
tree0f17c63e4a0551866280600e466f21267c8ae1ce
parentc34c4189ebbf0795e1f8e2de562c527a854c8db4 (diff)
downloadvcpkg-a6a1722cfa94caa5db98848679b99377bc5a0112.tar.gz
vcpkg-a6a1722cfa94caa5db98848679b99377bc5a0112.zip
[vcpkg, jsonnet, openssl-uwp] Enable use of the system powershell-core if it is present. (#13805)
-rw-r--r--ports/jsonnet/CONTROL1
-rw-r--r--ports/jsonnet/portfile.cmake5
-rw-r--r--ports/openssl-uwp/CONTROL1
-rw-r--r--ports/openssl-uwp/EnableUWPSupport.patch2
-rw-r--r--scripts/addPoshVcpkgToPowershellProfile.ps16
-rw-r--r--scripts/buildsystems/msbuild/vcpkg.targets41
-rw-r--r--scripts/buildsystems/vcpkg.cmake20
-rw-r--r--scripts/cmake/vcpkg_copy_tool_dependencies.cmake10
-rw-r--r--toolsrc/include/vcpkg/base/files.h13
-rw-r--r--toolsrc/include/vcpkg/tools.h1
-rw-r--r--toolsrc/src/vcpkg-test/files.cpp15
-rw-r--r--toolsrc/src/vcpkg/base/files.cpp33
-rw-r--r--toolsrc/src/vcpkg/build.cpp7
-rw-r--r--toolsrc/src/vcpkg/tools.cpp38
14 files changed, 160 insertions, 33 deletions
diff --git a/ports/jsonnet/CONTROL b/ports/jsonnet/CONTROL
index 99d73af6c..b069a6b1b 100644
--- a/ports/jsonnet/CONTROL
+++ b/ports/jsonnet/CONTROL
@@ -1,5 +1,6 @@
Source: jsonnet
Version: 0.16.0
+Port-Version: 1
Homepage: https://github.com/google/jsonnet
Description: Jsonnet - The data templating language
Build-Depends: nlohmann-json
diff --git a/ports/jsonnet/portfile.cmake b/ports/jsonnet/portfile.cmake
index 77e8b8783..b2769cd85 100644
--- a/ports/jsonnet/portfile.cmake
+++ b/ports/jsonnet/portfile.cmake
@@ -15,8 +15,9 @@ vcpkg_from_github(
)
if(VCPKG_TARGET_IS_WINDOWS)
- vcpkg_execute_required_process(
- COMMAND Powershell -Command "((Get-Content -AsByteStream \"${SOURCE_PATH}/stdlib/std.jsonnet\") -join ',') + ',0' | Out-File -Encoding Ascii \"${SOURCE_PATH}/core/std.jsonnet.h\""
+ find_program(PWSH_PATH pwsh)
+ vcpkg_execute_required_process(
+ COMMAND "${PWSH_PATH}" -Command "((Get-Content -AsByteStream \"${SOURCE_PATH}/stdlib/std.jsonnet\") -join ',') + ',0' | Out-File -Encoding Ascii \"${SOURCE_PATH}/core/std.jsonnet.h\""
WORKING_DIRECTORY "${SOURCE_PATH}"
LOGNAME "std.jsonnet"
)
diff --git a/ports/openssl-uwp/CONTROL b/ports/openssl-uwp/CONTROL
index 6d42b3af0..cdf818e33 100644
--- a/ports/openssl-uwp/CONTROL
+++ b/ports/openssl-uwp/CONTROL
@@ -1,4 +1,5 @@
Source: openssl-uwp
Version: 1.1.1h
+Port-Version: 1
Description: OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.
Supports: uwp
diff --git a/ports/openssl-uwp/EnableUWPSupport.patch b/ports/openssl-uwp/EnableUWPSupport.patch
index d534b9b4a..4313220f1 100644
--- a/ports/openssl-uwp/EnableUWPSupport.patch
+++ b/ports/openssl-uwp/EnableUWPSupport.patch
@@ -54,7 +54,7 @@ index d478f42b0f..e0fb70daca 100644
+my $UWP_info = {};
+sub UWP_info {
+ unless (%$UWP_info) {
-+ my $SDKver = `powershell -Command \"& {\$(Get-Item \\\"hklm:\\SOFTWARE\\WOW6432Node\\Microsoft\\Microsoft SDKs\\Windows\\\").GetValue(\\\"CurrentVersion\\\")}\"`;
++ my $SDKver = `pwsh.exe -Command \"& {\$(Get-Item \\\"hklm:\\SOFTWARE\\WOW6432Node\\Microsoft\\Microsoft SDKs\\Windows\\\").GetValue(\\\"CurrentVersion\\\")}\"`;
+ $SDKver =~ s|\R$||;
+ my @SDKver_split = split(/\./, $SDKver);
+ # SDK version older than 10.0.17763 don't support our ASM builds
diff --git a/scripts/addPoshVcpkgToPowershellProfile.ps1 b/scripts/addPoshVcpkgToPowershellProfile.ps1
index 1dd27aacf..185f658c9 100644
--- a/scripts/addPoshVcpkgToPowershellProfile.ps1
+++ b/scripts/addPoshVcpkgToPowershellProfile.ps1
@@ -16,7 +16,7 @@ function findExistingImportModuleDirectives([Parameter(Mandatory=$true)][string]
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
$profileEntry = "Import-Module '$scriptsDir\posh-vcpkg'"
-$profilePath = $PROFILE # Implicit powershell variable
+$profilePath = $PROFILE # Implicit PowerShell variable
$profileDir = Split-Path $profilePath -Parent
if (!(Test-Path $profileDir))
{
@@ -33,7 +33,7 @@ if ($existingImports.Count -gt 0)
$existingImportsOut = $existingImports -join "`n "
Write-Host "`nposh-vcpkg is already imported to your PowerShell profile. The following entries were found:"
Write-Host " $existingImportsOut"
- Write-Host "`nPlease make sure you have started a new Powershell window for the changes to take effect."
+ Write-Host "`nPlease make sure you have started a new PowerShell window for the changes to take effect."
return
}
@@ -53,4 +53,4 @@ if (Test-Path $profilePath)
}
Add-Content $profilePath -Value "`n$profileEntry" -Encoding UTF8
-Write-Host "`nSuccessfully added posh-vcpkg to your PowerShell profile. Please start a new Powershell window for the changes to take effect."
+Write-Host "`nSuccessfully added posh-vcpkg to your PowerShell profile. Please start a new PowerShell window for the changes to take effect."
diff --git a/scripts/buildsystems/msbuild/vcpkg.targets b/scripts/buildsystems/msbuild/vcpkg.targets
index a9c339559..5013d764a 100644
--- a/scripts/buildsystems/msbuild/vcpkg.targets
+++ b/scripts/buildsystems/msbuild/vcpkg.targets
@@ -103,18 +103,45 @@
</Target>
<Target Name="AppLocalFromInstalled" AfterTargets="CopyFilesToOutputDirectory" BeforeTargets="CopyLocalFilesOutputGroup;RegisterOutput" Condition="'$(VcpkgEnabled)' == 'true' and '$(VcpkgApplocalDeps)' == 'true'">
+ <Message Text="[vcpkg] Starting VcpkgApplocalDeps" Importance="low" />
<WriteLinesToFile
- File="$(TLogLocation)$(ProjectName).write.1u.tlog"
- Lines="^$(TargetPath);$([System.IO.Path]::Combine($(ProjectDir),$(IntDir)))vcpkg.applocal.log" Encoding="Unicode"/>
+ File="$(TLogLocation)$(ProjectName).write.1u.tlog"
+ Lines="^$(TargetPath);$([System.IO.Path]::Combine($(ProjectDir),$(IntDir)))vcpkg.applocal.log" Encoding="Unicode"/>
+ <PropertyGroup>
+ <_VcpkgAppLocalPowerShellCommonArguments>-ExecutionPolicy Bypass -noprofile -File "$(MSBuildThisFileDirectory)applocal.ps1" "$(TargetPath)" "$(VcpkgCurrentInstalledDir)$(VcpkgConfigSubdir)bin" "$(TLogLocation)$(ProjectName).write.1u.tlog" "$(IntDir)vcpkg.applocal.log"</_VcpkgAppLocalPowerShellCommonArguments>
+ </PropertyGroup>
+ <!-- Search %PATH% for pwsh.exe if it is available. -->
<Exec
- Command="$(SystemRoot)\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -noprofile -File %22$(MSBuildThisFileDirectory)applocal.ps1%22 %22$(TargetPath)%22 %22$(VcpkgCurrentInstalledDir)$(VcpkgConfigSubdir)bin%22 %22$(TLogLocation)$(ProjectName).write.1u.tlog%22 %22$(IntDir)vcpkg.applocal.log%22"
- StandardOutputImportance="Normal">
+ Command="pwsh.exe $(_VcpkgAppLocalPowerShellCommonArguments)"
+ StandardOutputImportance="Normal"
+ StandardErrorImportance="Normal"
+ IgnoreExitCode="true"
+ UseCommandProcessor="false">
+ <Output TaskParameter="ExitCode"
+ PropertyName="_VcpkgAppLocalExitCode" />
</Exec>
- <ReadLinesFromFile File="$(IntDir)vcpkg.applocal.log">
+ <!-- Fall back to well known system PowerShell location otherwise. -->
+ <Message Text="[vcpkg] Failed to run applocal.ps1 using pwsh, falling back to system PowerShell." Importance="low"
+ Condition="$(_VcpkgAppLocalExitCode) == 9009" />
+ <Exec
+ Command="%22$(SystemRoot)\System32\WindowsPowerShell\v1.0\powershell.exe%22 $(_VcpkgAppLocalPowerShellCommonArguments)"
+ StandardOutputImportance="Normal"
+ StandardErrorImportance="Normal"
+ IgnoreExitCode="true"
+ UseCommandProcessor="false"
+ Condition="$(_VcpkgAppLocalExitCode) == 9009">
+ <Output TaskParameter="ExitCode"
+ PropertyName="_VcpkgAppLocalExitCode" />
+ </Exec>
+ <!-- We're ignoring the above exit codes, so translate into a warning if both failed. -->
+ <Warning Text="[vcpkg] Failed to gather app local DLL dependencies, program may not run. Set VcpkgApplocalDeps to false in your project file to suppress this warning. PowerShell arguments: $(_VcpkgAppLocalPowerShellCommonArguments)"
+ Condition="$(_VcpkgAppLocalExitCode) != 0"/>
+ <ReadLinesFromFile File="$(IntDir)vcpkg.applocal.log"
+ Condition="$(_VcpkgAppLocalExitCode) == 0">
<Output TaskParameter="Lines" ItemName="VcpkgAppLocalDLLs" />
</ReadLinesFromFile>
- <Message Text="@(VcpkgAppLocalDLLs,'%0A')" Importance="Normal" />
- <ItemGroup>
+ <Message Text="@(VcpkgAppLocalDLLs,'%0A')" Importance="Normal" Condition="$(_VcpkgAppLocalExitCode) == 0" />
+ <ItemGroup Condition="$(_VcpkgAppLocalExitCode) == 0">
<ReferenceCopyLocalPaths Include="@(VcpkgAppLocalDLLs)" />
</ItemGroup>
</Target>
diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake
index 08d0c8d20..dab5b73a6 100644
--- a/scripts/buildsystems/vcpkg.cmake
+++ b/scripts/buildsystems/vcpkg.cmake
@@ -395,6 +395,20 @@ endif()
option(VCPKG_APPLOCAL_DEPS "Automatically copy dependencies into the output directory for executables." ON)
option(X_VCPKG_APPLOCAL_DEPS_SERIALIZED "(experimental) Add USES_TERMINAL to VCPKG_APPLOCAL_DEPS to force serialization." OFF)
+function(_vcpkg_set_powershell_path)
+ # Attempt to use pwsh if it is present; otherwise use powershell
+ if (NOT DEFINED _VCPKG_POWERSHELL_PATH)
+ find_program(_VCPKG_PWSH_PATH pwsh)
+ if (_VCPKG_PWSH_PATH-NOTFOUND)
+ message(DEBUG "vcpkg: Could not find PowerShell Core; falling back to PowerShell")
+ find_program(_VCPKG_BUILTIN_POWERSHELL_PATH powershell REQUIRED)
+ set(_VCPKG_POWERSHELL_PATH "${_VCPKG_BUILTIN_POWERSHELL_PATH}" CACHE INTERNAL "The path to the PowerShell implementation to use.")
+ else()
+ set(_VCPKG_POWERSHELL_PATH "${_VCPKG_PWSH_PATH}" CACHE INTERNAL "The path to the PowerShell implementation to use.")
+ endif()
+ endif() # _VCPKG_POWERSHELL_PATH
+endfunction()
+
function(add_executable name)
_add_executable(${ARGV})
list(FIND ARGV "IMPORTED" IMPORTED_IDX)
@@ -403,12 +417,13 @@ function(add_executable name)
if(IMPORTED_IDX EQUAL -1 AND ALIAS_IDX EQUAL -1)
if(VCPKG_APPLOCAL_DEPS)
if(_VCPKG_TARGET_TRIPLET_PLAT MATCHES "windows|uwp")
+ _vcpkg_set_powershell_path()
set(EXTRA_OPTIONS "")
if(X_VCPKG_APPLOCAL_DEPS_SERIALIZED)
set(EXTRA_OPTIONS USES_TERMINAL)
endif()
add_custom_command(TARGET ${name} POST_BUILD
- COMMAND powershell -noprofile -executionpolicy Bypass -file ${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1
+ COMMAND "${_VCPKG_POWERSHELL_PATH}" -noprofile -executionpolicy Bypass -file "${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1"
-targetBinary $<TARGET_FILE:${name}>
-installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/bin"
-OutVariable out
@@ -437,8 +452,9 @@ function(add_library name)
if(IMPORTED_IDX EQUAL -1 AND INTERFACE_IDX EQUAL -1 AND ALIAS_IDX EQUAL -1)
get_target_property(IS_LIBRARY_SHARED ${name} TYPE)
if(VCPKG_APPLOCAL_DEPS AND _VCPKG_TARGET_TRIPLET_PLAT MATCHES "windows|uwp" AND (IS_LIBRARY_SHARED STREQUAL "SHARED_LIBRARY" OR IS_LIBRARY_SHARED STREQUAL "MODULE_LIBRARY"))
+ _vcpkg_set_powershell_path()
add_custom_command(TARGET ${name} POST_BUILD
- COMMAND powershell -noprofile -executionpolicy Bypass -file ${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1
+ COMMAND "${_VCPKG_POWERSHELL_PATH}" -noprofile -executionpolicy Bypass -file "${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1"
-targetBinary $<TARGET_FILE:${name}>
-installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/bin"
-OutVariable out
diff --git a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake
index 1784a4d14..681c80461 100644
--- a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake
+++ b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake
@@ -17,16 +17,16 @@
## * [glib](https://github.com/Microsoft/vcpkg/blob/master/ports/glib/portfile.cmake)
## * [fltk](https://github.com/Microsoft/vcpkg/blob/master/ports/fltk/portfile.cmake)
function(vcpkg_copy_tool_dependencies TOOL_DIR)
- find_program(PS_EXE powershell PATHS ${DOWNLOADS}/tool)
- if (PS_EXE-NOTFOUND)
- message(FATAL_ERROR "Could not find powershell in vcpkg tools, please open an issue to report this.")
+ find_program(PWSH_EXE pwsh)
+ if (PWSH_EXE-NOTFOUND)
+ message(FATAL_ERROR "Could not find PowerShell Core; please open an issue to report this.")
endif()
macro(search_for_dependencies PATH_TO_SEARCH)
file(GLOB TOOLS ${TOOL_DIR}/*.exe ${TOOL_DIR}/*.dll)
foreach(TOOL ${TOOLS})
vcpkg_execute_required_process(
- COMMAND ${PS_EXE} -noprofile -executionpolicy Bypass -nologo
- -file ${SCRIPTS}/buildsystems/msbuild/applocal.ps1
+ COMMAND "${PWSH_EXE}" -noprofile -executionpolicy Bypass -nologo
+ -file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1"
-targetBinary ${TOOL}
-installedDir ${PATH_TO_SEARCH}
WORKING_DIRECTORY ${VCPKG_ROOT_DIR}
diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h
index 71e386a5c..607a75c8e 100644
--- a/toolsrc/include/vcpkg/base/files.h
+++ b/toolsrc/include/vcpkg/base/files.h
@@ -234,11 +234,20 @@ namespace vcpkg::Files
void print_paths(const std::vector<fs::path>& paths);
- /// Performs "lhs / rhs" according to the C++17 Filesystem Library Specification.
- /// This function exists as a workaround for TS implementations.
+ // Performs "lhs / rhs" according to the C++17 Filesystem Library Specification.
+ // This function exists as a workaround for TS implementations.
fs::path combine(const fs::path& lhs, const fs::path& rhs);
#if defined(_WIN32)
+ constexpr char preferred_separator = '\\';
+#else
+ constexpr char preferred_separator = '/';
+#endif // _WIN32
+
+ // Adds file as a new path element to the end of base, with an additional slash if necessary
+ std::string add_filename(StringView base, StringView file);
+
+#if defined(_WIN32)
fs::path win32_fix_path_case(const fs::path& source);
#endif // _WIN32
}
diff --git a/toolsrc/include/vcpkg/tools.h b/toolsrc/include/vcpkg/tools.h
index f9618a52d..8f0398a5c 100644
--- a/toolsrc/include/vcpkg/tools.h
+++ b/toolsrc/include/vcpkg/tools.h
@@ -18,6 +18,7 @@ namespace vcpkg
static const std::string GIT = "git";
static const std::string MONO = "mono";
static const std::string NINJA = "ninja";
+ static const std::string POWERSHELL_CORE = "powershell-core";
static const std::string NUGET = "nuget";
static const std::string IFW_INSTALLER_BASE = "ifw_installerbase";
static const std::string IFW_BINARYCREATOR = "ifw_binarycreator";
diff --git a/toolsrc/src/vcpkg-test/files.cpp b/toolsrc/src/vcpkg-test/files.cpp
index 429a4ba15..94cf7e1dd 100644
--- a/toolsrc/src/vcpkg-test/files.cpp
+++ b/toolsrc/src/vcpkg-test/files.cpp
@@ -250,6 +250,21 @@ TEST_CASE ("win32_fix_path_case", "[files]")
}
#endif // _WIN32
+TEST_CASE ("add_filename", "[files]")
+{
+ using vcpkg::Files::add_filename;
+ using vcpkg::Files::preferred_separator;
+
+ CHECK(add_filename("a/b", "c") == std::string("a/b") + preferred_separator + "c");
+ CHECK(add_filename("a/b/", "c") == "a/b/c");
+ CHECK(add_filename("a/b\\", "c") == "a/b\\c");
+ CHECK(add_filename("", "c") == "c");
+
+ // note that we don't special case slashes in the second argument; the caller shouldn't do that
+ CHECK(add_filename("a/b/", "\\c") == "a/b/\\c");
+ CHECK(add_filename("a/b\\", "/c") == "a/b\\/c");
+}
+
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
TEST_CASE ("remove all -- benchmarks", "[files][!benchmark]")
{
diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp
index 2d82e1df1..d00b9b7a6 100644
--- a/toolsrc/src/vcpkg/base/files.cpp
+++ b/toolsrc/src/vcpkg/base/files.cpp
@@ -23,7 +23,6 @@
#include <algorithm>
#include <string>
-#if defined(_WIN32)
namespace
{
struct IsSlash
@@ -32,7 +31,11 @@ namespace
};
constexpr IsSlash is_slash;
+} // unnamed namespace
+#if defined(_WIN32)
+namespace
+{
template<size_t N>
bool wide_starts_with(const std::wstring& haystack, const wchar_t (&needle)[N]) noexcept
{
@@ -1182,14 +1185,14 @@ namespace vcpkg::Files
auto paths = Strings::split_paths(System::get_environment_variable("PATH").value_or_exit(VCPKG_LINE_INFO));
std::vector<fs::path> ret;
- std::error_code ec;
for (auto&& path : paths)
{
- auto base = path + "/" + name;
+ auto base = add_filename(path, name);
+
for (auto&& ext : EXTS)
{
auto p = fs::u8path(base + ext.c_str());
- if (Util::find(ret, p) == ret.end() && this->exists(p, ec))
+ if (Util::find(ret, p) == ret.end() && this->exists(p, ignore_errors))
{
ret.push_back(p);
Debug::print("Found path: ", fs::u8string(p), '\n');
@@ -1372,4 +1375,26 @@ namespace vcpkg::Files
return fs::path(std::move(in_progress));
}
#endif // _WIN32
+
+ std::string add_filename(StringView base, StringView file)
+ {
+ std::string result;
+ const auto base_size = base.size();
+ const auto file_size = file.size();
+ if (base_size != 0 && !is_slash(base.data()[base_size - 1]))
+ {
+ result.reserve(base_size + file_size + 1);
+ result.append(base.data(), base_size);
+ result.push_back(preferred_separator);
+ result.append(file.data(), file_size);
+ }
+ else
+ {
+ result.reserve(base_size + file_size);
+ result.append(base.data(), base_size);
+ result.append(file.data(), file_size);
+ }
+
+ return result;
+ }
}
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp
index 9b4e7b428..7eaaf6aad 100644
--- a/toolsrc/src/vcpkg/build.cpp
+++ b/toolsrc/src/vcpkg/build.cpp
@@ -338,13 +338,6 @@ namespace vcpkg::Build
return base_env.cmd_cache.get_lazy(build_env_cmd, [&]() {
const fs::path& powershell_exe_path = paths.get_tool_exe("powershell-core");
- auto& fs = paths.get_filesystem();
- if (!fs.exists(powershell_exe_path.parent_path() / "powershell.exe"))
- {
- fs.copy(
- powershell_exe_path, powershell_exe_path.parent_path() / "powershell.exe", fs::copy_options::none);
- }
-
auto clean_env = System::get_modified_clean_environment(
base_env.env_map, fs::u8string(powershell_exe_path.parent_path()) + ";");
if (build_env_cmd.empty())
diff --git a/toolsrc/src/vcpkg/tools.cpp b/toolsrc/src/vcpkg/tools.cpp
index 5531a1dac..d308290ae 100644
--- a/toolsrc/src/vcpkg/tools.cpp
+++ b/toolsrc/src/vcpkg/tools.cpp
@@ -464,6 +464,36 @@ Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-2 Wed Feb 26 23:23:50
}
};
+ struct PowerShellCoreProvider : ToolProvider
+ {
+ std::string m_exe = "pwsh";
+
+ virtual const std::string& tool_data_name() const override { return m_exe; }
+ virtual const std::string& exe_stem() const override { return m_exe; }
+ virtual std::array<int, 3> default_min_version() const override { return {7, 0, 3}; }
+
+ virtual Optional<std::string> get_version(const VcpkgPaths&, const fs::path& path_to_exe) const override
+ {
+ const auto pwsh_invocation = System::cmd_execute_and_capture_output(
+ System::CmdLineBuilder().path_arg(path_to_exe).string_arg("--version").extract());
+ if (pwsh_invocation.exit_code != 0)
+ {
+ return nullopt;
+ }
+
+ // Sample output: PowerShell 7.0.3\r\n
+ auto output = std::move(pwsh_invocation.output);
+ if (!Strings::starts_with(output, "PowerShell "))
+ {
+ Checks::exit_with_message(
+ VCPKG_LINE_INFO, "Unexpected format of powershell-core version string: %s", output);
+ }
+
+ output.erase(0, 11);
+ return Strings::trim(std::move(output));
+ }
+ };
+
struct ToolCacheImpl final : ToolCache
{
vcpkg::Cache<std::string, fs::path> path_only_cache;
@@ -511,6 +541,14 @@ Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-2 Wed Feb 26 23:23:50
}
return get_path(paths, NinjaProvider());
}
+ if (tool == Tools::POWERSHELL_CORE)
+ {
+ if (System::get_environment_variable("VCPKG_FORCE_SYSTEM_BINARIES").has_value())
+ {
+ return {"pwsh", "0"};
+ }
+ return get_path(paths, PowerShellCoreProvider());
+ }
if (tool == Tools::NUGET) return get_path(paths, NuGetProvider());
if (tool == Tools::IFW_INSTALLER_BASE) return get_path(paths, IfwInstallerBaseProvider());
if (tool == Tools::MONO) return get_path(paths, MonoProvider());