Skip to content

Commit c3beb1f

Browse files
authored
build.cmd/sh changes (dotnet#5958)
Update the build scripts to support building subfolders or subgroups of projects * Add build scripts for ci * Remove obsolete scripts * Add flags like --test and --pack to control running just test or packaging * Add flags like --managed and --native to control building sub-types of projects * Remove KoreBuild bootstrapper flags * Update to extensions 3.0.0-preview.18619.1 (needed to get a fix for dotnet/extensions#815 to make this change work on MSBuild.exe)
1 parent d73d6e8 commit c3beb1f

47 files changed

Lines changed: 795 additions & 1395 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.azure/pipelines/ci.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
jobName: Windows_Build
1414
jobDisplayName: "Build and test: Windows"
1515
agentOs: Windows
16+
buildScript: ./eng/scripts/cibuild.cmd
1617
beforeBuild:
1718
- powershell: "& ./src/Servers/IIS/tools/UpdateIISExpressCertificate.ps1; & ./src/Servers/IIS/tools/update_schema.ps1"
1819
displayName: Setup IISExpress test certificates and schema
@@ -21,37 +22,10 @@ jobs:
2122
jobName: MacOs_Build
2223
jobDisplayName: "Build and test: macOS"
2324
agentOs: macOs
25+
buildScript: ./eng/scripts/cibuild.sh
2426
- template: jobs/default-build.yml
2527
parameters:
2628
jobName: Linux_Build
2729
jobDisplayName: "Build and test: Linux"
2830
agentOs: Linux
29-
# - template: jobs/iisintegration-job.yml
30-
# parameters:
31-
# TestGroupName: IIS
32-
# SkipIISTests: false
33-
# SkipIISExpressTests: true
34-
# SkipIISForwardsCompatibilityTests: true
35-
# SkipIISBackwardsCompatibilityTests: true
36-
# - template: jobs/iisintegration-job.yml
37-
# parameters:
38-
# TestGroupName: IISExpress
39-
# SkipIISTests: true
40-
# SkipIISExpressTests: false
41-
# SkipIISForwardsCompatibilityTests: true
42-
# SkipIISBackwardsCompatibilityTests: true
43-
# - template: jobs/iisintegration-job.yml
44-
# parameters:
45-
# TestGroupName: IISForwardCompat
46-
# SkipIISTests: true
47-
# SkipIISExpressTests: true
48-
# SkipIISForwardsCompatibilityTests: false
49-
# SkipIISBackwardsCompatibilityTests: true
50-
# - template: jobs/iisintegration-job.yml
51-
# parameters:
52-
# TestGroupName: IISBackCompat
53-
# SkipIISTests: true
54-
# SkipIISExpressTests: true
55-
# SkipIISForwardsCompatibilityTests: true
56-
# SkipIISBackwardsCompatibilityTests: false
57-
31+
buildScript: ./eng/scripts/cibuild.sh

.azure/pipelines/jobs/default-build.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
# This build definition is enabled for code signing. (Only applies to Windows)
3636
# buildDirectory: string
3737
# Specifies what directory to run build.sh/cmd
38+
# buildScript: string
39+
# Specifies the build script to run. Defaults to build.sh or build.cmd.
3840

3941
#
4042
# See https://docs.microsoft.com/en-us/vsts/pipelines/yaml-schema for details
@@ -58,6 +60,7 @@ parameters:
5860
publish: true
5961
path: 'artifacts/'
6062
buildDirectory: ''
63+
buildScript: ''
6164

6265
jobs:
6366
- job: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
@@ -90,6 +93,7 @@ jobs:
9093
AgentOsName: ${{ parameters.agentOs }}
9194
ASPNETCORE_TEST_LOG_MAXPATH: "200" # Keep test log file name length low enough for artifact zipping
9295
DOTNET_HOME: $(Agent.WorkFolder)/.dotnet
96+
BuildScript: ${{ parameters.buildScript }}
9397
BuildScriptArgs: ${{ parameters.buildArgs }}
9498
BuildConfiguration: ${{ parameters.configuration }}
9599
BuildDirectory: ${{ parameters.buildDirectory }}
@@ -114,12 +118,16 @@ jobs:
114118
signType: $(_SignType)
115119
zipSources: false
116120
- ${{ parameters.beforeBuild }}
117-
- ${{ if eq(parameters.agentOs, 'Windows') }}:
118-
- script: .\$(BuildDirectory)\build.cmd -ci /p:SignType=$(_SignType) /p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
119-
displayName: Run build.cmd
120-
- ${{ if ne(parameters.agentOs, 'Windows') }}:
121-
- script: ./$(BuildDirectory)/build.sh -ci -p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
122-
displayName: Run build.sh
121+
- ${{ if eq(parameters.buildScript, '') }}:
122+
- ${{ if eq(parameters.agentOs, 'Windows') }}:
123+
- script: .\$(BuildDirectory)\build.cmd -ci /p:SignType=$(_SignType) /p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
124+
displayName: Run build.cmd
125+
- ${{ if ne(parameters.agentOs, 'Windows') }}:
126+
- script: ./$(BuildDirectory)/build.sh -ci -p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
127+
displayName: Run build.sh
128+
- ${{ if ne(parameters.buildScript, '') }}:
129+
- script: $(BuildScript) /p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
130+
displayName: run $(BuildScript)
123131
- task: PublishTestResults@2
124132
displayName: Publish test results
125133
condition: always()

.azure/pipelines/pr-validation-temp.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ jobs:
1515
jobName: Windows_Build
1616
jobDisplayName: "Build only : Windows"
1717
agentOs: Windows
18-
buildArgs: '/p:SkipTests=true'
18+
buildArgs: -all -pack
1919
- template: jobs/default-build.yml
2020
parameters:
2121
jobName: macOs_Build
2222
jobDisplayName: "Build only : macOS"
2323
agentOs: macOS
24-
buildArgs: '/p:SkipTests=true'
24+
buildArgs: --all --pack
2525
- template: jobs/default-build.yml
2626
parameters:
2727
jobName: Linux_Build
2828
jobDisplayName: "Build only : Linux"
2929
agentOs: Linux
30-
buildArgs: '/p:SkipTests=true'
30+
buildArgs: --all --pack

build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@ECHO OFF
2-
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' default-build %*; exit $LASTEXITCODE"
2+
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"

build.ps1

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
#requires -version 4
2+
3+
<#
4+
.SYNOPSIS
5+
Builds this repository.
6+
7+
.DESCRIPTION
8+
This build script installs required tools and runs an MSBuild command on this repository.
9+
This script can be used to invoke various targets, such as targets to produce packages,
10+
build projects, run tests, and generate code.
11+
12+
.PARAMETER RepoPath
13+
The folder to build. Defaults to the folder containing this script. This will be removed soon.
14+
15+
.PARAMETER CI
16+
Sets up CI specific settings and variables.
17+
18+
.PARAMETER Restore
19+
Run restore on projects.
20+
21+
.PARAMETER Build
22+
Compile projects.
23+
24+
.PARAMETER Pack
25+
Produce packages.
26+
27+
.PARAMETER Test
28+
Run tests.
29+
30+
.PARAMETER Sign
31+
Run code signing.
32+
33+
.PARAMETER Projects
34+
A list of projects to build. (Must be an absolute path.) Globbing patterns are supported, such as "$(pwd)/**/*.csproj"
35+
36+
.PARAMETER All
37+
Build all project types.
38+
39+
.PARAMETER Managed
40+
Build managed projects (C#, F#, VB).
41+
42+
.PARAMETER Native
43+
Build native projects (C++).
44+
45+
.PARAMETER NodeJS
46+
Build NodeJS projects (TypeScript, JS).
47+
48+
.PARAMETER MSBuildArguments
49+
Additional MSBuild arguments to be passed through.
50+
51+
.EXAMPLE
52+
Building both native and managed projects.
53+
54+
build.ps1 -managed -native
55+
56+
.EXAMPLE
57+
Building a subfolder of code.
58+
59+
build.ps1 "$(pwd)/src/SomeFolder/**/*.csproj"
60+
61+
.EXAMPLE
62+
Running tests.
63+
64+
build.ps1 -test
65+
66+
.LINK
67+
Online version: https://github.com/aspnet/AspNetCore/blob/master/docs/BuildFromSource.md
68+
#>
69+
[CmdletBinding(PositionalBinding = $false, DefaultParameterSetName='Groups')]
70+
param(
71+
# Bootstrapper options
72+
[Obsolete('This parameter will be removed when we finish https://github.com/aspnet/AspNetCore/issues/4246')]
73+
[string]$RepoRoot = $PSScriptRoot,
74+
75+
[switch]$CI,
76+
77+
# Build lifecycle options
78+
[switch]$Restore = $True, # Run tests
79+
[switch]$Build = $True, # Compile
80+
[switch]$Pack, # Produce packages
81+
[switch]$Test, # Run tests
82+
[switch]$Sign, # Code sign
83+
84+
# Project selection
85+
[Parameter(ParameterSetName = 'All')]
86+
[switch]$All, # Build everything
87+
88+
# A list of projects which should be built.
89+
[Parameter(ParameterSetName = 'Projects')]
90+
[string]$Projects,
91+
92+
# Build a specified set of project groups
93+
[Parameter(ParameterSetName = 'Groups')]
94+
[switch]$Managed,
95+
[Parameter(ParameterSetName = 'Groups')]
96+
[switch]$Native,
97+
[Parameter(ParameterSetName = 'Groups')]
98+
[switch]$NodeJS,
99+
100+
# Other lifecycle targets
101+
[switch]$Help, # Show help
102+
103+
# Capture the rest
104+
[Parameter(ValueFromRemainingArguments = $true)]
105+
[string[]]$MSBuildArguments
106+
)
107+
108+
Set-StrictMode -Version 2
109+
$ErrorActionPreference = 'Stop'
110+
111+
#
112+
# Functions
113+
#
114+
115+
function Get-KoreBuild {
116+
117+
if (!(Test-Path $LockFile)) {
118+
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $LockFile
119+
}
120+
121+
$version = Get-Content $LockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
122+
if (!$version) {
123+
Write-Error "Failed to parse version from $LockFile. Expected a line that begins with 'version:'"
124+
}
125+
$version = $version.TrimStart('version:').Trim()
126+
$korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version)
127+
128+
if (!(Test-Path $korebuildPath)) {
129+
Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version"
130+
New-Item -ItemType Directory -Path $korebuildPath | Out-Null
131+
$remotePath = "$ToolsSource/korebuild/artifacts/$version/korebuild.$version.zip"
132+
133+
try {
134+
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
135+
Get-RemoteFile $remotePath $tmpfile
136+
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
137+
# Use built-in commands where possible as they are cross-plat compatible
138+
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
139+
}
140+
else {
141+
# Fallback to old approach for old installations of PowerShell
142+
Add-Type -AssemblyName System.IO.Compression.FileSystem
143+
[System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath)
144+
}
145+
}
146+
catch {
147+
Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore
148+
throw
149+
}
150+
finally {
151+
Remove-Item $tmpfile -ErrorAction Ignore
152+
}
153+
}
154+
155+
return $korebuildPath
156+
}
157+
158+
function Join-Paths([string]$path, [string[]]$childPaths) {
159+
$childPaths | ForEach-Object { $path = Join-Path $path $_ }
160+
return $path
161+
}
162+
163+
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
164+
if ($RemotePath -notlike 'http*') {
165+
Copy-Item $RemotePath $LocalPath
166+
return
167+
}
168+
169+
$retries = 10
170+
while ($retries -gt 0) {
171+
$retries -= 1
172+
try {
173+
Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath
174+
return
175+
}
176+
catch {
177+
Write-Verbose "Request failed. $retries retries remaining"
178+
}
179+
}
180+
181+
Write-Error "Download failed: '$RemotePath'."
182+
}
183+
184+
#
185+
# Main
186+
#
187+
188+
# Load configuration or set defaults
189+
190+
if ($Help) {
191+
Get-Help $PSCommandPath
192+
exit 1
193+
}
194+
195+
$RepoRoot = Resolve-Path $RepoRoot
196+
$Channel = 'master'
197+
$ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools'
198+
$ConfigFile = Join-Path $PSScriptRoot 'korebuild.json'
199+
$LockFile = Join-Path $PSScriptRoot 'korebuild-lock.txt'
200+
201+
if (Test-Path $ConfigFile) {
202+
try {
203+
$config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json
204+
if ($config) {
205+
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
206+
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
207+
}
208+
} catch {
209+
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
210+
Write-Warning $Error[0]
211+
}
212+
}
213+
214+
$DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
215+
elseif ($CI) { Join-Path $PSScriptRoot '.dotnet' } `
216+
elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
217+
elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
218+
else { Join-Path $PSScriptRoot '.dotnet'}
219+
220+
$env:DOTNET_HOME = $DotNetHome
221+
222+
# Execute
223+
224+
$korebuildPath = Get-KoreBuild
225+
226+
# Project selection
227+
if ($All) {
228+
$MSBuildArguments += '/p:BuildAllProjects=true'
229+
}
230+
elseif ($Projects) {
231+
$MSBuildArguments += "/p:Projects=$Projects"
232+
}
233+
else {
234+
# When adding new sub-group build flags, add them to this check
235+
if((-not $Native) -and (-not $Managed) -and (-not $NodeJS)) {
236+
Write-Warning "No default group of projects was specified, so building the 'managed' and 'native' subset of projects. Run ``build.cmd -help`` for more details."
237+
238+
# This goal of this is to pick a sensible default for `build.cmd` with zero arguments.
239+
# We believe the most common thing our contributors will work on is C#, so if no other build group was picked, build the C# projects.
240+
241+
$Managed = $true
242+
}
243+
244+
$MSBuildArguments += "/p:BuildManaged=$Managed"
245+
$MSBuildArguments += "/p:BuildNative=$Native"
246+
$MSBuildArguments += "/p:BuildNodeJS=$NodeJS"
247+
}
248+
249+
# Target selection
250+
$MSBuildArguments += "/p:_RunRestore=$Restore"
251+
$MSBuildArguments += "/p:_RunBuild=$Build"
252+
$MSBuildArguments += "/p:_RunPack=$Pack"
253+
$MSBuildArguments += "/p:_RunTests=$Test"
254+
$MSBuildArguments += "/p:_RunSign=$Sign"
255+
256+
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
257+
258+
try {
259+
Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $RepoRoot -ConfigFile $ConfigFile -CI:$CI
260+
Invoke-KoreBuildCommand 'default-build' @MSBuildArguments
261+
}
262+
finally {
263+
Remove-Module 'KoreBuild' -ErrorAction Ignore
264+
}

0 commit comments

Comments
 (0)