Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.cmd/sh changes #5958

Merged
merged 14 commits into from
Dec 21, 2018
Merged
32 changes: 3 additions & 29 deletions .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
jobName: Windows_Build
jobDisplayName: "Build and test: Windows"
agentOs: Windows
buildScript: ./eng/scripts/cibuild.cmd
beforeBuild:
- powershell: "& ./src/Servers/IIS/tools/UpdateIISExpressCertificate.ps1; & ./src/Servers/IIS/tools/update_schema.ps1"
displayName: Setup IISExpress test certificates and schema
Expand All @@ -21,37 +22,10 @@ jobs:
jobName: MacOs_Build
jobDisplayName: "Build and test: macOS"
agentOs: macOs
buildScript: ./eng/scripts/cibuild.sh
- template: jobs/default-build.yml
parameters:
jobName: Linux_Build
jobDisplayName: "Build and test: Linux"
agentOs: Linux
# - template: jobs/iisintegration-job.yml
# parameters:
# TestGroupName: IIS
# SkipIISTests: false
# SkipIISExpressTests: true
# SkipIISForwardsCompatibilityTests: true
# SkipIISBackwardsCompatibilityTests: true
# - template: jobs/iisintegration-job.yml
# parameters:
# TestGroupName: IISExpress
# SkipIISTests: true
# SkipIISExpressTests: false
# SkipIISForwardsCompatibilityTests: true
# SkipIISBackwardsCompatibilityTests: true
# - template: jobs/iisintegration-job.yml
# parameters:
# TestGroupName: IISForwardCompat
# SkipIISTests: true
# SkipIISExpressTests: true
# SkipIISForwardsCompatibilityTests: false
# SkipIISBackwardsCompatibilityTests: true
# - template: jobs/iisintegration-job.yml
# parameters:
# TestGroupName: IISBackCompat
# SkipIISTests: true
# SkipIISExpressTests: true
# SkipIISForwardsCompatibilityTests: true
# SkipIISBackwardsCompatibilityTests: false

buildScript: ./eng/scripts/cibuild.sh
20 changes: 14 additions & 6 deletions .azure/pipelines/jobs/default-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
# This build definition is enabled for code signing. (Only applies to Windows)
# buildDirectory: string
# Specifies what directory to run build.sh/cmd
# buildScript: string
# Specifies the build script to run. Defaults to build.sh or build.cmd.

#
# See https://docs.microsoft.com/en-us/vsts/pipelines/yaml-schema for details
Expand All @@ -58,6 +60,7 @@ parameters:
publish: true
path: 'artifacts/'
buildDirectory: ''
buildScript: ''

jobs:
- job: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
Expand Down Expand Up @@ -90,6 +93,7 @@ jobs:
AgentOsName: ${{ parameters.agentOs }}
ASPNETCORE_TEST_LOG_MAXPATH: "200" # Keep test log file name length low enough for artifact zipping
DOTNET_HOME: $(Agent.WorkFolder)/.dotnet
BuildScript: ${{ parameters.buildScript }}
BuildScriptArgs: ${{ parameters.buildArgs }}
BuildConfiguration: ${{ parameters.configuration }}
BuildDirectory: ${{ parameters.buildDirectory }}
Expand All @@ -114,12 +118,16 @@ jobs:
signType: $(_SignType)
zipSources: false
- ${{ parameters.beforeBuild }}
- ${{ if eq(parameters.agentOs, 'Windows') }}:
- script: .\$(BuildDirectory)\build.cmd -ci /p:SignType=$(_SignType) /p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
displayName: Run build.cmd
- ${{ if ne(parameters.agentOs, 'Windows') }}:
- script: ./$(BuildDirectory)/build.sh -ci -p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
displayName: Run build.sh
- ${{ if eq(parameters.buildScript, '') }}:
- ${{ if eq(parameters.agentOs, 'Windows') }}:
- script: .\$(BuildDirectory)\build.cmd -ci /p:SignType=$(_SignType) /p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
displayName: Run build.cmd
- ${{ if ne(parameters.agentOs, 'Windows') }}:
- script: ./$(BuildDirectory)/build.sh -ci -p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
displayName: Run build.sh
- ${{ if ne(parameters.buildScript, '') }}:
- script: $(BuildScript) /p:Configuration=$(BuildConfiguration) $(BuildScriptArgs)
displayName: run $(BuildScript)
- task: PublishTestResults@2
displayName: Publish test results
condition: always()
Expand Down
6 changes: 3 additions & 3 deletions .azure/pipelines/pr-validation-temp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
jobName: Windows_Build
jobDisplayName: "Build only : Windows"
agentOs: Windows
buildArgs: '/p:SkipTests=true'
buildArgs: -all -pack
- template: jobs/default-build.yml
parameters:
jobName: macOs_Build
jobDisplayName: "Build only : macOS"
agentOs: macOS
buildArgs: '/p:SkipTests=true'
buildArgs: --all --pack
- template: jobs/default-build.yml
parameters:
jobName: Linux_Build
jobDisplayName: "Build only : Linux"
agentOs: Linux
buildArgs: '/p:SkipTests=true'
buildArgs: --all --pack
2 changes: 1 addition & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@ECHO OFF
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' default-build %*; exit $LASTEXITCODE"
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"
264 changes: 264 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
#requires -version 4

<#
.SYNOPSIS
Builds this repository.

.DESCRIPTION
This build script installs required tools and runs an MSBuild command on this repository.
This script can be used to invoke various targets, such as targets to produce packages,
build projects, run tests, and generate code.

.PARAMETER RepoPath
The folder to build. Defaults to the folder containing this script. This will be removed soon.

.PARAMETER CI
Sets up CI specific settings and variables.

.PARAMETER Restore
Run restore on projects.

.PARAMETER Build
Compile projects.

.PARAMETER Pack
Produce packages.

.PARAMETER Test
Run tests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understood whether this only runs tests, or does it also build some subset of things required to run tests? And if it literally only runs tests (i.e. it assumes all binaries are already built and in the right location), when would that be needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build.cmd -test will build AND test. We could add a gesture for just running tests without building, but I don't think re-running tests without changes is very common.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halter73 does this all the time, re-running tests in a loop trying to repro flaky issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I was thinking it presumably builds & runs tests.

The case of re-running tests in a loop happens, but is rare, so I didn't think that would be a frequently used case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the build were incremental then it would work both ways...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builds should be incremental once we finish #4246.

re-running tests in a loop trying to repro flaky issues.

You can do it with the build.cmd script, it's just not the default. On *nix, build.sh --no-restore --no-build --test. On Windows, it's ./build.ps1 -restore:$false -build:$false -test. You can also use dotnet test --no-build on the project you're trying to use.


.PARAMETER Sign
Run code signing.

.PARAMETER Projects
A list of projects to build. (Must be an absolute path.) Globbing patterns are supported, such as "$(pwd)/**/*.csproj"

.PARAMETER All
Build all project types.

.PARAMETER Managed
Build managed projects (C#, F#, VB).

.PARAMETER Native
Build native projects (C++).

.PARAMETER NodeJS
Build NodeJS projects (TypeScript, JS).

.PARAMETER MSBuildArguments
Additional MSBuild arguments to be passed through.

.EXAMPLE
Building both native and managed projects.

build.ps1 -managed -native

.EXAMPLE
Building a subfolder of code.

build.ps1 "$(pwd)/src/SomeFolder/**/*.csproj"

.EXAMPLE
Running tests.

build.ps1 -test

.LINK
Online version: https://github.com/aspnet/AspNetCore/blob/master/docs/BuildFromSource.md
#>
[CmdletBinding(PositionalBinding = $false, DefaultParameterSetName='Groups')]
param(
# Bootstrapper options
[Obsolete('This parameter will be removed when we finish https://github.com/aspnet/AspNetCore/issues/4246')]
[string]$RepoRoot = $PSScriptRoot,

[switch]$CI,

# Build lifecycle options
[switch]$Restore = $True, # Run tests
[switch]$Build = $True, # Compile
[switch]$Pack, # Produce packages
[switch]$Test, # Run tests
[switch]$Sign, # Code sign

# Project selection
[Parameter(ParameterSetName = 'All')]
[switch]$All, # Build everything

# A list of projects which should be built.
[Parameter(ParameterSetName = 'Projects')]
[string]$Projects,

# Build a specified set of project groups
[Parameter(ParameterSetName = 'Groups')]
[switch]$Managed,
[Parameter(ParameterSetName = 'Groups')]
[switch]$Native,
[Parameter(ParameterSetName = 'Groups')]
[switch]$NodeJS,

# Other lifecycle targets
[switch]$Help, # Show help

# Capture the rest
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$MSBuildArguments
)

Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'

#
# Functions
#

function Get-KoreBuild {

if (!(Test-Path $LockFile)) {
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $LockFile
}

$version = Get-Content $LockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
if (!$version) {
Write-Error "Failed to parse version from $LockFile. Expected a line that begins with 'version:'"
}
$version = $version.TrimStart('version:').Trim()
$korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version)

if (!(Test-Path $korebuildPath)) {
Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version"
New-Item -ItemType Directory -Path $korebuildPath | Out-Null
$remotePath = "$ToolsSource/korebuild/artifacts/$version/korebuild.$version.zip"

try {
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
Get-RemoteFile $remotePath $tmpfile
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
# Use built-in commands where possible as they are cross-plat compatible
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
}
else {
# Fallback to old approach for old installations of PowerShell
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath)
}
}
catch {
Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore
throw
}
finally {
Remove-Item $tmpfile -ErrorAction Ignore
}
}

return $korebuildPath
}

function Join-Paths([string]$path, [string[]]$childPaths) {
$childPaths | ForEach-Object { $path = Join-Path $path $_ }
return $path
}

function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
if ($RemotePath -notlike 'http*') {
Copy-Item $RemotePath $LocalPath
return
}

$retries = 10
while ($retries -gt 0) {
$retries -= 1
try {
Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath
return
}
catch {
Write-Verbose "Request failed. $retries retries remaining"
}
}

Write-Error "Download failed: '$RemotePath'."
}

#
# Main
#

# Load configuration or set defaults

if ($Help) {
Get-Help $PSCommandPath
exit 1
}

$RepoRoot = Resolve-Path $RepoRoot
$Channel = 'master'
$ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools'
$ConfigFile = Join-Path $PSScriptRoot 'korebuild.json'
$LockFile = Join-Path $PSScriptRoot 'korebuild-lock.txt'

if (Test-Path $ConfigFile) {
try {
$config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json
if ($config) {
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
}
} catch {
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
Write-Warning $Error[0]
}
}

$DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
elseif ($CI) { Join-Path $PSScriptRoot '.dotnet' } `
elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
else { Join-Path $PSScriptRoot '.dotnet'}

$env:DOTNET_HOME = $DotNetHome

# Execute

$korebuildPath = Get-KoreBuild

# Project selection
if ($All) {
$MSBuildArguments += '/p:BuildAllProjects=true'
}
elseif ($Projects) {
$MSBuildArguments += "/p:Projects=$Projects"
}
else {
# When adding new sub-group build flags, add them to this check
if((-not $Native) -and (-not $Managed) -and (-not $NodeJS)) {
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."

# This goal of this is to pick a sensible default for `build.cmd` with zero arguments.
# 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.

$Managed = $true
}

$MSBuildArguments += "/p:BuildManaged=$Managed"
$MSBuildArguments += "/p:BuildNative=$Native"
$MSBuildArguments += "/p:BuildNodeJS=$NodeJS"
}

# Target selection
$MSBuildArguments += "/p:_RunRestore=$Restore"
$MSBuildArguments += "/p:_RunBuild=$Build"
$MSBuildArguments += "/p:_RunPack=$Pack"
$MSBuildArguments += "/p:_RunTests=$Test"
$MSBuildArguments += "/p:_RunSign=$Sign"

Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')

try {
Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $RepoRoot -ConfigFile $ConfigFile -CI:$CI
Invoke-KoreBuildCommand 'default-build' @MSBuildArguments
}
finally {
Remove-Module 'KoreBuild' -ErrorAction Ignore
}
Loading