aboutsummaryrefslogtreecommitdiff
path: root/scripts/buildsystems
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 /scripts/buildsystems
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)
Diffstat (limited to 'scripts/buildsystems')
-rw-r--r--scripts/buildsystems/msbuild/vcpkg.targets41
-rw-r--r--scripts/buildsystems/vcpkg.cmake20
2 files changed, 52 insertions, 9 deletions
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