msbuild

Форк
0
/
build.ps1 
205 строк · 7.5 Кб
1
#
2
# Copyright (c) .NET Foundation and contributors. All rights reserved.
3
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
#
5

6
[CmdletBinding(PositionalBinding=$false)]
7
Param(
8
  [string][Alias('c')]$configuration = "Debug",
9
  [string] $projects,
10
  [string][Alias('v')]$verbosity = "minimal",
11
  [string] $msbuildEngine = $null,
12
  [bool] $warnAsError = $true,
13
  [bool] $nodeReuse = $true,
14
  [switch][Alias('r')]$restore,
15
  [switch] $deployDeps,
16
  [switch][Alias('b')]$build,
17
  [switch] $rebuild,
18
  [switch] $deploy,
19
  [switch] $test,
20
  [switch] $integrationTest,
21
  [switch] $performanceTest,
22
  [switch] $sign,
23
  [switch] $pack,
24
  [switch] $publish,
25
  [switch][Alias('bl')]$binaryLog,
26
  [switch] $ci,
27
  [switch] $prepareMachine,
28
  [switch] $help,
29

30
  # official build settings
31
  [string]$officialBuildId = "",
32
  [string]$officialSkipApplyOptimizationData = "",
33

34
  [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
35
)
36

37
function Print-Usage() {
38
  Write-Host "Common settings:"
39
  Write-Host "  -configuration <value>  Build configuration: 'Debug' or 'Release' (short: -c)"
40
  Write-Host "  -verbosity <value>      Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
41
  Write-Host "  -binaryLog              Output binary log (short: -bl)"
42
  Write-Host ""
43

44
  Write-Host "Actions:"
45
  Write-Host "  -restore                Restore dependencies (short: -r)"
46
  Write-Host "  -build                  Build solution (short: -b)"
47
  Write-Host "  -rebuild                Rebuild solution"
48
  Write-Host "  -deploy                 Deploy built VSIXes"
49
  Write-Host "  -deployDeps             Deploy dependencies (e.g. VSIXes for integration tests)"
50
  Write-Host "  -test                   Run all unit tests in the solution"
51
  Write-Host "  -pack                   Package build outputs into NuGet packages and Willow components"
52
  Write-Host "  -help                   Print help and exit"
53
  Write-Host "  -integrationTest        Run all integration tests in the solution"
54
  Write-Host "  -performanceTest        Run all performance tests in the solution"
55
  Write-Host "  -sign                   Sign build outputs"
56
  Write-Host "  -publish                Publish artifacts (e.g. symbols)"
57
  Write-Host ""
58

59
  Write-Host "Advanced settings:"
60
  Write-Host "  -projects <value>       Semi-colon delimited list of sln/proj's to build. Globbing is supported (*.sln)"
61
  Write-Host "  -ci                     Set when running on CI server"
62
  Write-Host "  -prepareMachine         Prepare machine for CI run"
63
  Write-Host "  -msbuildEngine <value>  Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
64
  Write-Host ""
65

66
  Write-Host "Official build settings:"
67
  Write-Host "  -officialBuildId                            An official build id, e.g. 20190102.3"
68
  Write-Host "  -officialSkipApplyOptimizationData <bool>   Pass 'true' to not apply optimization data"
69
  Write-Host ""
70
  Write-Host "Command line arguments not listed above are passed thru to msbuild."
71
  Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
72
}
73

74
function Process-Arguments() {
75
  function OfficialBuildOnly([string]$argName) {
76
    if ((Get-Variable $argName -Scope Script).Value) {
77
      if (!$officialBuildId) {
78
        Write-Host "$argName can only be specified for official builds"
79
        exit 1
80
      }
81
    } else {
82
      if ($officialBuildId) {
83
        Write-Host "$argName must be specified in official builds"
84
        exit 1
85
      }
86
    }
87
  }
88

89
  if ($help -or (($properties -ne $null) -and ($properties.Contains("/help") -or $properties.Contains("/?")))) {
90
    Print-Usage
91
    exit 0
92
  }
93

94
  OfficialBuildOnly "officialSkipApplyOptimizationData"
95

96
  if ($officialBuildId) {
97
    $script:applyOptimizationData = ![System.Boolean]::Parse($officialSkipApplyOptimizationData)
98
  } else {
99
    $script:applyOptimizationData = $false
100
  }
101

102
  if ($ci) {
103
    $script:binaryLog = $true
104
    $script:nodeReuse = $false
105
  }
106
}
107

108
function Build-Repo() {
109
  $bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "Build.binlog") } else { "" }
110
  $toolsetBuildProj = InitializeToolset
111

112
  if ($projects) {
113
    # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons.
114
    # Explicitly set the type as string[] because otherwise PowerShell would make this char[] if $properties is empty.
115
    [string[]] $msbuildArgs = $properties
116
    $msbuildArgs += "/p:Projects=$projects"
117
    $properties = $msbuildArgs
118
  }
119

120
  # Do not set this property to true explicitly, since that would override values set in projects.
121
  $suppressPartialNgenOptimization = if (!$applyOptimizationData) { "/p:EnableNgenOptimization=false" } else { "" }
122

123
  MSBuild $toolsetBuildProj `
124
    $bl `
125
    /p:Configuration=$configuration `
126
    /p:RepoRoot=$RepoRoot `
127
    /p:Restore=$restore `
128
    /p:DeployDeps=$deployDeps `
129
    /p:Build=$build `
130
    /p:Rebuild=$rebuild `
131
    /p:Deploy=$deploy `
132
    /p:Test=$test `
133
    /p:Pack=$pack `
134
    /p:IntegrationTest=$integrationTest `
135
    /p:PerformanceTest=$performanceTest `
136
    /p:Sign=$sign `
137
    /p:Publish=$publish `
138
    /p:ContinuousIntegrationBuild=$ci `
139
    /p:OfficialBuildId=$officialBuildId `
140
    $suppressPartialNgenOptimization `
141
    @properties
142
}
143

144
# Set VSO variables used by MicroBuildBuildVSBootstrapper pipeline task
145
function Set-OptProfVariables() {
146
  $insertionDir = Join-Path $VSSetupDir "Insertion"
147
  $manifestList = [string]::Join(',', (Get-ChildItem "$insertionDir\*.vsman"))
148
  Write-Host "##vso[task.setvariable variable=VisualStudio.SetupManifestList;]$manifestList"
149
}
150

151
function Check-EditedFiles() {
152
  # Log VSTS errors for changed lines
153
  git --no-pager diff HEAD --unified=0 --no-color --exit-code | ForEach-Object { "##vso[task.logissue type=error] $_" }
154
  if ($LASTEXITCODE -ne 0) {
155
    throw "##vso[task.logissue type=error] After building, there are changed files.  Please build locally and include these changes in your pull request."
156
  }
157
}
158

159
function Check-RequiredVersionBumps() {
160
  # Log VSTS errors for missing required version bumps
161
  $targetBranch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
162
  if ($targetBranch) {
163
    # Some PRs specify the bare target branch (most commonly "main"), some prefix it with "refs/heads/".
164
    # The following statement normalizes both to a revision spec that git understands.
165
    $targetBranch = "refs/remotes/origin/" + ($targetBranch -replace "^refs/heads/", "")
166
    $versionLineChanged = $false
167
    git --no-pager diff --unified --no-color --exit-code -w $targetBranch HEAD src\Framework\EngineServices.cs `
168
      | Select-String -Pattern "int Version =" | ForEach-Object -process { $versionLineChanged = $true }
169
    if (($LASTEXITCODE -ne 0) -and (-not $versionLineChanged)) {
170
      throw "##vso[task.logissue type=error] Detected changes in Framework\EngineServices.cs without a version bump.  " +
171
            "If you are making API changes, please bump the version.  " +
172
            "If the changes in the file are cosmetic, please change an inline comment on the `"int Version =`" line in EngineServices.cs to silence the error."
173
    }
174
  }
175
}
176

177
try {
178
  Process-Arguments
179

180
  # Import Arcade functions
181
  . (Join-Path $PSScriptRoot "common\tools.ps1")
182
  . (Join-Path $PSScriptRoot "configure-toolset.ps1")
183

184
  $VSSetupDir = Join-Path $ArtifactsDir "VSSetup\$configuration"
185

186
  if ($ci -and $build) {
187
    Check-RequiredVersionBumps
188
  }
189

190
  Build-Repo
191

192
  if ($ci -and $build) {
193
    Set-OptProfVariables
194

195
    Check-EditedFiles
196
  }
197
}
198
catch {
199
  Write-Host $_
200
  Write-Host $_.Exception
201
  Write-Host $_.ScriptStackTrace
202
  ExitWithExitCode 1
203
}
204

205
ExitWithExitCode 0
206

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.