aboutsummaryrefslogtreecommitdiff
path: root/scripts
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
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')
-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
4 files changed, 60 insertions, 17 deletions
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}