From 815e3caf5573d1149e1f826b359beb9039293307 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 6 Feb 2018 15:44:59 -0800 Subject: [PATCH 1/2] Merge findFileRecursivelyUp into VcpkgPowershellUtils --- scripts/VcpkgPowershellUtils.ps1 | 20 ++++++++++++++++++++ scripts/bootstrap.ps1 | 2 +- scripts/fetchDependency.ps1 | 2 +- scripts/findFileRecursivelyUp.ps1 | 18 ------------------ toolsrc/vcpkg.sln | 1 - 5 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 scripts/findFileRecursivelyUp.ps1 diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1 index 07270dd228..4334df2cc6 100644 --- a/scripts/VcpkgPowershellUtils.ps1 +++ b/scripts/VcpkgPowershellUtils.ps1 @@ -226,3 +226,23 @@ function vcpkgFormatElapsedTime([TimeSpan]$ts) throw $ts } + +function vcpkgFindFileRecursivelyUp() +{ + param( + [ValidateNotNullOrEmpty()] + [Parameter(Mandatory=$true)][string]$startingDir, + [ValidateNotNullOrEmpty()] + [Parameter(Mandatory=$true)][string]$filename + ) + + $currentDir = $startingDir + + while (!($currentDir -eq "") -and !(Test-Path "$currentDir\$filename")) + { + Write-Verbose "Examining $currentDir for $filename" + $currentDir = Split-path $currentDir -Parent + } + Write-Verbose "Examining $currentDir for $filename - Found" + return $currentDir +} diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1 index 03f05d50bc..0df2a2a996 100644 --- a/scripts/bootstrap.ps1 +++ b/scripts/bootstrap.ps1 @@ -6,7 +6,7 @@ param( $scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition . "$scriptsDir\VcpkgPowershellUtils.ps1" -$vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root +$vcpkgRootDir = vcpkgFindFileRecursivelyUp $scriptsDir .vcpkg-root Write-Verbose("vcpkg Path " + $vcpkgRootDir) diff --git a/scripts/fetchDependency.ps1 b/scripts/fetchDependency.ps1 index ad0b774d4b..bfc0f733a4 100644 --- a/scripts/fetchDependency.ps1 +++ b/scripts/fetchDependency.ps1 @@ -7,7 +7,7 @@ $scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition . "$scriptsDir\VcpkgPowershellUtils.ps1" Write-Verbose "Fetching dependency: $Dependency" -$vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root +$vcpkgRootDir = vcpkgFindFileRecursivelyUp $scriptsDir .vcpkg-root $downloadsDir = "$vcpkgRootDir\downloads" diff --git a/scripts/findFileRecursivelyUp.ps1 b/scripts/findFileRecursivelyUp.ps1 deleted file mode 100644 index 4b6409e8cf..0000000000 --- a/scripts/findFileRecursivelyUp.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -[CmdletBinding()] -param( - [ValidateNotNullOrEmpty()] - [Parameter(Mandatory=$true)][string]$startingDir, - [ValidateNotNullOrEmpty()] - [Parameter(Mandatory=$true)][string]$filename -) - -$ErrorActionPreference = "Stop" -$currentDir = $startingDir - -while (!($currentDir -eq "") -and !(Test-Path "$currentDir\$filename")) -{ - Write-Verbose "Examining $currentDir for $filename" - $currentDir = Split-path $currentDir -Parent -} -Write-Verbose "Examining $currentDir for $filename - Found" -return $currentDir \ No newline at end of file diff --git a/toolsrc/vcpkg.sln b/toolsrc/vcpkg.sln index c2df757fc6..6c429cff96 100644 --- a/toolsrc/vcpkg.sln +++ b/toolsrc/vcpkg.sln @@ -16,7 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{F589 ..\scripts\bootstrap.ps1 = ..\scripts\bootstrap.ps1 ..\scripts\fetchDependency.ps1 = ..\scripts\fetchDependency.ps1 ..\scripts\findAnyMSBuildWithCppPlatformToolset.ps1 = ..\scripts\findAnyMSBuildWithCppPlatformToolset.ps1 - ..\scripts\findFileRecursivelyUp.ps1 = ..\scripts\findFileRecursivelyUp.ps1 ..\scripts\findVisualStudioInstallationInstances.ps1 = ..\scripts\findVisualStudioInstallationInstances.ps1 ..\scripts\get_triplet_environment.cmake = ..\scripts\get_triplet_environment.cmake ..\scripts\getProgramFiles32bit.ps1 = ..\scripts\getProgramFiles32bit.ps1 From 3aac3957ae9053eb3ffb97bcc49148e7b0a4c050 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 7 Feb 2018 17:31:19 -0800 Subject: [PATCH 2/2] [vcpkgInvokeCommandClean] Don't use -encodedCommand. Instead, use -Command with the appropriate number of escaped quotes (which ended up being 3) --- scripts/VcpkgPowershellUtils.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1 index 4334df2cc6..bed78b198c 100644 --- a/scripts/VcpkgPowershellUtils.ps1 +++ b/scripts/VcpkgPowershellUtils.ps1 @@ -190,10 +190,10 @@ function vcpkgInvokeCommandClean() Write-Verbose "Clean-Executing: ${executable} ${arguments}" $scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition $cleanEnvScript = "$scriptsDir\VcpkgPowershellUtils-ClearEnvironment.ps1" - $command = "& `"$cleanEnvScript`"; & `"$executable`" $arguments" - $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) - $encodedCommand = [Convert]::ToBase64String($bytes) - $arg = "-NoProfile -ExecutionPolicy Bypass -encodedCommand $encodedCommand" + $tripleQuotes = "`"`"`"" + $argumentsWithEscapedQuotes = $arguments -replace "`"", $tripleQuotes + $command = ". $tripleQuotes$cleanEnvScript$tripleQuotes; & $tripleQuotes$executable$tripleQuotes $argumentsWithEscapedQuotes" + $arg = "-NoProfile", "-ExecutionPolicy Bypass", "-command $command" $process = Start-Process -FilePath powershell.exe -ArgumentList $arg -PassThru -NoNewWindow Wait-Process -InputObject $process