提交 45d2e0a1 编写于 作者: J Jared Parsons 提交者: GitHub

Merge pull request #17740 from jaredpar/fix-script

Move more infrastructure to Powershell
@if not defined EchoOn @echo off
@setlocal enabledelayedexpansion
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\restore-legacy.ps1" %*
set RoslynRoot=%~dp0
set DevDivPackages=%RoslynRoot%src\Setup\DevDivPackages
:ParseArguments
if /I "%1" == "/?" goto :Usage
if /I "%1" == "/clean" set RestoreClean=true&&shift&& goto :ParseArguments
if /I "%1" == "/fast" set RestoreFast=true&&shift&& goto :ParseArguments
goto :DoneParsing
:DoneParsing
REM Allow for alternate solutions to be passed as restore targets.
set RoslynSolution=%1
if "%RoslynSolution%" == "" set RoslynSolution=%RoslynRoot%\Roslyn.sln
REM Load in the inforation for NuGet
call "%RoslynRoot%build\scripts\LoadNuGetInfo.cmd" || goto :LoadNuGetInfoFailed
if "%RestoreClean%" == "true" (
echo Clearing the NuGet caches
call "%NugetExe%" locals all -clear || goto :CleanFailed
)
if "%RestoreFast%" == "" (
echo Deleting project.lock.json files
pushd "%RoslynRoot%src"
echo "Dummy lock file to avoid error when there is no project.lock.json file" > project.lock.json
del /s /q project.lock.json > nul
popd
)
echo Restoring packages: Toolsets
call "%NugetExe%" restore "%RoslynRoot%build\ToolsetPackages\project.json" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
echo Restoring packages: Toolsets (Dev14 VS SDK build tools)
call "%NugetExe%" restore "%RoslynRoot%build\ToolsetPackages\dev14.project.json" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
echo Restoring packages: Toolsets (Dev15 VS SDK RC build tools)
call "%NugetExe%" restore "%RoslynRoot%build\ToolsetPackages\dev15rc.project.json" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
echo Locating MSBuild for Solution restore
call "%RoslynRoot%SetDevCommandPrompt.cmd" || goto :RestoreFailed
REM If we have an applocal copy of MSBuild, pass it to NuGet. Otherwise, assume NuGet knows how to find it.
if exist "%DevenvDir%\..\..\MSBuild\15.0\Bin\MSBuild.exe" (
set NuGetAdditionalCommandLineArgs=%NuGetAdditionalCommandLineArgs% -msbuildpath "%DevenvDir%\..\..\MSBuild\15.0\Bin"
)
echo Restoring packages: Samples
call "%NugetExe%" restore "%RoslynRoot%src\Samples\Samples.sln" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
echo Restoring packages: Templates
call "%NugetExe%" restore "%RoslynRoot%src\Setup\Templates\Templates.sln" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
echo Restoring packages: Toolset
call "%NugetExe%" restore "%RoslynRoot%build\Toolset\Toolset.csproj" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
echo Restoring packages: Roslyn (this may take some time)
call "%NugetExe%" restore "%RoslynSolution%" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
echo Restoring packages: DevDiv tools
call "%NugetExe%" restore "%RoslynRoot%src\Setup\DevDivInsertionFiles\DevDivInsertionFiles.sln" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
call "%NugetExe%" restore "%DevDivPackages%\Roslyn\project.json" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
call "%NugetExe%" restore "%DevDivPackages%\Debugger\project.json" %NuGetAdditionalCommandLineArgs% || goto :RestoreFailed
exit /b 0
:CleanFailed
echo Clean failed with ERRORLEVEL %ERRORLEVEL%
exit /b 1
:RestoreFailed
echo Restore failed with ERRORLEVEL %ERRORLEVEL%
exit /b 1
:LoadNuGetInfoFailed
echo Error loading NuGet.exe information %ERRORLEVEL%
exit /b 1
:Usage
@echo Usage: Restore.cmd /clean [Solution File]
exit /b 1
......@@ -36,7 +36,7 @@
$(NuGetPackageRoot)\Microsoft.Net.Compilers\$(ToolsetCompilerPackageVersion)\build\Microsoft.Net.Compilers.props -->
<ToolsetCompilerPropsFilePath>$(MSBuildThisFileDirectory)Microsoft.Net.Compilers.props</ToolsetCompilerPropsFilePath>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VisualStudioReferenceMajorVersion Condition="'$(VisualStudioReferenceMajorVersion)' == ''">$(VisualStudioVersion.Substring(0, $(VisualStudioVersion.IndexOf('.'))))</VisualStudioReferenceMajorVersion>
<VisualStudioReferenceAssemblyVersion Condition="'$(VisualStudioReferenceAssemblyVersion)' == ''">$(VisualStudioReferenceMajorVersion).0.0.0</VisualStudioReferenceAssemblyVersion>
<VisualStudioCodename>Dev$(VisualStudioReferenceMajorVersion)</VisualStudioCodename>
......
......@@ -2,11 +2,10 @@
REM This is a script that will set environment information about where to find
REM NuGet.exe, it's version and ensure that it's present on the enlistment.
set NuGetExeVersion=3.6.0-beta1
set NuGetExeFolder=%~dp0..\..
set NuGetExe=%NuGetExeFolder%\NuGet.exe
set NuGetAdditionalCommandLineArgs=-verbosity quiet -configfile "%NuGetExeFolder%\nuget.config" -Project2ProjectTimeOut 1200
REM Download NuGet.exe if we haven't already
powershell -noprofile -executionPolicy Bypass -file "%~dp0download-nuget.ps1" "%NuGetExeVersion%" "%NuGetExeFolder%" "%NuGetExeFolder%\Binaries"
powershell -noprofile -executionPolicy Bypass -file "%~dp0download-nuget.ps1"
......@@ -6,10 +6,37 @@ $ErrorActionPreference="Stop"
# Declare a number of useful variables for other scripts to use
[string]$repoDir = Resolve-Path (Join-Path $PSScriptRoot "..\..")
[string]$binariesDir = Join-Path $repoDir "Binaries"
[string]$scriptDir = $PSScriptRoot
# Handy function for executing a command in powershell and throwing if it
# fails.
#
# Original sample came from: http://jameskovacs.com/2010/02/25/the-exec-problem/
function Exec([scriptblock]$cmd, [string]$errorMessage = "Error executing command: " + $cmd) {
$output = & $cmd
if (-not $?) {
Write-Host $output
throw $errorMessage
}
}
# Ensure that NuGet is installed and return the path to the
# executable to use.
function Ensure-NuGet() {
Exec { & (Join-Path $PSScriptRoot "download-nuget.ps1") }
$nuget = Join-Path $repoDir "NuGet.exe"
return $nuget
}
# Ensure that MSBuild is installed and return the path to the
# executable to use.
function Ensure-MSBuild() {
$p = Get-MSBuildDir
$p = Join-Path $p "msbuild.exe"
return $p
}
function Create-Directory([string]$dir) {
New-Item $dir -ItemType Directory -ErrorAction SilentlyContinue | out-null
New-Item $dir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
}
# Return the version of the NuGet package as used in this repo
......@@ -39,3 +66,68 @@ function Get-PackagesDir {
Create-Directory $d
return $d
}
# The intent of this script is to locate and return the path to the MSBuild directory that
# we should use for bulid operations. The preference order for MSBuild to use is as
# follows
#
# 1. MSBuild from an active VS command prompt
# 2. MSBuild from a machine wide VS install
#
# This function will return two values: the kind of MSBuild chosen and the MSBuild directory.
function Get-MSBuildKindAndDir() {
# MSBuild from an active VS command prompt.
if (${env:VSINSTALLDIR} -ne $null) {
# This line deliberately avoids using -ErrorAction. Inside a VS command prompt
# an MSBuild command should always be available.
$p = (Get-Command msbuild).Path
$p = Split-Path -parent $p
Write-Output "vscmd"
Write-Output $p
return
}
# Look for a valid VS installation
try {
$p = Get-VisualStudioDir
$p = Join-Path $p "MSBuild\15.0\Bin"
Write-Output "vsinstall"
Write-Output $p
return
}
catch {
# Failures are expected here when no VS installation is present on the
# machine.
}
throw "Unable to find MSBuild"
}
function Get-MSBuildDir() {
$both = Get-MSBuildKindAndDir
return $both[1]
}
# Get the directory of the first Visual Studio which meets our minimal
# requirements for the Roslyn repo
function Get-VisualStudioDir() {
$vswhereVersion = "1.0.50"
$vswhere = Join-Path (Get-PackagesDir) "vswhere\$($vswhereVersion)\tools\vswhere.exe"
if (-not (Test-path $vswhere)) {
$nuget = Ensure-NuGet
Exec { & $nuget install "vswhere" -OutputDirectory (Get-PackagesDir) -Version $vswhereVersion }
}
$output = & $vswhere -requires Microsoft.Component.MSBuild -format json | Out-String
if (-not $?) {
throw "Could not locate a valid Visual Studio"
}
$j = ConvertFrom-Json $output
$p = $j[0].installationPath
return $p
}
# This is a script to convert from our legacy CMD file / format for arguments
# to the Powershell - version.
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
$newArgs = @()
foreach ($arg in $args) {
if (($arg.Length -gt 0) -and ($arg[0] -eq '/')) {
$arg = '-' + $arg.Substring(1)
}
if ($arg -eq "-debug") {
$arg = "-release:`$false"
}
if ($arg -eq "-test32") {
$arg = "-test64:`$false"
}
$newArgs += $arg
}
Write-Host "New Args are $newArgs"
$script = Join-Path $PSScriptRoot "cibuild.ps1"
Invoke-Expression "$script $newArgs"
[CmdletBinding(PositionalBinding=$false)]
param (
[switch]$test64 = $false,
[switch]$testDeterminism = $false,
[switch]$testBuildCorrectness = $false,
[switch]$testPerfCorrectness = $false,
[switch]$testPerfRun = $false,
[switch]$testVsi = $false,
[switch]$skipTest = $false,
[switch]$skipRestore = $false,
[switch]$skipCommitPrinting = $false,
[switch]$release = $false
)
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
function Print-Usage() {
Write-Host "Usage: cibuild.cmd [-debug^|-release] [-test32^|-test64] [-restore]"
Write-Host " -debug Perform debug build. This is the default."
Write-Host " -release Perform release build."
Write-Host " -test32 Run unit tests in the 32-bit runner. This is the default."
Write-Host " -test64 Run units tests in the 64-bit runner."
}
function Run-MSBuild() {
# Because we override the C#/VB toolset to build against our LKG package, it is important
# that we do not reuse MSBuild nodes from other jobs/builds on the machine. Otherwise,
# we'll run into issues such as https://github.com/dotnet/roslyn/issues/6211.
# MSBuildAdditionalCommandLineArgs=
& $msbuild /nologo /m /nodeReuse:false /consoleloggerparameters:Verbosity=minimal /filelogger /fileloggerparameters:Verbosity=normal @args
if (-not $?) {
throw "Build failed"
}
}
# Kill any instances VBCSCompiler.exe to release locked files, ignoring stderr if process is not open
# This prevents future CI runs from failing while trying to delete those files.
# Kill any instances of msbuild.exe to ensure that we never reuse nodes (e.g. if a non-roslyn CI run
# left some floating around).
function Terminate-BuildProcesses() {
Get-Process msbuild -ErrorAction SilentlyContinue | kill
Get-Process vbcscompiler -ErrorAction SilentlyContinue | kill
}
try {
. (Join-Path $PSScriptRoot "build-utils.ps1")
Push-Location $repoDir
Write-Host "Parameters:"
foreach ($k in $PSBoundParameters.Keys) {
$v = $PSBoundParameters[$k]
Write-Host "`t$k=$v"
}
$buildConfiguration = if ($release) { "Release" } else { "Debug" }
$msbuildDir = Get-MSBuildDir
$msbuild = Join-Path $msbuildDir "msbuild.exe"
$configDir = Join-Path $binariesDIr $buildConfiguration
if (-not $skipRestore) {
Write-Host "Running restore"
& ".\build\scripts\restore.ps1" -msbuildDir $msbuildDir
}
# Ensure the binaries directory exists because msbuild can fail when part of the path to LogFile isn't present.
Create-Directory $binariesDir
if ($testBuildCorrectness) {
Exec { & ".\build\scripts\test-build-correctness.ps1" $repoDir $configDir }
exit 0
}
# Output the commit that we're building, for reference in Jenkins logs
if (-not $skipCommitPrinting) {
Write-Host "Building this commit:"
Exec { & git show --no-patch --pretty=raw HEAD }
}
# Build with the real assembly version, since that's what's contained in the bootstrap compiler redirects
$bootstrapLog = Join-Path $binariesDir "Bootstrap.log"
Run-MSBuild /p:UseShippingAssemblyVersion=true /p:InitialDefineConstants=BOOTSTRAP "build\Toolset\Toolset.csproj" /p:Configuration=$buildConfiguration /fileloggerparameters:LogFile=$($bootstrapLog)
Exec { & ".\build\scripts\check-msbuild.ps1" $bootstrapLog }
$bootstrapDir = Join-Path $binariesDir "Bootstrap"
Remove-Item -re $bootstrapDir -ErrorAction SilentlyContinue
Create-Directory $bootstrapDir
Move-Item "$configDir\Exes\Toolset\*" $bootstrapDir
Run-MSBuild /t:Clean "build\Toolset\Toolset.csproj" /p:Configuration=$buildConfiguration
Terminate-BuildProcesses
if ($testDeterminism) {
Exec { & ".\build\scripts\test-determinism.ps1" $bootstrapDir }
Terminate-BuildProcesses
exit 0
}
if ($testPerfCorrectness) {
Run-MSBuild Roslyn.sln /p:Configuration=$buildConfiguration /p:DeployExtension=false
Exec { & ".\Binaries\$buildConfiguration\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe" --ci-test }
exit 0
}
if ($testPerfRun) {
Run-MSBuild Roslyn.sln /p:Configuration=$buildConfiguration /p:DeployExtension=false
# Check if we have credentials to upload to benchview
if ((Test-Path env:\GIT_BRANCH) -and (Test-Path BV_UPLOAD_SAS_TOKEN)) {
$extraArgs="--report-benchview --branch $(env:GIT_BRANCH)"
# Check if we are in a PR or this is a rolling submission
if (Test-Path env:\ghprbPullTitle) {
$extraArgs='$($extraArgs) --benchview-submission-name "[$($env:ghprbPullAuthorLogin)] PR $($env:ghprbPullId): $($env:ghprbPullTitle)" --benchview-submission-type private'
}
else {
$extraArgs='$(4extraArgs) --benchview-submission-type rolling'
}
Create-Directory ".\Binaries\$buildConfiguration\tools\"
# Get the benchview tools - Place alongside Roslyn.Test.Performance.Runner.exe
Exec { & ".\build\scripts\install_benchview_tools.cmd" ".\Binaries\$buildConfiguration\tools\" }
}
Terminate-BuildProcesses
Exec { & ".\Binaries\$buildConfiguration\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe" --search-directory=".\\Binaries\\$buildConfiguration\\Dlls\\" --no-trace-upload $extraArgs }
exit 0
}
$target = if ($skipTest) { "Build" } else { "BuildAndTest" }
$test64Arg = if ($test64) { "true" } else { "false" }
$testVsiArg = if ($testVsi) { "true" } else { "false" }
$buildLog = Join-Path $binariesdir "Build.log"
Run-MSBuild /p:BootstrapBuildPath="$bootstrapDir" BuildAndTest.proj /t:$target /p:Configuration=$buildConfiguration /p:Test64=$test64Arg /p:TestVsi=$testVsiArg /p:PathMap="$($repoDir)=q:\roslyn" /p:Feature=pdb-path-determinism /fileloggerparameters:LogFile="$buildLog"`;verbosity=diagnostic /p:DeployExtension=false
Exec { & ".\build\scripts\check-msbuild.ps1" $buildLog }
exit 0
}
catch {
Write-Host $_
Write-Host $_.Exception
exit 1
}
finally {
Pop-Location
}
param (
[string]$nugetVersion = $(throw "Need a nuget version"),
[string]$destDir = $(throw "Need a path to download too"),
[string]$binariesDir = $(throw "Need path to Binaries directory"))
set-strictmode -version 2.0
param ([string]$nugetVersion = "3.6.0-beta1")
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"
try
{
$scratchDir = join-path $binariesDir "NuGet"
if (-not (test-path $scratchDir)) {
mkdir $scratchDir | out-null
}
try {
. (Join-Path $PSScriptRoot "build-utils.ps1")
if (-not (test-path $destDir)) {
mkdir $destDir | out-null
}
$scratchDir = Join-Path $binariesDir "NuGet"
Create-Directory $scratchDir
$destFile = join-path $destDir "NuGet.exe"
$scratchFile = join-path $scratchDir "NuGet.exe"
$versionFile = join-path $scratchDir "version.txt"
$destFile = Join-Path $repoDir "NuGet.exe"
$scratchFile = Join-Path $scratchDir "NuGet.exe"
$versionFile = Join-Path $scratchDir "version.txt"
# Check and see if we already have a NuGet.exe which exists and is the correct
# version.
if ((test-path $destFile) -and (test-path $scratchFile) -and (test-path $versionFile)) {
$destHash = (get-filehash $destFile -algorithm MD5).Hash
$scratchHash = (get-filehash $scratchFile -algorithm MD5).Hash
$scratchVersion = gc $versionFile
if ((Test-Path $destFile) -and (Test-Path $scratchFile) -and (Test-Path $versionFile)) {
$destHash = (Get-FileHash $destFile -algorithm MD5).Hash
$scratchHash = (Get-FileHash $scratchFile -algorithm MD5).Hash
$scratchVersion = Get-Content $versionFile
if (($destHash -eq $scratchHash) -and ($scratchVersion -eq $nugetVersion)) {
write-host "Using existing NuGet.exe at version $nuGetVersion"
Write-Host "Using existing NuGet.exe at version $nuGetVersion"
exit 0
}
}
write-host "Downloading NuGet.exe"
Write-Host "Downloading NuGet.exe"
$webClient = New-Object -TypeName "System.Net.WebClient"
$webClient.DownloadFile("https://dist.nuget.org/win-x86-commandline/v$nugetVersion/NuGet.exe", $scratchFile)
$nugetVersion | out-file $versionFile
cp $scratchFile $destFile
$nugetVersion | Out-File $versionFile
Copy-Item $scratchFile $destFile
exit 0
}
catch [exception]
{
write-host $_.Exception
exit -1
catch [exception] {
Write-Host $_.Exception
exit 1
}
Param(
[string] $locateVsApiVersion = "0.2.4-beta"
)
set-strictmode -version 2.0
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"
function Create-Directory([string[]] $path) {
if (!(Test-Path -path $path)) {
New-Item -path $path -force -itemType "Directory" | Out-Null
}
try {
. (Join-Path $PSScriptRoot "build-utils.ps1")
$p = Get-VisualStudioDir
Write-Host (Join-Path $p "Common7\Tools\")
}
function Locate-LocateVsApi {
$packagesPath = Locate-PackagesPath
$locateVsApi = Join-Path -path $packagesPath -ChildPath "RoslynTools.Microsoft.LocateVS\$locateVsApiVersion\tools\LocateVS.dll"
if (!(Test-Path -path $locateVsApi)) {
throw "The specified LocateVS API version ($locateVsApiVersion) could not be located."
}
return Resolve-Path -path $locateVsApi
}
function Locate-PackagesPath {
if ($env:NUGET_PACKAGES -eq $null) {
$env:NUGET_PACKAGES = Join-Path -path $env:UserProfile -childPath ".nuget\packages\"
}
$packagesPath = $env:NUGET_PACKAGES
Create-Directory -path $packagesPath
return Resolve-Path -path $packagesPath
}
try
{
$locateVsApi = Locate-LocateVsApi
$requiredPackageIds = @()
$requiredPackageIds += "Microsoft.Component.MSBuild"
$requiredPackageIds += "Microsoft.Net.Component.4.6.TargetingPack"
$requiredPackageIds += "Microsoft.VisualStudio.Component.PortableLibrary"
$requiredPackageIds += "Microsoft.VisualStudio.Component.Roslyn.Compiler"
$requiredPackageIds += "Microsoft.VisualStudio.Component.VSSDK"
Add-Type -path $locateVsApi
$visualStudioInstallationPath = [LocateVS.Instance]::GetInstallPath("15.0", $requiredPackageIds)
return Join-Path -Path $visualStudioInstallationPath -ChildPath "Common7\Tools\"
}
catch
{
catch {
Write-Error $_.Exception.Message
# Return an empty string and let the caller fallback or handle this as appropriate
return ""
......
# This is a script to convert from our legacy CMD file / format for arguments
# to the Powershell - version.
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
$newArgs = @()
foreach ($arg in $args) {
if (($arg.Length -gt 0) -and ($arg[0] -eq '/')) {
$arg = '-' + $arg.Substring(1)
}
$newArgs += $arg
}
Write-Host "New Args are $newArgs"
$script = Join-Path $PSScriptRoot "restore.ps1"
Invoke-Expression "$script $newArgs"
[CmdletBinding(PositionalBinding=$false)]
param (
[switch]$clean = $false,
[switch]$fast = $false,
[string]$msbuildDir = "")
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"
function Run-Restore([string]$name, [string]$fileName) {
Write-Host "Restoring $name"
$nugetConfig = Join-Path $repoDir "nuget.config"
$filePath = Join-Path $repoDir $fileName
Exec { & $nuget restore -verbosity quiet -configfile $nugetConfig -MSBuildPath $msbuildDir -Project2ProjectTimeOut 1200 $filePath }
}
try {
. (Join-Path $PSScriptRoot "build-utils.ps1")
$nuget = Ensure-NuGet
if ($msbuildDir -eq "") {
$msbuildDir = Get-MSBuildDir
}
Write-Host "Restore using MSBuild at $msbuildDir"
if ($clean) {
Write-Host "Clearing the NuGet caches"
Exec { & $nuget locals all -clear }
}
if (-not $fast) {
Write-Host "Deleting project.lock.json files"
Get-ChildItem $repoDir -re -in project.lock.json | Remove-Item
}
Run-Restore "Toolsets" "build\ToolsetPackages\project.json"
Run-Restore "Toolsets (Dev14 VS SDK build tools)" "build\ToolsetPackages\dev14.project.json"
Run-Restore "Toolsets (Dev15 VS SDK RC build tools)" "build\ToolsetPackages\dev15rc.project.json"
Run-Restore "Samples" "src\Samples\Samples.sln"
Run-Restore "Templates" "src\Setup\Templates\Templates.sln"
Run-Restore "Toolsets Compiler" "build\Toolset\Toolset.csproj"
Run-Restore "Roslyn" "Roslyn.sln"
Run-Restore "DevDivInsertionFiles" "src\Setup\DevDivInsertionFiles\DevDivInsertionFiles.sln"
Run-Restore "DevDiv Roslyn Packages" "src\Setup\DevDivPackages\Roslyn\project.json"
Run-Restore "DevDiv Debugger Packages" "src\Setup\DevDivPackages\Debugger\project.json"
}
catch {
Write-Host $_
exit 1
}
# Script for testing out the various functions on a given machine. Useful for
# debugging Jeknins issues.
param ([switch]$simple = $false)
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"
try {
if (-not $simple) {
Set-PSDebug -Trace 2
}
. (Join-Path $PSScriptRoot "build-utils.ps1")
Write-Host "Calling Get-MSBuildKindAndDir"
Get-MSBuildKindAndDir
Write-Host "Calling Get-MSBuildDir"
Get-MSBuildDir
try {
Write-Host "Calling Get-VisualStudioDir"
Get-VisualStudioDir
}
catch {
Write-Host "Unable to find Visual Studio (expected on a machine without VS)"
Write-Host $_
}
}
catch {
Write-Host $_.Exception.Message
exit 1
}
finally {
Set-PSDebug -Trace 0
}
@setlocal enabledelayedexpansion
REM Parse Arguments.
set RoslynRoot=%~dp0
set BuildConfiguration=Debug
REM Because override the C#/VB toolset to build against our LKG package, it is important
REM that we do not reuse MSBuild nodes from other jobs/builds on the machine. Otherwise,
REM we'll run into issues such as https://github.com/dotnet/roslyn/issues/6211.
set MSBuildAdditionalCommandLineArgs=/nologo /m /nodeReuse:false /consoleloggerparameters:Verbosity=minimal /filelogger /fileloggerparameters:Verbosity=normal
set BuildAndTestBuildTarget=BuildAndTest
:ParseArguments
if "%1" == "" goto :DoneParsing
if /I "%1" == "/?" call :Usage && exit /b 1
if /I "%1" == "/debug" set BuildConfiguration=Debug&&shift&& goto :ParseArguments
if /I "%1" == "/release" set BuildConfiguration=Release&&shift&& goto :ParseArguments
if /I "%1" == "/test32" set Test64=false&&shift&& goto :ParseArguments
if /I "%1" == "/test64" set Test64=true&&shift&& goto :ParseArguments
if /I "%1" == "/testDeterminism" set TestDeterminism=true&&shift&& goto :ParseArguments
if /I "%1" == "/testBuildCorrectness" set TestBuildCorrectness=true&&shift&& goto :ParseArguments
if /I "%1" == "/testPerfCorrectness" set TestPerfCorrectness=true&&shift&& goto :ParseArguments
if /I "%1" == "/testPerfRun" set TestPerfRun=true&&shift&& goto :ParseArguments
if /I "%1" == "/testVsi" set TestVsi=true&&shift&& goto :ParseArguments
if /I "%1" == "/skipTest" set BuildAndTestBuildTarget=Build&&shift&&goto :ParseArguments
if /I "%1" == "/skipCommitPrinting" set SkipCommitPrinting=1&&shift&&goto :ParseArguments
REM /buildTimeLimit is the time limit, measured in minutes, for the Jenkins job that runs
REM the build. The Jenkins script netci.groovy passes the time limit to this script.
if /I "%1" == "/buildTimeLimit" set BuildTimeLimit=%2&&shift&&shift&& goto :ParseArguments
call :Usage && exit /b 1
:DoneParsing
REM This script takes the presence of the /buildTimeLimit option as an indication that it
REM should run the tests under the control of the ProcessWatchdog, which, if the tests
REM exceed the time limit, will take a screenshot, obtain memory dumps from the test
REM process and all its descendants, and shut those processes down.
REM
REM Developers building from the command line will presumably not pass /buildTimeLimit,
REM and so the tests will not run under the ProcessWatchdog.
if not "%BuildTimeLimit%" == "" (
set CurrentDate=%date%
set CurrentTime=%time: =0%
set BuildStartTime=!CurrentDate:~-4!-!CurrentDate:~-10,2!-!CurrentDate:~-7,2!T!CurrentTime!
set RunProcessWatchdog=true
) else (
set RunProcessWatchdog=false
)
REM Restore the NuGet packages
call "%RoslynRoot%\Restore.cmd" || goto :BuildFailed
call "%RoslynRoot%SetDevCommandPrompt.cmd" || goto :BuildFailed
REM Ensure the binaries directory exists because msbuild can fail when part of the path to LogFile isn't present.
set bindir=%RoslynRoot%Binaries
if not exist "%bindir%" mkdir "%bindir%" || goto :BuildFailed
if defined testBuildCorrectness (
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\test-build-correctness.ps1" %RoslynRoot% "%bindir%\%BuildConfiguration%" || goto :BuildFailed
call :TerminateBuildProcesses
exit /b 0
)
REM Output the commit that we're building, for reference in Jenkins logs
if not "%SkipCommitPrinting" == "1" (
echo Building this commit:
git show --no-patch --pretty=raw HEAD
)
REM Build with the real assembly version, since that's what's contained in the bootstrap compiler redirects
msbuild %MSBuildAdditionalCommandLineArgs% /p:UseShippingAssemblyVersion=true /p:InitialDefineConstants=BOOTSTRAP "%RoslynRoot%build\Toolset\Toolset.csproj" /p:NuGetRestorePackages=false /p:Configuration=%BuildConfiguration% /fileloggerparameters:LogFile="%bindir%\Bootstrap.log" || goto :BuildFailed
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\check-msbuild.ps1" "%bindir%\Bootstrap.log" || goto :BuildFailed
if not exist "%bindir%\Bootstrap" mkdir "%bindir%\Bootstrap" || goto :BuildFailed
move "Binaries\%BuildConfiguration%\Exes\Toolset\*" "%bindir%\Bootstrap" || goto :BuildFailed
REM Clean the previous build
msbuild %MSBuildAdditionalCommandLineArgs% /t:Clean build/Toolset/Toolset.csproj /p:Configuration=%BuildConfiguration% /fileloggerparameters:LogFile="%bindir%\BootstrapClean.log" || goto :BuildFailed
call :TerminateBuildProcesses || goto :BuildFailed
if defined TestDeterminism (
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\test-determinism.ps1" "%bindir%\Bootstrap" || goto :BuildFailed
call :TerminateBuildProcesses || goto :BuildFailed
exit /b 0
)
if defined TestPerfCorrectness (
msbuild %MSBuildAdditionalCommandLineArgs% Roslyn.sln /p:Configuration=%BuildConfiguration% /p:DeployExtension=false || goto :BuildFailed
.\Binaries\%BuildConfiguration%\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe --ci-test || goto :BuildFailed
exit /b 0
)
if defined TestPerfRun (
msbuild %MSBuildAdditionalCommandLineArgs% Roslyn.sln /p:Configuration=%BuildConfiguration% /p:DeployExtension=false || goto :BuildFailed
if defined GIT_BRANCH (
REM Check if we have credentials to upload to benchview
if defined BV_UPLOAD_SAS_TOKEN (
set "EXTRA_PERF_RUNNER_ARGS=--report-benchview --branch "%GIT_BRANCH%""
REM Check if we are in a PR or this is a rolling submission
if defined ghprbPullTitle (
set "EXTRA_PERF_RUNNER_ARGS=!EXTRA_PERF_RUNNER_ARGS! --benchview-submission-name ""[%ghprbPullAuthorLogin%] PR %ghprbPullId%: %ghprbPullTitle%"" --benchview-submission-type private"
) else (
set "EXTRA_PERF_RUNNER_ARGS=!EXTRA_PERF_RUNNER_ARGS! --benchview-submission-type rolling"
)
mkdir ".\Binaries\%BuildConfiguration%\tools\"
REM Get the benchview tools - Place alongside Roslyn.Test.Performance.Runner.exe
call "%RoslynRoot%\build\scripts\install_benchview_tools.cmd" ".\Binaries\%BuildConfiguration%\tools\" || goto :BuildFailed
dir ".\Binaries\%BuildConfiguration%\"
)
)
call :TerminateBuildProcesses || goto :BuildFailed
.\Binaries\%BuildConfiguration%\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe --search-directory=".\\Binaries\\%BuildConfiguration%\\Dlls\\" --no-trace-upload !EXTRA_PERF_RUNNER_ARGS! || goto :BuildFailed
exit /b 0
)
msbuild %MSBuildAdditionalCommandLineArgs% /p:BootstrapBuildPath="%bindir%\Bootstrap" BuildAndTest.proj /t:%BuildAndTestBuildTarget% /p:Configuration=%BuildConfiguration% /p:Test64=%Test64% /p:TestVsi=%TestVsi% /p:RunProcessWatchdog=%RunProcessWatchdog% /p:BuildStartTime=%BuildStartTime% /p:"ProcDumpExe=%ProcDumpExe%" /p:BuildTimeLimit=%BuildTimeLimit% /p:PathMap="%RoslynRoot%=q:\roslyn" /p:Feature=pdb-path-determinism /fileloggerparameters:LogFile="%bindir%\Build.log";verbosity=diagnostic /p:DeployExtension=false || goto :BuildFailed
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\check-msbuild.ps1" "%bindir%\Build.log" || goto :BuildFailed
call :TerminateBuildProcesses || goto :BuildFailed
REM Ensure caller sees successful exit.
exit /b 0
:Usage
@echo Usage: cibuild.cmd [/debug^|/release] [/test32^|/test64] [/restore]
@echo /debug Perform debug build. This is the default.
@echo /release Perform release build.
@echo /test32 Run unit tests in the 32-bit runner. This is the default.
@echo /test64 Run units tests in the 64-bit runner.
@echo.
@goto :eof
:BuildFailed
echo Build failed with ERRORLEVEL %ERRORLEVEL%
call :TerminateBuildProcesses
exit /b 1
:TerminateBuildProcesses
@REM Kill any instances VBCSCompiler.exe to release locked files, ignoring stderr if process is not open
@REM This prevents future CI runs from failing while trying to delete those files.
@REM Kill any instances of msbuild.exe to ensure that we never reuse nodes (e.g. if a non-roslyn CI run
@REM left some floating around).
@REM An error-level of 1 means that the process was found, but could not be killed.
echo Killing all build-related processes
taskkill /F /IM msbuild.exe > nul 2>&1
if %ERRORLEVEL% == 1 (
echo ERROR: taskkill for msbuild.exe failed
exit /b 1
)
taskkill /F /IM vbcscompiler.exe > nul 2>&1
if %ERRORLEVEL% == 1 (
echo ERROR: taskkill for vbcscompiler.exe failed
exit /b 1
)
exit /b 0
@if not defined EchoOn @echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\cibuild-legacy.ps1" %*
......@@ -22,7 +22,7 @@
</PropertyGroup>
<Target Name="Build">
<Exec Command="Restore.cmd /clean" WorkingDirectory="$(RepoRoot)" Condition="'$(SkipRestore)' != 'true'" />
<Exec Command="powershell -noprofile -executionPolicy ByPass -file build\scripts\restore.ps1 -clean -msbuildDir &quot;$(MSBuildBinPath)&quot;" WorkingDirectory="$(RepoRoot)" />
<MSBuild Projects="$(RepoRoot)Roslyn.sln" BuildInParallel="true" Properties="DeployExtension=false" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册