From a6a1722cfa94caa5db98848679b99377bc5a0112 Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Tue, 27 Oct 2020 20:48:14 -0700 Subject: [vcpkg, jsonnet, openssl-uwp] Enable use of the system powershell-core if it is present. (#13805) --- scripts/addPoshVcpkgToPowershellProfile.ps1 | 6 ++-- scripts/buildsystems/msbuild/vcpkg.targets | 41 ++++++++++++++++++++---- scripts/buildsystems/vcpkg.cmake | 20 ++++++++++-- scripts/cmake/vcpkg_copy_tool_dependencies.cmake | 10 +++--- 4 files changed, 60 insertions(+), 17 deletions(-) (limited to 'scripts') 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 @@ + + File="$(TLogLocation)$(ProjectName).write.1u.tlog" + Lines="^$(TargetPath);$([System.IO.Path]::Combine($(ProjectDir),$(IntDir)))vcpkg.applocal.log" Encoding="Unicode"/> + + <_VcpkgAppLocalPowerShellCommonArguments>-ExecutionPolicy Bypass -noprofile -File "$(MSBuildThisFileDirectory)applocal.ps1" "$(TargetPath)" "$(VcpkgCurrentInstalledDir)$(VcpkgConfigSubdir)bin" "$(TLogLocation)$(ProjectName).write.1u.tlog" "$(IntDir)vcpkg.applocal.log" + + + Command="pwsh.exe $(_VcpkgAppLocalPowerShellCommonArguments)" + StandardOutputImportance="Normal" + StandardErrorImportance="Normal" + IgnoreExitCode="true" + UseCommandProcessor="false"> + - + + + + + + + + - - + + 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 $ -installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/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 $ -installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/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} -- cgit v1.2.3