2016-09-18 20:50:08 -07:00
[ CmdletBinding ( ) ]
param (
2017-11-09 20:09:04 -08:00
[ ValidateNotNullOrEmpty ( ) ] [ string ] $disableMetrics = " 0 " ,
2017-11-09 21:41:16 -08:00
[ Parameter ( Mandatory = $False ) ] [ string ] $withVSPath = " "
2016-09-18 20:50:08 -07:00
)
2018-02-28 18:44:57 -08:00
Set-StrictMode -Version Latest
2018-01-22 18:18:53 -08:00
$scriptsDir = split-path -parent $script:MyInvocation . MyCommand . Definition
2017-08-25 23:20:57 -07:00
2018-05-05 04:23:19 -07:00
$vcpkgRootDir = $scriptsDir
$withVSPath = $withVSPath -replace " \\ $ " # Remove potential trailing backslash
2018-02-22 19:56:08 -08:00
2018-05-05 04:23:19 -07:00
while ( ! ( $vcpkgRootDir -eq " " ) -and ! ( Test-Path " $vcpkgRootDir \.vcpkg-root " ) )
2017-08-25 23:25:41 -07:00
{
2018-05-05 04:23:19 -07:00
Write-Verbose " Examining $vcpkgRootDir for .vcpkg-root "
$vcpkgRootDir = Split-path $vcpkgRootDir -Parent
2017-08-25 23:25:41 -07:00
}
2018-05-05 04:23:19 -07:00
Write-Verbose " Examining $vcpkgRootDir for .vcpkg-root - Found "
2018-02-22 19:56:08 -08:00
2018-05-05 04:23:19 -07:00
$gitHash = " nohash "
2016-09-19 18:46:02 -07:00
$vcpkgSourcesPath = " $vcpkgRootDir \toolsrc "
2016-09-18 20:50:08 -07:00
if ( ! ( Test-Path $vcpkgSourcesPath ) )
{
2017-10-31 23:41:24 -07:00
Write-Error " Unable to determine vcpkg sources directory. ' $vcpkgSourcesPath ' does not exist. "
return
2016-09-18 20:50:08 -07:00
}
2018-05-05 04:23:19 -07:00
function findAnyMSBuildWithCppPlatformToolset([string]$withVSPath )
{
$VisualStudioInstances = & $scriptsDir \ getVisualStudioInstances . ps1
if ( $VisualStudioInstances -eq $null )
{
throw " Could not find Visual Studio. VS2015 or VS2017 (with C++) needs to be installed. "
}
Write-Verbose " VS Candidates: `n `r $( [ system.String ] :: Join ( [ Environment ] :: NewLine , $VisualStudioInstances ) ) "
foreach ( $instanceCandidateWithEOL in $VisualStudioInstances )
{
$instanceCandidate = $instanceCandidateWithEOL -replace " <sol>:: " -replace " ::<eol> "
Write-Verbose " Inspecting: $instanceCandidate "
$split = $instanceCandidate -split " :: "
# $preferenceWeight = $split[0]
# $releaseType = $split[1]
$version = $split [ 2 ]
$path = $split [ 3 ]
if ( $withVSPath -ne " " -and $withVSPath -ne $path )
{
Write-Verbose " Skipping: $instanceCandidate "
continue
}
$majorVersion = $version . Substring ( 0 , 2 ) ;
if ( $majorVersion -eq " 15 " )
{
$VCFolder = " $path \VC\Tools\MSVC\ "
if ( Test-Path $VCFolder )
{
Write-Verbose " Picking: $instanceCandidate "
return " $path \MSBuild\15.0\Bin\MSBuild.exe " , " v141 "
}
}
if ( $majorVersion -eq " 14 " )
{
$clExe = " $path \VC\bin\cl.exe "
if ( Test-Path $clExe )
{
Write-Verbose " Picking: $instanceCandidate "
$programFilesPath = getProgramFiles32bit
return " $programFilesPath \MSBuild\14.0\Bin\MSBuild.exe " , " v140 "
}
}
}
throw " Could not find MSBuild version with C++ support. VS2015 or VS2017 (with C++) needs to be installed. "
}
$msbuildExeWithPlatformToolset = findAnyMSBuildWithCppPlatformToolset $withVSPath
2018-01-25 16:48:32 -08:00
$msbuildExe = $msbuildExeWithPlatformToolset [ 0 ]
$platformToolset = $msbuildExeWithPlatformToolset [ 1 ]
$windowsSDK = & $scriptsDir \ getWindowsSDK . ps1
2018-01-22 18:19:30 -08:00
2018-01-25 16:48:32 -08:00
$arguments = (
" `" /p:VCPKG_VERSION=- $gitHash `" " ,
" `" /p:DISABLE_METRICS= $disableMetrics `" " ,
" /p:Configuration=Release " ,
" /p:Platform=x86 " ,
" /p:PlatformToolset= $platformToolset " ,
" /p:TargetPlatformVersion= $windowsSDK " ,
2018-05-05 04:23:19 -07:00
" /verbosity:minimal " ,
2018-01-25 16:48:32 -08:00
" /m " ,
2018-05-05 04:23:19 -07:00
" /nologo " ,
2018-01-25 17:03:37 -08:00
" `" $vcpkgSourcesPath \dirs.proj `" " ) -join " "
2016-09-18 20:50:08 -07:00
2018-05-05 04:23:19 -07:00
function vcpkgInvokeCommandClean ( )
{
param ( [ Parameter ( Mandatory = $true ) ] [ string ] $executable ,
[ string ] $arguments = " " )
Write-Verbose " Clean-Executing: ${executable} ${arguments} "
$scriptsDir = split-path -parent $script:MyInvocation . MyCommand . Definition
$cleanEnvScript = " $scriptsDir \VcpkgPowershellUtils-ClearEnvironment.ps1 "
$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
$ec = $process . ExitCode
Write-Verbose " Execution terminated with exit code $ec . "
return $ec
}
2018-01-25 16:48:32 -08:00
# vcpkgInvokeCommandClean cmd "/c echo %PATH%"
2018-05-05 04:23:19 -07:00
Write-Host " `n Building vcpkg.exe ... `n "
2018-01-25 16:48:32 -08:00
$ec = vcpkgInvokeCommandClean $msbuildExe $arguments
2016-09-18 20:50:08 -07:00
2018-01-25 16:48:32 -08:00
if ( $ec -ne 0 )
2017-08-25 23:25:41 -07:00
{
2018-01-25 16:48:32 -08:00
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
2016-09-18 20:50:08 -07:00
}
2018-05-05 04:23:19 -07:00
Write-Host " `n Building vcpkg.exe... done. `n "
2018-01-25 16:48:32 -08:00
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