vcpkg/scripts/bootstrap.ps1
Alexander Karatarakis a5fe308ea3 $script:MyInvocation.MyCommand.Definition
It works also in cases where scripts/functions are calling each other.
Without the $script prefix, it would instead give you the calling function OR the path if there was no parent function.
With the prefix, it always yields the directory of the script
2018-01-23 14:16:06 -08:00

73 lines
2.1 KiB
PowerShell

[CmdletBinding()]
param(
[ValidateNotNullOrEmpty()][string]$disableMetrics = "0",
[Parameter(Mandatory=$False)][string]$withVSPath = ""
)
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
$vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root
Write-Verbose("vcpkg Path " + $vcpkgRootDir)
$gitHash = "unknownhash"
$oldpath = $env:path
try
{
$env:path += ";$vcpkgRootDir\downloads\MinGit-2.15.0-32-bit\cmd"
if (Get-Command "git" -ErrorAction SilentlyContinue)
{
$gitHash = git log HEAD -n 1 --format="%cd-%H" --date=short
if ($LASTEXITCODE -ne 0)
{
$gitHash = "unknownhash"
}
}
}
finally
{
$env:path = $oldpath
}
Write-Verbose("Git repo version string is " + $gitHash)
$vcpkgSourcesPath = "$vcpkgRootDir\toolsrc"
if (!(Test-Path $vcpkgSourcesPath))
{
Write-Error "Unable to determine vcpkg sources directory. '$vcpkgSourcesPath' does not exist."
return
}
try
{
Push-Location $vcpkgSourcesPath
$msbuildExeWithPlatformToolset = & $scriptsDir\findAnyMSBuildWithCppPlatformToolset.ps1 $withVSPath
$msbuildExe = $msbuildExeWithPlatformToolset[0]
$platformToolset = $msbuildExeWithPlatformToolset[1]
$windowsSDK = & $scriptsDir\getWindowsSDK.ps1
$arguments = (
"`"/p:VCPKG_VERSION=-$gitHash`"",
"`"/p:DISABLE_METRICS=$disableMetrics`"",
"/p:Configuration=Release",
"/p:Platform=x86",
"/p:PlatformToolset=$platformToolset",
"/p:TargetPlatformVersion=$windowsSDK",
"/m",
"dirs.proj")
& $msbuildExe $arguments
if ($LASTEXITCODE -ne 0)
{
Write-Error "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++."
return
}
Write-Verbose("Placing vcpkg.exe in the correct location")
Copy-Item $vcpkgSourcesPath\Release\vcpkg.exe $vcpkgRootDir\vcpkg.exe | Out-Null
Copy-Item $vcpkgSourcesPath\Release\vcpkgmetricsuploader.exe $vcpkgRootDir\scripts\vcpkgmetricsuploader.exe | Out-Null
}
finally
{
Pop-Location
}