Powershell scripts now detect the root dir via the .vcpkg-root file

This commit is contained in:
Alexander Karatarakis 2016-09-19 18:46:02 -07:00
parent 31e7e21921
commit b9a0cee78d
4 changed files with 46 additions and 26 deletions

View File

@ -4,13 +4,13 @@ param(
[string]$disableMetrics = "0" [string]$disableMetrics = "0"
) )
$scriptsdir = split-path -parent $MyInvocation.MyCommand.Definition $scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$vcpkgRoot = Split-path $scriptsdir -Parent $vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root
$gitHash = git rev-parse HEAD $gitHash = git rev-parse HEAD
Write-Verbose("Git hash is " + $gitHash) Write-Verbose("Git hash is " + $gitHash)
$gitStartOfHash = $gitHash.substring(0,6) $gitStartOfHash = $gitHash.substring(0,6)
$vcpkgSourcesPath = "$vcpkgRoot\toolsrc" $vcpkgSourcesPath = "$vcpkgRootDir\toolsrc"
Write-Verbose("vcpkg Path " + $vcpkgSourcesPath) Write-Verbose("vcpkg Path " + $vcpkgSourcesPath)
if (!(Test-Path $vcpkgSourcesPath)) if (!(Test-Path $vcpkgSourcesPath))
@ -24,8 +24,8 @@ try{
Write-Verbose("Placing vcpkg.exe in the correct location") Write-Verbose("Placing vcpkg.exe in the correct location")
Copy-Item $vcpkgSourcesPath\Release\vcpkg.exe $vcpkgRoot\vcpkg.exe | Out-Null Copy-Item $vcpkgSourcesPath\Release\vcpkg.exe $vcpkgRootDir\vcpkg.exe | Out-Null
Copy-Item $vcpkgSourcesPath\Release\vcpkgmetricsuploader.exe $vcpkgRoot\scripts\vcpkgmetricsuploader.exe | Out-Null Copy-Item $vcpkgSourcesPath\Release\vcpkgmetricsuploader.exe $vcpkgRootDir\scripts\vcpkgmetricsuploader.exe | Out-Null
} }
finally{ finally{
popd popd

View File

@ -25,11 +25,12 @@ if ($matchingTags.Length -gt 0)
$gitHash = git rev-parse HEAD $gitHash = git rev-parse HEAD
Write-Verbose("Git hash is " + $gitHash) Write-Verbose("Git hash is " + $gitHash)
$vcpkgPath = (get-item $PSScriptRoot).parent.FullName $scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root
$gitStartOfHash = $gitHash.substring(0,6) $gitStartOfHash = $gitHash.substring(0,6)
$versionWithStartOfHash = "$version-$gitStartOfHash" $versionWithStartOfHash = "$version-$gitStartOfHash"
$buildPath = "$vcpkgPath\build-$versionWithStartOfHash" $buildPath = "$vcpkgRootDir\build-$versionWithStartOfHash"
$releasePath = "$vcpkgPath\release-$versionWithStartOfHash" $releasePath = "$vcpkgRootDir\release-$versionWithStartOfHash"
Write-Verbose("Build Path " + $buildPath) Write-Verbose("Build Path " + $buildPath)
Write-Verbose("Release Path " + $releasePath) Write-Verbose("Release Path " + $releasePath)
@ -48,7 +49,7 @@ for ($disableMetrics = 0; $disableMetrics -le 1; $disableMetrics++)
} }
# Partial checkout for building vcpkg # Partial checkout for building vcpkg
$dotGitDir = "$vcpkgPath\.git" $dotGitDir = "$vcpkgRootDir\.git"
$workTreeForBuildOnly = "$buildPath" $workTreeForBuildOnly = "$buildPath"
$checkoutThisDirForBuildOnly1 = ".\scripts" # Must be relative to the root of the repository $checkoutThisDirForBuildOnly1 = ".\scripts" # Must be relative to the root of the repository
$checkoutThisDirForBuildOnly2 = ".\toolsrc" # Must be relative to the root of the repository $checkoutThisDirForBuildOnly2 = ".\toolsrc" # Must be relative to the root of the repository
@ -68,10 +69,10 @@ for ($disableMetrics = 0; $disableMetrics -le 1; $disableMetrics++)
Copy-Item $buildPath\scripts\vcpkgmetricsuploader.exe $releasePath\scripts\vcpkgmetricsuploader.exe | Out-Null Copy-Item $buildPath\scripts\vcpkgmetricsuploader.exe $releasePath\scripts\vcpkgmetricsuploader.exe | Out-Null
Write-Verbose("Archiving") Write-Verbose("Archiving")
$outputArchive = "$vcpkgPath\vcpkg-$versionWithStartOfHash.zip" $outputArchive = "$vcpkgRootDir\vcpkg-$versionWithStartOfHash.zip"
if ($disableMetrics -ne 0) if ($disableMetrics -ne 0)
{ {
$outputArchive = "$vcpkgPath\vcpkg-$versionWithStartOfHash-external.zip" $outputArchive = "$vcpkgRootDir\vcpkg-$versionWithStartOfHash-external.zip"
} }
Compress-Archive -Path "$releasePath\*" -CompressionLevel Optimal -DestinationPath $outputArchive -Force | Out-Null Compress-Archive -Path "$releasePath\*" -CompressionLevel Optimal -DestinationPath $outputArchive -Force | Out-Null

View File

@ -5,9 +5,10 @@ param(
Import-Module BitsTransfer Import-Module BitsTransfer
$scriptsdir = split-path -parent $MyInvocation.MyCommand.Definition $scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$vcpkgroot = Split-path $scriptsdir -Parent $vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root
$downloadsdir = "$vcpkgroot\downloads"
$downloadsDir = "$vcpkgRootDir\downloads"
function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
{ {
@ -24,7 +25,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
function promptForDownload([string]$title, [string]$message, [string]$yesDescription, [string]$noDescription) function promptForDownload([string]$title, [string]$message, [string]$yesDescription, [string]$noDescription)
{ {
if ((Test-Path "$downloadsdir\AlwaysAllowEverything") -Or (Test-Path "$downloadsdir\AlwaysAllowDownloads")) if ((Test-Path "$downloadsDir\AlwaysAllowEverything") -Or (Test-Path "$downloadsDir\AlwaysAllowDownloads"))
{ {
return $true return $true
} }
@ -41,7 +42,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
0 {return $true} 0 {return $true}
1 {return $false} 1 {return $false}
2 { 2 {
New-Item "$downloadsdir\AlwaysAllowDownloads" -type file -force | Out-Null New-Item "$downloadsDir\AlwaysAllowDownloads" -type file -force | Out-Null
return $true return $true
} }
} }
@ -52,7 +53,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
function performDownload( [Parameter(Mandatory=$true)][string]$Dependency, function performDownload( [Parameter(Mandatory=$true)][string]$Dependency,
[Parameter(Mandatory=$true)][string]$url, [Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][string]$downloaddir, [Parameter(Mandatory=$true)][string]$downloadDir,
[Parameter(Mandatory=$true)][string]$downloadPath, [Parameter(Mandatory=$true)][string]$downloadPath,
[Parameter(Mandatory=$true)][string]$downloadVersion, [Parameter(Mandatory=$true)][string]$downloadVersion,
[Parameter(Mandatory=$true)][string]$requiredVersion) [Parameter(Mandatory=$true)][string]$requiredVersion)
@ -73,9 +74,9 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
throw [System.IO.FileNotFoundException] ("Could not detect suitable version of " + $Dependency + " and download not allowed") throw [System.IO.FileNotFoundException] ("Could not detect suitable version of " + $Dependency + " and download not allowed")
} }
if (!(Test-Path $downloaddir)) if (!(Test-Path $downloadDir))
{ {
New-Item -ItemType directory -Path $downloaddir | Out-Null New-Item -ItemType directory -Path $downloadDir | Out-Null
} }
if ($Dependency -ne "git") # git fails with BITS if ($Dependency -ne "git") # git fails with BITS
@ -135,7 +136,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
$url = "https://cmake.org/files/v3.5/cmake-3.5.2-win32-x86.zip" $url = "https://cmake.org/files/v3.5/cmake-3.5.2-win32-x86.zip"
$downloadName = "cmake-3.5.2-win32-x86.zip" $downloadName = "cmake-3.5.2-win32-x86.zip"
$expectedDownloadedFileHash = "671073aee66b3480a564d0736792e40570a11e861bb34819bb7ae7858bbdfb80" $expectedDownloadedFileHash = "671073aee66b3480a564d0736792e40570a11e861bb34819bb7ae7858bbdfb80"
$executableFromDownload = "$downloadsdir\cmake-3.5.2-win32-x86\bin\cmake.exe" $executableFromDownload = "$downloadsDir\cmake-3.5.2-win32-x86\bin\cmake.exe"
$extractionType = $ExtractionType_ZIP $extractionType = $ExtractionType_ZIP
} }
elseif($Dependency -eq "nuget") elseif($Dependency -eq "nuget")
@ -145,7 +146,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
$url = "https://dist.nuget.org/win-x86-commandline/v3.4.3/nuget.exe" $url = "https://dist.nuget.org/win-x86-commandline/v3.4.3/nuget.exe"
$downloadName = "nuget.exe" $downloadName = "nuget.exe"
$expectedDownloadedFileHash = "3B1EA72943968D7AF6BACDB4F2F3A048A25AFD14564EF1D8B1C041FDB09EBB0A" $expectedDownloadedFileHash = "3B1EA72943968D7AF6BACDB4F2F3A048A25AFD14564EF1D8B1C041FDB09EBB0A"
$executableFromDownload = "$downloadsdir\nuget.exe" $executableFromDownload = "$downloadsDir\nuget.exe"
$extractionType = $ExtractionType_NO_EXTRACTION_REQUIRED $extractionType = $ExtractionType_NO_EXTRACTION_REQUIRED
} }
elseif($Dependency -eq "git") elseif($Dependency -eq "git")
@ -157,7 +158,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
$expectedDownloadedFileHash = "DE52D070219E9C4EC1DB179F2ADBF4B760686C3180608F0382A1F8C7031E72AD" $expectedDownloadedFileHash = "DE52D070219E9C4EC1DB179F2ADBF4B760686C3180608F0382A1F8C7031E72AD"
# There is another copy of git.exe in PortableGit\bin. However, an installed version of git add the cmd dir to the PATH. # There is another copy of git.exe in PortableGit\bin. However, an installed version of git add the cmd dir to the PATH.
# Therefore, choosing the cmd dir here as well. # Therefore, choosing the cmd dir here as well.
$executableFromDownload = "$downloadsdir\PortableGit\cmd\git.exe" $executableFromDownload = "$downloadsDir\PortableGit\cmd\git.exe"
$extractionType = $ExtractionType_SELF_EXTRACTING_7Z $extractionType = $ExtractionType_SELF_EXTRACTING_7Z
} }
else else
@ -165,8 +166,8 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
throw "Unknown program requested" throw "Unknown program requested"
} }
$downloadPath = "$downloadsdir\$downloadName" $downloadPath = "$downloadsDir\$downloadName"
performDownload $Dependency $url $downloadsdir $downloadPath $downloadVersion $requiredVersion performDownload $Dependency $url $downloadsDir $downloadPath $downloadVersion $requiredVersion
#calculating the hash #calculating the hash
$hashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create("SHA256") $hashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create("SHA256")
@ -187,8 +188,8 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
{ {
if (-not (Test-Path $executableFromDownload)) # consider renaming the extraction folder to make sure the extraction finished if (-not (Test-Path $executableFromDownload)) # consider renaming the extraction folder to make sure the extraction finished
{ {
# Expand-Archive $downloadPath -dest "$downloadsdir" -Force # Requires powershell 5+ # Expand-Archive $downloadPath -dest "$downloadsDir" -Force # Requires powershell 5+
Expand-ZIPFile -File $downloadPath -Destination $downloadsdir Expand-ZIPFile -File $downloadPath -Destination $downloadsDir
} }
} }
elseif($extractionType -eq $ExtractionType_SELF_EXTRACTING_7Z) elseif($extractionType -eq $ExtractionType_SELF_EXTRACTING_7Z)

View File

@ -0,0 +1,18 @@
[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"
$currentDir = Split-path $currentDir -Parent
}
Write-Verbose "Found: $currentDir"
return $currentDir