2016-09-19 11:50:08 +08:00
[ CmdletBinding ( ) ]
param (
2017-11-10 12:09:04 +08:00
[ ValidateNotNullOrEmpty ( ) ] [ string ] $disableMetrics = " 0 " ,
2017-11-10 13:41:16 +08:00
[ Parameter ( Mandatory = $False ) ] [ string ] $withVSPath = " "
2016-09-19 11:50:08 +08:00
)
2018-03-01 10:44:57 +08:00
Set-StrictMode -Version Latest
2018-01-23 10:18:53 +08:00
$scriptsDir = split-path -parent $script:MyInvocation . MyCommand . Definition
2018-01-23 10:19:30 +08:00
. " $scriptsDir \VcpkgPowershellUtils.ps1 "
2018-02-07 07:44:59 +08:00
$vcpkgRootDir = vcpkgFindFileRecursivelyUp $scriptsDir . vcpkg-root
2017-08-26 14:20:57 +08:00
Write-Verbose ( " vcpkg Path " + $vcpkgRootDir )
2016-11-22 10:10:21 +08:00
$gitHash = " unknownhash "
2017-08-26 14:25:41 +08:00
$oldpath = $env:path
try
2016-11-22 10:10:21 +08:00
{
2018-02-24 08:34:31 +08:00
[ xml ] $asXml = Get-Content " $scriptsDir \vcpkgTools.xml "
$toolData = $asXml . SelectSingleNode ( " //tools/tool[@name= `" git `" ] " )
2018-03-01 09:48:31 +08:00
$gitFromDownload = " $vcpkgRootDir \downloads\ $( $toolData . exeRelativePath ) "
2018-02-23 11:56:08 +08:00
$gitDir = split-path -parent $gitFromDownload
$env:path + = " ; $gitDir "
2017-08-29 08:33:03 +08:00
if ( Get-Command " git " -ErrorAction SilentlyContinue )
2017-08-26 14:20:57 +08:00
{
2017-08-26 14:25:41 +08:00
$gitHash = git log HEAD -n 1 - -format = " %cd-%H " - -date = short
if ( $LASTEXITCODE -ne 0 )
{
$gitHash = " unknownhash "
}
2017-08-26 14:20:57 +08:00
}
2016-11-22 10:10:21 +08:00
}
2017-08-26 14:25:41 +08:00
finally
{
$env:path = $oldpath
}
2017-08-26 14:20:57 +08:00
Write-Verbose ( " Git repo version string is " + $gitHash )
2018-02-23 11:56:08 +08:00
2016-09-20 09:46:02 +08:00
$vcpkgSourcesPath = " $vcpkgRootDir \toolsrc "
2016-09-19 11:50:08 +08:00
if ( ! ( Test-Path $vcpkgSourcesPath ) )
{
2017-11-01 14:41:24 +08:00
Write-Error " Unable to determine vcpkg sources directory. ' $vcpkgSourcesPath ' does not exist. "
return
2016-09-19 11:50:08 +08:00
}
2018-01-26 08:48:32 +08:00
$msbuildExeWithPlatformToolset = & $scriptsDir \ findAnyMSBuildWithCppPlatformToolset . ps1 $withVSPath
$msbuildExe = $msbuildExeWithPlatformToolset [ 0 ]
$platformToolset = $msbuildExeWithPlatformToolset [ 1 ]
$windowsSDK = & $scriptsDir \ getWindowsSDK . ps1
2018-01-23 10:19:30 +08:00
2018-01-26 08: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 " ,
" /m " ,
2018-01-26 09:03:37 +08:00
" `" $vcpkgSourcesPath \dirs.proj `" " ) -join " "
2016-09-19 11:50:08 +08:00
2018-01-26 08:48:32 +08:00
# vcpkgInvokeCommandClean cmd "/c echo %PATH%"
$ec = vcpkgInvokeCommandClean $msbuildExe $arguments
2016-09-19 11:50:08 +08:00
2018-01-26 08:48:32 +08:00
if ( $ec -ne 0 )
2017-08-26 14:25:41 +08:00
{
2018-01-26 08: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-19 11:50:08 +08:00
}
2018-01-26 08: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