summaryrefslogtreecommitdiff
path: root/eng/common/sdk-task.ps1
blob: 9ba7530122f6961d38a6f2adb02c14eef94214af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
[CmdletBinding(PositionalBinding=$false)]
Param(
  [string] $projects = "",
  [string][Alias('v')]$verbosity = "minimal",
  [string] $msbuildEngine = $null,
  [bool] $warnAsError = $true,
  [switch][Alias('bl')]$binaryLog,
  [switch][Alias('r')]$restore,
  [switch] $ci,
  [switch] $prepareMachine,
  [switch] $help,
  [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
)

. $PSScriptRoot\tools.ps1

function Print-Usage() {
    Write-Host "Common settings:"
    Write-Host "  -v[erbosity] <value>    Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]"
    Write-Host "  -[bl|binaryLog]         Output binary log (short: -bl)"
    Write-Host "  -help                   Print help and exit"
    Write-Host ""

    Write-Host "Advanced settings:"
    Write-Host "  -restore                Restore dependencies (short: -r)"
    Write-Host "  -projects <value>       Semi-colon delimited list of sln/proj's from the Arcade sdk to build. Globbing is supported (*.sln)"
    Write-Host "  -ci                     Set when running on CI server"
    Write-Host "  -prepareMachine         Prepare machine for CI run"
    Write-Host "  -msbuildEngine <value>  Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
    Write-Host ""
    Write-Host "Command line arguments not listed above are passed thru to msbuild."
    Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
}

function Build {
  $toolsetBuildProj = InitializeToolset

  $toolsetBuildProj = Join-Path (Split-Path $toolsetBuildProj -Parent) "SdkTasks\SdkTask.proj"
  $bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "SdkTask.binlog") } else { "" }
  MSBuild $toolsetBuildProj `
    $bl `
    /p:Projects=$projects `
    /p:Restore=$restore `
    /p:RepoRoot=$RepoRoot `
    /p:ContinuousIntegrationBuild=$ci `
    @properties
}

try {
  if ($help -or (($null -ne $properties) -and ($properties.Contains("/help") -or $properties.Contains("/?")))) {
    Print-Usage
    exit 0
  }

  if ($projects -eq "") {
    Write-Error "Missing required parameter '-projects <value>'"
    Print-Usage
    ExitWithExitCode 1
  }

  if ($ci) {
    $binaryLog = $true
  }

  Build
}
catch {
  Write-Host $_
  Write-Host $_.Exception
  Write-Host $_.ScriptStackTrace
  ExitWithExitCode 1
}

ExitWithExitCode 0