build.ps1 26.4 KB
Newer Older
J
Jared Parsons 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#
# This script controls the Roslyn build process. This encompasess everything from build, testing to
# publishing of NuGet packages. The intent is to structure it to allow for a simple flow of logic 
# between the following phases:
#
#   - restore
#   - build
#   - sign
#   - pack
#   - test
#   - publish
#
# Each of these phases has a separate command which can be executed independently. For instance 
# it's fine to call `build.ps1 -build -testDesktop` followed by repeated calls to 
# `.\build.ps1 -testDesktop`. 

J
Jared Parsons 已提交
17 18
[CmdletBinding(PositionalBinding=$false)]
param (
J
Jared Parsons 已提交
19
    # Configuration
J
Jared Parsons 已提交
20
    [switch]$restore = $false,
J
Jared Parsons 已提交
21
    [switch]$release = $false,
S
Shyam N 已提交
22
    [switch]$official = $false,
J
Jared Parsons 已提交
23 24
    [switch]$cibuild = $false,
    [switch]$build = $false,
25
    [switch]$buildCoreClr = $false,
J
Jared Parsons 已提交
26
    [switch]$bootstrap = $false,
27
    [switch]$sign = $false,
28
    [switch]$pack = $false,
J
Jared Parsons 已提交
29
    [switch]$binaryLog = $false,
30
    [switch]$noAnalyzers = $false,
J
Jared Parsons 已提交
31
    [string]$signType = "",
J
Jared Parsons 已提交
32 33 34

    # Test options 
    [switch]$test32 = $false,
J
Fixes  
Jared Parsons 已提交
35
    [switch]$test64 = $false,
36 37 38 39
    [switch]$testVsi = $false,
    [switch]$testVsiNetCore = $false,
    [switch]$testDesktop = $false,
    [switch]$testCoreClr = $false,
40
    [switch]$testIOperation = $false,
41 42 43 44 45 46 47

    # Special test options
    [switch]$testDeterminism = $false,
    [switch]$testBuildCorrectness = $false,
    [switch]$testPerfCorrectness = $false,
    [switch]$testPerfRun = $false,

J
Fixup  
Jared Parsons 已提交
48
    [parameter(ValueFromRemainingArguments=$true)] $badArgs)
J
Jared Parsons 已提交
49 50

Set-StrictMode -version 2.0
J
Jared Parsons 已提交
51
$ErrorActionPreference = "Stop"
J
Jared Parsons 已提交
52 53

function Print-Usage() {
J
Jared Parsons 已提交
54 55 56
    Write-Host "Usage: build.ps1"
    Write-Host "  -release                  Perform release build (default is debug)"
    Write-Host "  -restore                  Restore packages"
57
    Write-Host "  -build                    Build Roslyn.sln"
S
Shyam N 已提交
58
    Write-Host "  -official                 Perform an official build"
J
Jared Parsons 已提交
59
    Write-Host "  -bootstrap                Build using a bootstrap Roslyn"
J
Jared Parsons 已提交
60
    Write-Host "  -sign                     Sign our binaries"
J
Jared Parsons 已提交
61
    Write-Host "  -signType                 Type of sign: real, test, verify"
62
    Write-Host "  -pack                     Create our NuGet packages"
J
Jared Parsons 已提交
63
    Write-Host "  -binaryLog                Create binary log for every MSBuild invocation"
J
Jared Parsons 已提交
64 65 66 67 68 69 70 71
    Write-Host "" 
    Write-Host "Test options" 
    Write-Host "  -test32                   Run unit tests in the 32-bit runner"
    Write-Host "  -test64                   Run units tests in the 64-bit runner"
    Write-Host "  -testDesktop              Run desktop unit tests"
    Write-Host "  -testCoreClr              Run CoreClr unit tests"
    Write-Host "  -testVsi                  Run all integration tests"
    Write-Host "  -testVsiNetCore           Run just dotnet core integration tests"
G
Gen Lu 已提交
72
    Write-Host "  -testIOperation           Run extra checks to validate IOperations"
73 74
    Write-Host ""
    Write-Host "Special Test options" 
J
Jared Parsons 已提交
75
    Write-Host "  -testBuildCorrectness     Run build correctness tests"
76
    Write-Host "  -testDeterminism          Run determinism tests"
J
Jared Parsons 已提交
77
    Write-Host "  -testPerfCorrectness      Run perf correctness tests"
78
    Write-Host "  -testPerfCorrectness      Run perf tests"
J
Jared Parsons 已提交
79 80
}

81 82 83 84
# Process the command line arguments and establish defaults for the values which are not 
# specified.
#
# In this function it's okay to use two arguments to extend the effect of another. For 
J
Jared Parsons 已提交
85
# example it's okay to look at $buildCoreClr and infer $build. It's not okay though to infer 
86 87
# $build based on say $testDesktop. It's possible the developer wanted only for testing 
# to execute, not any build.
J
Jared Parsons 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
function Process-Arguments() {
    if ($badArgs -ne $null) {
        Write-Host "Unsupported argument $badArgs"
        Print-Usage
        exit 1
    }

    if ($test32 -and $test64) {
        Write-Host "Cannot combine -test32 and -test64"
        exit 1
    }

    $anyVsi = $testVsi -or $testVsiNetCore
    $anyUnit = $testDesktop -or $testCoreClr
    if ($anyUnit -and $anyVsi) {
        Write-Host "Cannot combine unit and VSI testing"
        exit 1
J
Jared Parsons 已提交
105 106
    }

107 108 109 110 111 112
    $script:isAnyTestSpecial = $testBuildCorrectness -or $testDeterminism -or $testPerfCorrectness -or $testPerfRun
    if ($isAnyTestSpecial -and ($anyUnit -or $anyVsi)) {
        Write-Host "Cannot combine special testing with any other action"
        exit 1
    }

J
Jared Parsons 已提交
113
    if ($buildCoreClr) {
114 115 116
        $script:build = $true
    }

117 118
    $script:test32 = -not $test64
    $script:debug = -not $release
J
Jared Parsons 已提交
119 120
}

121
function Run-MSBuild([string]$projectFilePath, [string]$buildArgs = "", [string]$logFileName = "", [switch]$parallel = $true, [switch]$useDotnetBuild = $false) {
J
Jared Parsons 已提交
122 123 124 125
    # 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=
J
Jared Parsons 已提交
126
    $args = "/p:TreatWarningsAsErrors=true /warnaserror /nologo /nodeReuse:false /consoleloggerparameters:Verbosity=minimal;summary /p:Configuration=$buildConfiguration";
127 128 129 130

    if ($parallel) {
        $args += " /m"
    }
131 132 133 134 135 136

    if ($noAnalyzers -or ($cibuild -and $testVsi)) {
        # Avoid spending time in analyzers when requested, and also in the slowest integration test builds
        $args += " /p:UseRoslynAnalyzers=false"
    }

J
Jared Parsons 已提交
137 138 139 140 141
    if ($binaryLog) {
        if ($logFileName -eq "") { 
            $logFileName = [IO.Path]::GetFileNameWithoutExtension($projectFilePath)
        }
        $logFileName = [IO.Path]::ChangeExtension($logFileName, ".binlog")
142
        $logFilePath = Join-Path $logsDir $logFileName
J
Jared Parsons 已提交
143
        $args += " /bl:$logFilePath"
J
Jared Parsons 已提交
144 145
    }

S
Shyam N 已提交
146 147 148 149
    if ($official) {
        $args += " /p:OfficialBuild=true"
    }

150 151 152 153
    if ($bootstrapDir -ne "") {
        $args += " /p:BootstrapBuildPath=$bootstrapDir"
    }

154
    if ($testIOperation) {
155 156 157
        $args += " /p:TestIOperationInterface=true"
    }

J
Jared Parsons 已提交
158
    $args += " $buildArgs"
J
Jared Parsons 已提交
159
    $args += " $projectFilePath"
160 161

    if ($useDotnetBuild) {
J
Jared Parsons 已提交
162
        $args = " msbuild $args"
163 164 165 166 167
        Exec-Console $dotnet $args
    }
    else {
        Exec-Console $msbuild $args
    }
J
Jared Parsons 已提交
168 169
}

170 171 172 173 174 175 176 177 178 179 180 181 182
# Restore all of the projects that the repo consumes
function Restore-Packages() {
    Write-Host "Restore using dotnet at $dotnet"

    $all = @(
        "Roslyn Toolset:build\ToolsetPackages\RoslynToolset.csproj",
        "Roslyn:Roslyn.sln")

    foreach ($cur in $all) {
        $both = $cur.Split(':')
        Write-Host "Restoring $($both[0])"
        $projectFilePath = $both[1]
        $projectFileName = [IO.Path]::GetFileNameWithoutExtension($projectFilePath)
J
Jared Parsons 已提交
183 184 185 186
        $logFilePath = ""
        if ($binaryLog) { 
            $logFilePath = Join-Path $logsDir "Restore-$($projectFileName).binlog"
        }
187 188 189 190
        Restore-Project $dotnet $both[1] $logFilePath
    }
}

J
Jared Parsons 已提交
191
# Create a bootstrap build of the compiler.  Returns the directory where the bootstrap build 
J
Jared Parsons 已提交
192 193 194 195 196 197
# is located. 
#
# Important to not set $script:bootstrapDir here yet as we're actually in the process of 
# building the bootstrap.
function Make-BootstrapBuild() {
    $dir = Join-Path $binariesDir "Bootstrap"
198 199
    Write-Host "Building Bootstrap compiler"
    $bootstrapArgs = "/p:UseShippingAssemblyVersion=true /p:InitialDefineConstants=BOOTSTRAP"
J
Jared Parsons 已提交
200 201
    Remove-Item -re $dir -ErrorAction SilentlyContinue
    Create-Directory $dir
202 203
    if ($buildCoreClr) {
        $bootstrapFramework = "netcoreapp2.0"
204 205 206 207 208 209 210 211 212
        $projectFiles = @(
            'src/Compilers/CSharp/csc/csc.csproj',
            'src/Compilers/VisualBasic/vbc/vbc.csproj',
            'src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj',
            'src/Compilers/Core/MSBuildTask/MSBuildTask.csproj'
        )

        foreach ($projectFilePath in $projectFiles) { 
            $fileName = [IO.Path]::GetFileNameWithoutExtension((Split-Path -leaf $projectFilePath))
J
Jared Parsons 已提交
213 214
            $logFileName = "Bootstrap$($fileName)"
            Run-MSBuild $projectFilePath "/t:Publish /p:TargetFramework=netcoreapp2.0 $bootstrapArgs" -logFileName $logFileName -useDotnetBuild
215 216
        }

J
Jared Parsons 已提交
217 218 219
        # The csi executable is only supported on desktop (even though we do multi-target it to 
        # netcoreapp2.). Need to build the desktop version here in order to build our NuGet 
        # packages below. 
J
Jared Parsons 已提交
220
        Run-MSBuild "src/Interactive/csi/csi.csproj" -logFileName "BootstrapCsi" -useDotnetBuild
221 222

        Ensure-NuGet | Out-Null
J
Jared Parsons 已提交
223 224
        Exec-Console "$configDir\Exes\csi\net46\csi.exe" "$repoDir\src\NuGet\BuildNuGets.csx $configDir 42.42.42.42-bootstrap $dir `"<developer build>`" Microsoft.NETCore.Compilers.nuspec"
        Unzip-File "$dir\Microsoft.NETCore.Compilers.42.42.42.42-bootstrap.nupkg" "$dir\Microsoft.NETCore.Compilers\42.42.42.42"
225

226
        Write-Host "Cleaning Bootstrap compiler artifacts"
J
Jared Parsons 已提交
227
        Run-MSBuild "Compilers.sln" "/t:Clean"
228 229 230 231 232 233
        Stop-BuildProcesses
    }
    else {
        Run-MSBuild "build\Toolset\Toolset.csproj" $bootstrapArgs -logFileName "Bootstrap"
        Remove-Item -re $dir -ErrorAction SilentlyContinue
        Create-Directory $dir
234 235

        Ensure-NuGet | Out-Null
J
Jared Parsons 已提交
236 237
        Exec-Console "$configDir\Exes\csi\net46\csi.exe" "$repoDir\src\NuGet\BuildNuGets.csx $configDir 42.42.42.42-bootstrap $dir `"<developer build>`" Microsoft.Net.Compilers.nuspec"
        Unzip-File "$dir\Microsoft.Net.Compilers.42.42.42.42-bootstrap.nupkg" "$dir\Microsoft.Net.Compilers\42.42.42.42"
238 239 240 241 242

        Write-Host "Cleaning Bootstrap compiler artifacts"
        Run-MSBuild "build\Toolset\Toolset.csproj" "/t:Clean" -logFileName "BootstrapClean"
        Stop-BuildProcesses
    }
243

244
    return $dir
J
Jared Parsons 已提交
245 246
}

247
function Build-Artifacts() { 
248 249 250 251
    if ($buildCoreClr) {
        Run-MSBuild "Compilers.sln" -useDotnetBuild
    }
    elseif ($build) {
J
Jared Parsons 已提交
252
        Run-MSBuild "Roslyn.sln" "/p:DeployExtension=false"
253
        Build-ExtraSignArtifacts
254 255 256 257 258 259 260 261 262 263
    }

    if ($pack) {
        Build-NuGetPackages
    }

    if ($sign) {
        Run-SignTool
    }

J
Jared Parsons 已提交
264 265 266 267
    if ($pack -and ($cibuild -or $official)) { 
        Build-DeployToSymStore
    }

J
Jared Parsons 已提交
268 269 270
    if ($build -and (-not $buildCoreClr)) {
        Build-InsertionItems
    }
271 272
}

273 274 275 276
# Not all of our artifacts needed for signing are included inside Roslyn.sln. Need to 
# finish building these before we can run signing.
function Build-ExtraSignArtifacts() { 

J
Jared Parsons 已提交
277
    Ensure-NuGet | Out-Null
278 279 280
    Push-Location (Join-Path $repoDir "src\Setup")
    try {
        # Publish the CoreClr projects (CscCore and VbcCore) and dependencies for later NuGet packaging.
281
        Write-Host "Publishing csc"
J
Jared Parsons 已提交
282
        Run-MSBuild "..\Compilers\CSharp\csc\csc.csproj" "/p:TargetFramework=netcoreapp2.0 /t:PublishWithoutBuilding"
A
Ashley Hauck 已提交
283
        Write-Host "Publishing vbc"
J
Jared Parsons 已提交
284
        Run-MSBuild "..\Compilers\VisualBasic\vbc\vbc.csproj" "/p:TargetFramework=netcoreapp2.0 /t:PublishWithoutBuilding"
A
Ashley Hauck 已提交
285 286
        Write-Host "Publishing VBCSCompiler"
        Run-MSBuild "..\Compilers\Server\VBCSCompiler\VBCSCompiler.csproj" "/p:TargetFramework=netcoreapp2.0 /t:PublishWithoutBuilding"
287
        Write-Host "Publishing MSBuildTask"
J
Jared Parsons 已提交
288
        Run-MSBuild "..\Compilers\Core\MSBuildTask\MSBuildTask.csproj" "/p:TargetFramework=netcoreapp2.0 /t:PublishWithoutBuilding"
289

J
Jared Parsons 已提交
290
        $dest = @($configDir)
291 292 293 294
        foreach ($dir in $dest) { 
            Copy-Item "PowerShell\*.ps1" $dir
        }

295
        Copy-Item -Force "Vsix\myget_org-extensions.config" $configDir
296 297 298 299 300 301
    }
    finally {
        Pop-Location
    }
}

302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
function Build-InsertionItems() { 

    # Create the PerfTests directory under Binaries\$(Configuration).  There are still a number
    # of tools (in roslyn and roslyn-internal) that depend on this combined directory.
    function Create-PerfTests() {
        $target = Join-Path $configDir "PerfTests"
        Write-Host "PerfTests: $target"
        Create-Directory $target

        Push-Location $configDir
        foreach ($subDir in @("Dlls", "UnitTests")) {
            Push-Location $subDir
            foreach ($path in Get-ChildItem -re -in "PerfTests") {
                Write-Host "`tcopying $path"
                Copy-Item -force -recurse "$path\*" $target
            }
            Pop-Location
        }
        Pop-Location
    }

    $setupDir = Join-Path $repoDir "src\Setup"
    Push-Location $setupDir
    try { 
        Create-PerfTests
J
Jared Parsons 已提交
327
        Exec-Console (Join-Path $configDir "Exes\DevDivInsertionFiles\Roslyn.BuildDevDivInsertionFiles.exe") "$configDir $repoDir $(Get-PackagesDir)"
328 329 330 331 332 333 334 335
        
        # In non-official builds need to supply values for a few MSBuild properties. The actual value doesn't
        # matter, just that it's provided some value.
        $extraArgs = ""
        if (-not $official) { 
            $extraArgs = " /p:FinalizeValidate=false /p:ManifestPublishUrl=https://vsdrop.corp.microsoft.com/file/v1/Products/DevDiv/dotnet/roslyn/master/20160729.6"
        }

J
Jared Parsons 已提交
336 337 338 339
        Run-MSBuild "DevDivPackages\Roslyn.proj" -logFileName "RoslynPackagesProj"
        Run-MSBuild "DevDivVsix\PortableFacades\PortableFacades.vsmanproj" -buildArgs $extraArgs
        Run-MSBuild "DevDivVsix\CompilersPackage\Microsoft.CodeAnalysis.Compilers.vsmanproj" -buildArgs $extraArgs
        Run-MSBuild "DevDivVsix\MicrosoftCodeAnalysisLanguageServices\Microsoft.CodeAnalysis.LanguageServices.vsmanproj" -buildArgs "$extraArgs"
340 341 342 343 344 345
        Run-MSBuild "..\Dependencies\Microsoft.NetFX20\Microsoft.NetFX20.nuget.proj"
    }
    finally {
        Pop-Location
    }
}
346

347
function Build-NuGetPackages() {
J
Jared Parsons 已提交
348
    $buildArgs = ""
349
    if (-not $official) {
J
Jared Parsons 已提交
350
        $buildArgs = '/p:SkipReleaseVersion=true /p:SkipPreReleaseVersion=true'
351 352
    }

J
Jared Parsons 已提交
353
    Ensure-NuGet | Out-Null
J
Jared Parsons 已提交
354
    Run-MSBuild "src\NuGet\NuGet.proj" $buildArgs
355
}
356

T
Tomas Matousek 已提交
357
function Build-DeployToSymStore() {
J
Jared Parsons 已提交
358
    Run-MSBuild "Roslyn.sln" "/t:DeployToSymStore" -logFileName "RoslynDeployToSymStore"
T
Tomas Matousek 已提交
359 360
}

361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
# These are tests that don't follow our standard restore, build, test pattern. They customize 
# the processes in order to test specific elements of our build and hence are handled 
# separately from our other tests
function Test-Special() {
    if ($testBuildCorrectness) {
        Exec-Block { & ".\build\scripts\test-build-correctness.ps1" -config $buildConfiguration } | Out-Host
    }
    elseif ($testDeterminism) {
        $bootstrapDir = Make-BootstrapBuild
        Exec-Block { & ".\build\scripts\test-determinism.ps1" -bootstrapDir $bootstrapDir } | Out-Host
    } 
    elseif ($testPerfCorrectness) {
        Test-PerfCorrectness
    }
    elseif ($testPerfRun) {
        Test-PerfRun
    }
    else {
        throw "Not a special test"
    }
}

J
Jared Parsons 已提交
383
function Test-PerfCorrectness() {
J
Jared Parsons 已提交
384
    Run-MSBuild "Roslyn.sln" "/p:DeployExtension=false" -logFileName "RoslynPerfCorrectness"
J
Jared Parsons 已提交
385 386 387 388
    Exec-Block { & ".\Binaries\$buildConfiguration\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe" --ci-test } | Out-Host
}

function Test-PerfRun() { 
J
Jared Parsons 已提交
389
    Run-MSBuild "Roslyn.sln" "/p:DeployExtension=false" -logFileName "RoslynPerfRun"
J
Jared Parsons 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418

    # Check if we have credentials to upload to benchview
    $extraArgs = @()
    if ((Test-Path env:\GIT_BRANCH) -and (Test-Path env:\BV_UPLOAD_SAS_TOKEN)) {
        $extraArgs += "--report-benchview"
        $extraArgs += "--branch=$env:GIT_BRANCH"

        # Check if we are in a PR or this is a rolling submission
        if (Test-Path env:\ghprbPullTitle) {
            $submissionName = $env:ghprbPullTitle.Replace(" ", "_")
            $extraArgs += "--benchview-submission-name=""$submissionName"""
            $extraArgs += "--benchview-submission-type=private"
        } 
        else {
            $extraArgs += "--benchview-submission-type=rolling"
        }

        Create-Directory ".\Binaries\$buildConfiguration\tools\"
        # Get the benchview tools - Place alongside Roslyn.Test.Performance.Runner.exe
        Exec-Block { & ".\build\scripts\install_benchview_tools.cmd" ".\Binaries\$buildConfiguration\tools\" } | Out-Host
    }

    Stop-BuildProcesses
    & ".\Binaries\$buildConfiguration\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe"  $extraArgs --search-directory=".\\Binaries\\$buildConfiguration\\Dlls\\" --no-trace-upload
    if (-not $?) { 
        throw "Perf run failed"
    }
}

A
Ashley Hauck 已提交
419 420 421 422 423
function Test-XUnitCoreClr() {
    Write-Host "Publishing ILAsm.csproj"
    $toolsDir = Join-Path $binariesDir "Tools"
    $ilasmDir = Join-Path $toolsDir "ILAsm"
    Exec-Console $dotnet "publish src\Tools\ILAsm --no-restore --runtime win-x64 --self-contained -o $ilasmDir"
424

425 426
    $unitDir = Join-Path $configDir "UnitTests"
    $tf = "netcoreapp2.0"
427 428
    $xunitResultDir = Join-Path $unitDir "xUnitResults"
    Create-Directory $xunitResultDir 
429
    $xunitConsole = Join-Path (Get-PackageDir "xunit.runner.console") "tools\$tf\xunit.console.dll"
430

431 432 433 434 435 436 437 438
    $dlls = @()
    $allGood = $true
    foreach ($dir in Get-ChildItem $unitDir) {
        $testDir = Join-Path $unitDir (Join-Path $dir $tf)
        if (Test-Path $testDir) { 
            $dllName = Get-ChildItem -name "*.UnitTests.dll" -path $testDir
            $dllPath = Join-Path $testDir $dllName

J
Jared Parsons 已提交
439 440 441 442 443
            $args = "exec"
            $args += " --depsfile " + [IO.Path]::ChangeExtension($dllPath, ".deps.json")
            $args += " --runtimeconfig " + [IO.Path]::ChangeExtension($dllPath, ".runtimeconfig.json")
            $args += " $xunitConsole"
            $args += " $dllPath"
444
            $args += " -xml " + (Join-Path $xunitResultDir ([IO.Path]::ChangeExtension($dllName, ".xml")))
J
Jared Parsons 已提交
445

J
Jared Parsons 已提交
446 447 448 449
            # https://github.com/dotnet/roslyn/issues/25049
            # Disable parallel runs everywhere until we get assembly specific settings working again
            $args += " -parallel none"

450 451
            try {
                Write-Host "Running $dllName"
J
Jared Parsons 已提交
452
                Exec-Console $dotnet $args
453 454 455 456 457 458
            }
            catch {
                Write-Host "Failed"
                $allGood = $false
            }
        }
459 460
    }

461 462 463
    if (-not $allGood) { 
        throw "Unit tests failed"
    }
464 465
}

J
Jared Parsons 已提交
466 467 468
# Core function for running our unit / integration tests tests
function Test-XUnit() { 

469 470 471 472 473
    if ($testCoreClr) {
        Test-XUnitCoreClr
        return
    }

474
    if ($testVsi -or $testVsiNetCore) {
J
Jared Parsons 已提交
475
        Deploy-VsixViaTool
J
Jared Parsons 已提交
476 477 478
    }

    $unitDir = Join-Path $configDir "UnitTests"
479
    $runTests = Join-Path $configDir "Exes\RunTests\RunTests.exe"
J
Jared Parsons 已提交
480
    $xunitDir = Join-Path (Get-PackageDir "xunit.runner.console") "tools\net452"
481
    $args = "$xunitDir"
482
    $args += " -logpath:$logsDir"
483
    $args += " -nocache"
J
Jared Parsons 已提交
484

485 486
    if ($testDesktop) {
        if ($test32) {
487 488 489
            $dlls = Get-ChildItem -re -in "*.UnitTests.dll" $unitDir
        }
        else {
490
            $dlls = Get-ChildItem -re -in "*.UnitTests.dll" -ex "*Roslyn.Interactive*" $unitDir 
491
        }
492 493
    }
    elseif ($testVsi) {
J
Jared Parsons 已提交
494
        $dlls = Get-ChildItem -re -in "*.IntegrationTests.dll" $unitDir
495 496
    }
    else {
J
Jared Parsons 已提交
497
        $dlls = Get-ChildItem -re -in "*.IntegrationTests.dll" $unitDir
498 499
        $args += " -trait:Feature=NetCore"
    }
500

J
Jared Parsons 已提交
501 502 503
    # Exclude out the multi-targetted netcore app projects
    $dlls = $dlls | ?{ -not ($_.FullName -match ".*netcoreapp.*") }

504 505 506 507
    # Exclude out the ref assemblies
    $dlls = $dlls | ?{ -not ($_.FullName -match ".*\\ref\\.*") }
    $dlls = $dlls | ?{ -not ($_.FullName -match ".*/ref/.*") }

508
    if ($cibuild -or $official) {
J
Jared Parsons 已提交
509
        # Use a 50 minute timeout on CI
510
        $args += " -xml -timeout:50"
511

512 513 514
        $procdumpPath = Ensure-ProcDump
        $args += " -procdumppath:$procDumpPath"
    }
515

516 517 518
    if ($test64) {
        $args += " -test64"
    }
519

520 521 522 523 524
    foreach ($dll in $dlls) { 
        $args += " $dll"
    }
    
    try {
J
Jared Parsons 已提交
525
        Exec-Console $runTests $args
526 527 528 529
    }
    finally {
        Get-Process "xunit*" -ErrorAction SilentlyContinue | Stop-Process    
    }
J
Jared Parsons 已提交
530 531 532 533 534
}

# Deploy our core VSIX libraries to Visual Studio via the Roslyn VSIX tool.  This is an alternative to 
# deploying at build time.
function Deploy-VsixViaTool() { 
535
    $vsixDir = Get-PackageDir "RoslynTools.Microsoft.VSIXExpInstaller"
J
Jared Parsons 已提交
536
    $vsixExe = Join-Path $vsixDir "tools\VsixExpInstaller.exe"
537 538 539
    $both = Get-VisualStudioDirAndId
    $vsDir = $both[0].Trim("\")
    $vsId = $both[1]
540
    $hive = "RoslynDev"
541
    Write-Host "Using VS Instance $vsId at `"$vsDir`""
542
    $baseArgs = "/rootSuffix:$hive /vsInstallDir:`"$vsDir`""
J
Jared Parsons 已提交
543 544 545 546 547 548 549 550 551
    $all = @(
        "Vsix\CompilerExtension\Roslyn.Compilers.Extension.vsix",
        "Vsix\VisualStudioSetup\Roslyn.VisualStudio.Setup.vsix",
        "Vsix\VisualStudioSetup.Next\Roslyn.VisualStudio.Setup.Next.vsix",
        "Vsix\VisualStudioInteractiveComponents\Roslyn.VisualStudio.InteractiveComponents.vsix",
        "Vsix\ExpressionEvaluatorPackage\ExpressionEvaluatorPackage.vsix",
        "Vsix\VisualStudioDiagnosticsWindow\Roslyn.VisualStudio.DiagnosticsWindow.vsix",
        "Vsix\VisualStudioIntegrationTestSetup\Microsoft.VisualStudio.IntegrationTest.Setup.vsix")

552
    Write-Host "Uninstalling old Roslyn VSIX"
553

554 555 556 557 558 559 560 561 562
    # Actual uninstall is failing at the moment using the uninstall options. Temporarily using 
    # wildfire to uninstall our VSIX extensions
    $extDir = Join-Path ${env:USERPROFILE} "AppData\Local\Microsoft\VisualStudio\15.0_$($vsid)$($hive)"
    if (Test-Path $extDir) {
        foreach ($dir in Get-ChildItem -Directory $extDir) {
            $name = Split-Path -leaf $dir
            Write-Host "`tUninstalling $name"
        }
        Remove-Item -re -fo $extDir
563 564
    }

J
Jared Parsons 已提交
565 566 567 568 569 570
    Write-Host "Installing all Roslyn VSIX"
    foreach ($e in $all) {
        $name = Split-Path -leaf $e
        $filePath = Join-Path $configDir $e
        $fullArg = "$baseArgs $filePath"
        Write-Host "`tInstalling $name"
J
Jared Parsons 已提交
571
        Exec-Console $vsixExe $fullArg
J
Jared Parsons 已提交
572 573 574
    }
}

J
Jared Parsons 已提交
575 576 577 578
# Sign all of our binaries that need to be signed
function Run-SignTool() { 
    Push-Location $repoDir
    try {
579
        $signTool = Join-Path (Get-PackageDir "RoslynTools.SignTool") "tools\SignTool.exe"
580
        $signToolArgs = "-msbuildPath `"$msbuild`""
581
        $signToolArgs += " -msbuildBinaryLog $logsDir\Signing.binlog"
J
Jared Parsons 已提交
582 583 584 585
        switch ($signType) {
            "real" { break; }
            "test" { $signToolArgs += " -testSign"; break; }
            default { $signToolArgs += " -test"; break; }
J
Jared Parsons 已提交
586
        }
J
Jared Parsons 已提交
587

J
Jared Parsons 已提交
588
        $signToolArgs += " `"$configDir`""
589
        Exec-Console $signTool $signToolArgs
J
Jared Parsons 已提交
590 591 592 593 594 595
    }
    finally { 
        Pop-Location
    }
}

J
Jared Parsons 已提交
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
# Ensure that procdump is available on the machine.  Returns the path to the directory that contains 
# the procdump binaries (both 32 and 64 bit)
function Ensure-ProcDump() {

    # Jenkins images default to having procdump installed in the root.  Use that if available to avoid
    # an unnecessary download.
    if (Test-Path "c:\SysInternals\procdump.exe") {
        return "c:\SysInternals";
    }    

    $toolsDir = Join-Path $binariesDir "Tools"
    $outDir = Join-Path $toolsDir "ProcDump"
    $filePath = Join-Path $outDir "procdump.exe"
    if (-not (Test-Path $filePath)) { 
        Remove-Item -Re $filePath -ErrorAction SilentlyContinue
        Create-Directory $outDir 
        $zipFilePath = Join-Path $toolsDir "procdump.zip"
J
Jared Parsons 已提交
613
        Invoke-WebRequest "https://download.sysinternals.com/files/Procdump.zip" -UseBasicParsing -outfile $zipFilePath | Out-Null
J
Jared Parsons 已提交
614 615 616 617 618 619 620 621 622 623 624 625 626 627
        Add-Type -AssemblyName System.IO.Compression.FileSystem
        [IO.Compression.ZipFile]::ExtractToDirectory($zipFilePath, $outDir)
    }

    return $outDir
}

# The Jenkins images used to execute our tests can live for a very long time.  Over the course
# of hundreds of runs this can cause the %TEMP% folder to fill up.  To avoid this we redirect
# %TEMP% into the binaries folder which is deleted at the end of every run as a part of cleaning
# up the workspace.
function Redirect-Temp() {
    $temp = Join-Path $binariesDir "Temp"
    Create-Directory $temp
628
    Copy-Item (Join-Path $repoDir "src\Workspaces\CoreTestUtilities\TestFiles\.editorconfig") $temp
629 630
    Copy-Item (Join-Path $repoDir "src\Workspaces\CoreTestUtilities\TestFiles\Directory.Build.props") $temp
    Copy-Item (Join-Path $repoDir "src\Workspaces\CoreTestUtilities\TestFiles\Directory.Build.targets") $temp
J
Jared Parsons 已提交
631 632 633
    ${env:TEMP} = $temp
    ${env:TMP} = $temp
}
J
Fixup  
Jared Parsons 已提交
634

635 636 637 638
function List-BuildProcesses() {
    Write-Host "Listing running build processes..."
    Get-Process -Name "msbuild" -ErrorAction SilentlyContinue | Out-Host
    Get-Process -Name "vbcscompiler" -ErrorAction SilentlyContinue | Out-Host
639
    Get-Process -Name "dotnet" -ErrorAction SilentlyContinue | where { $_.Modules | select { $_.ModuleName -eq "VBCSCompiler.dll" } } | Out-Host
640 641 642 643 644 645 646
}

function List-VSProcesses() {
    Write-Host "Listing running vs processes..."
    Get-Process -Name "devenv" -ErrorAction SilentlyContinue | Out-Host
}

J
Jared Parsons 已提交
647 648 649 650 651
# 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 Stop-BuildProcesses() {
652 653 654
    Write-Host "Killing running build processes..."
    Get-Process -Name "msbuild" -ErrorAction SilentlyContinue | Stop-Process
    Get-Process -Name "vbcscompiler" -ErrorAction SilentlyContinue | Stop-Process
655
    Get-Process -Name "dotnet" -ErrorAction SilentlyContinue | where { $_.Modules | select { $_.ModuleName -eq "VBCSCompiler.dll" } } | Stop-Process
656 657 658 659 660 661 662 663
}

# Kill any instances of devenv.exe to ensure VSIX install/uninstall works in future runs and to ensure
# that any locked files don't prevent future CI runs from failing.
# Also call Stop-BuildProcesses
function Stop-VSProcesses() {
    Write-Host "Killing running vs processes..."
    Get-Process -Name "devenv" -ErrorAction SilentlyContinue | Stop-Process
J
Jared Parsons 已提交
664 665
}

J
Jared Parsons 已提交
666
try {
J
Jared Parsons 已提交
667
    . (Join-Path $PSScriptRoot "build-utils.ps1")
J
Jared Parsons 已提交
668 669
    Push-Location $repoDir

670 671 672
    Write-Host "Repo Dir $repoDir"
    Write-Host "Binaries Dir $binariesDir"

J
Jared Parsons 已提交
673 674
    Process-Arguments

675
    $msbuild = Ensure-MSBuild
J
Jared Parsons 已提交
676
    $dotnet = Ensure-DotnetSdk
J
Jared Parsons 已提交
677
    $buildConfiguration = if ($release) { "Release" } else { "Debug" }
T
Tomas Matousek 已提交
678
    $configDir = Join-Path $binariesDir $buildConfiguration
679
    $logsDir = Join-Path $configDir "Logs"
J
Jared Parsons 已提交
680 681 682 683 684
    $bootstrapDir = ""

    # Ensure the main output directories exist as a number of tools will fail when they don't exist. 
    Create-Directory $binariesDir
    Create-Directory $configDir 
685
    Create-Directory $logsDir
J
Jared Parsons 已提交
686

J
Jared Parsons 已提交
687
    if ($cibuild) { 
688 689
        List-VSProcesses
        List-BuildProcesses
J
Jared Parsons 已提交
690
        Redirect-Temp
J
Fixup  
Jared Parsons 已提交
691 692
    }

A
Ashley Hauck 已提交
693 694
    if ($restore) {
        Write-Host "Running restore"
695
        Restore-Packages
A
Ashley Hauck 已提交
696 697
    }

698 699 700 701 702
    if ($isAnyTestSpecial) {
        Test-Special
        exit 0
    }

J
Jared Parsons 已提交
703 704 705 706
    if ($bootstrap) {
        $bootstrapDir = Make-BootstrapBuild
    }

J
Jared Parsons 已提交
707
    if ($build -or $pack) {
708
        Build-Artifacts
J
Jared Parsons 已提交
709 710 711 712 713 714 715
    }

    if ($testDesktop -or $testCoreClr -or $testVsi -or $testVsiNetCore) {
        Test-XUnit
    } 

    exit 0
J
Jared Parsons 已提交
716 717
}
catch {
J
Jared Parsons 已提交
718 719 720 721 722 723 724
    Write-Host $_
    Write-Host $_.Exception
    Write-Host $_.ScriptStackTrace
    exit 1
}
finally {
    Pop-Location
725 726
    if ($cibuild) {
        Stop-VSProcesses
J
Jared Parsons 已提交
727 728
        Stop-BuildProcesses
    }
J
Jared Parsons 已提交
729
}