-
Notifications
You must be signed in to change notification settings - Fork 35
/
build.ps1
129 lines (112 loc) · 3.99 KB
/
build.ps1
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env powershell
#Requires -Version 5
<#
.SYNOPSIS
Builds Habitat components for Windows
.DESCRIPTION
This script builds habitat components and ensures that all necesary prerequisites are installed.
#>
param (
# The path to the component to be built. If not specified the current directory is used.
[string]$Path=".",
# When specified, all necessary prerequisites will be installed.
[switch]$Configure,
# When specified, a cargo clean will be invoked.
[switch]$Clean,
# Cargo command to invoke
[ValidateSet("Build","Test","Check","Clippy","Fmt")]
[string]$command="Build",
# When specified a build will not be run.
[switch]$SkipBuild,
# Use a optimized release build
[switch]$Release,
# Features to pass to cargo
[string]$Features,
# Options to pass to the cargo test command
[string]$TestOptions,
# The Rust toolchain to use and enjoy
[string]$Toolchain
)
$ErrorActionPreference="stop"
. $PSScriptRoot\support\ci\shared.ps1
if (!$Toolchain) {
$Toolchain = Get-Toolchain
}
if($Command -eq "Fmt") {
$toolchain = Get-RustfmtToolchain
Write-Host "Forcing the use of $toolchain toolchain for rustfmt"
}
if(!$env:ChocolateyInstall) {
$env:ChocolateyInstall = "$env:ProgramData\Chocolatey"
}
function Invoke-Configure {
# Make sure that chocolatey is installed and up to date
# (required for dependencies)
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Host "Installing Chocolatey"
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | Out-Null
}
if (!((choco list habitat --local-only) -match '^1 packages installed\.$')) {
choco install habitat -y
}
if(!(Get-Command git -ErrorAction SilentlyContinue)) {
choco install git --confirm
$env:path = New-PathString -StartingPath $env:path -Path "c:\Program Files\git\cmd"
}
}
function Get-Component($path) {
$leaf = Split-Path $path -leaf
$parent = Split-Path (Split-Path $path -Parent) -leaf
if($parent -eq "components") { $leaf } else { Write-Error "The specified path is not a component" }
}
function Invoke-Build([string]$Path, [switch]$Clean, [string]$Command, [switch]$Release, [string]$ToolChain, [string]$Features, [string]$TestOptions) {
$Path = Resolve-Path $Path
$Command = $command.ToLower()
if($Features) {
$FeatureString = "--features $Features"
} else {
$FeatureString = ""
}
Push-Location "$Path"
if($Clean) {
cargo clean
}
switch($Command) {
"fmt" {
Install-Rustup $toolchain
Install-RustToolchain $toolchain
rustup component add --toolchain $Toolchain rustfmt
Setup-Environment
Invoke-Expression "cargo +$ToolChain $Command --all"
break
}
"clippy" {
& $PSScriptRoot\test\run_clippy.ps1 -ToolChain $toolchain `
-UnexaminedLintsPath $PSScriptRoot\test\unexamined_lints.txt `
-AllowedLintsPath $PSScriptRoot\test\allowed_lints.txt `
-LintsToFixPath $PSScriptRoot\test\lints_to_fix.txt `
-DeniedLintsPath $PSScriptRoot\test\denied_lints.txt `
break
}
"build" {
Install-Rustup $toolchain
Install-RustToolchain $toolchain
Setup-Environment
Invoke-Expression "cargo +$ToolChain $Command $(if ($Release) { '--release' }) $FeatureString"
}
"check" {
Install-Rustup $toolchain
Install-RustToolchain $toolchain
Setup-Environment
Invoke-Expression "cargo +$ToolChain $Command $(if ($Release) { '--release' }) $FeatureString"
}
}
Pop-Location
}
if($Configure) {
Invoke-Configure
}
if (!$SkipBuild) {
Invoke-Build $Path -Clean:$Clean -Release:$Release -Command $Command -ToolChain $toolchain -Features $Features -TestOptions $TestOptions
}
exit $LASTEXITCODE