Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 6d9dd3c

Browse files
Update bootstrappers
1 parent de2e096 commit 6d9dd3c

File tree

6 files changed

+266
-218
lines changed

6 files changed

+266
-218
lines changed

.appveyor.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: Visual Studio 2015
1+
image: Visual Studio 2015
22
init:
33
- git config --global core.autocrlf true
44
branches:
@@ -9,7 +9,7 @@ branches:
99
- /^(.*\/)?ci-.*$/
1010
- /^rel\/.*/
1111
build_script:
12-
- ps: .\build.ps1
12+
- ps: .\run.ps1 default-build
1313
install:
1414
- ps: Install-Product node 8
1515
clone_depth: 1

build.cmd

+1-1
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 = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"
2+
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' default-build %*; exit $LASTEXITCODE"

build.sh

+3-194
Original file line numberDiff line numberDiff line change
@@ -1,199 +1,8 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4-
5-
#
6-
# variables
7-
#
8-
9-
RESET="\033[0m"
10-
RED="\033[0;31m"
11-
MAGENTA="\033[0;95m"
124
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
13-
[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet"
14-
config_file="$DIR/version.xml"
15-
verbose=false
16-
update=false
17-
repo_path="$DIR"
18-
channel=''
19-
tools_source=''
20-
21-
#
22-
# Functions
23-
#
24-
__usage() {
25-
echo "Usage: $(basename "${BASH_SOURCE[0]}") [options] [[--] <MSBUILD_ARG>...]"
26-
echo ""
27-
echo "Arguments:"
28-
echo " <MSBUILD_ARG>... Arguments passed to MSBuild. Variable number of arguments allowed."
29-
echo ""
30-
echo "Options:"
31-
echo " --verbose Show verbose output."
32-
echo " -c|--channel <CHANNEL> The channel of KoreBuild to download. Overrides the value from the config file.."
33-
echo " --config-file <FILE> TThe path to the configuration file that stores values. Defaults to version.xml."
34-
echo " -d|--dotnet-home <DIR> The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
35-
echo " --path <PATH> The directory to build. Defaults to the directory containing the script."
36-
echo " -s|--tools-source <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
37-
echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
38-
echo ""
39-
echo "Description:"
40-
echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be."
41-
echo " When the lockfile is not present, KoreBuild will create one using latest available version from \$channel."
42-
43-
if [[ "${1:-}" != '--no-exit' ]]; then
44-
exit 2
45-
fi
46-
}
47-
48-
get_korebuild() {
49-
local version
50-
local lock_file="$repo_path/korebuild-lock.txt"
51-
if [ ! -f "$lock_file" ] || [ "$update" = true ]; then
52-
__get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file"
53-
fi
54-
version="$(grep 'version:*' -m 1 "$lock_file")"
55-
if [[ "$version" == '' ]]; then
56-
__error "Failed to parse version from $lock_file. Expected a line that begins with 'version:'"
57-
return 1
58-
fi
59-
version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
60-
local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version"
61-
62-
{
63-
if [ ! -d "$korebuild_path" ]; then
64-
mkdir -p "$korebuild_path"
65-
local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip"
66-
tmpfile="$(mktemp)"
67-
echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}"
68-
if __get_remote_file "$remote_path" "$tmpfile"; then
69-
unzip -q -d "$korebuild_path" "$tmpfile"
70-
fi
71-
rm "$tmpfile" || true
72-
fi
73-
74-
source "$korebuild_path/KoreBuild.sh"
75-
} || {
76-
if [ -d "$korebuild_path" ]; then
77-
echo "Cleaning up after failed installation"
78-
rm -rf "$korebuild_path" || true
79-
fi
80-
return 1
81-
}
82-
}
83-
84-
__error() {
85-
echo -e "${RED}$*${RESET}" 1>&2
86-
}
87-
88-
__machine_has() {
89-
hash "$1" > /dev/null 2>&1
90-
return $?
91-
}
92-
93-
__get_remote_file() {
94-
local remote_path=$1
95-
local local_path=$2
96-
97-
if [[ "$remote_path" != 'http'* ]]; then
98-
cp "$remote_path" "$local_path"
99-
return 0
100-
fi
101-
102-
local failed=false
103-
if __machine_has wget; then
104-
wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true
105-
else
106-
failed=true
107-
fi
108-
109-
if [ "$failed" = true ] && __machine_has curl; then
110-
failed=false
111-
curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true
112-
fi
113-
114-
if [ "$failed" = true ]; then
115-
__error "Download failed: $remote_path" 1>&2
116-
return 1
117-
fi
118-
}
119-
120-
__read_dom () { local IFS=\> ; read -r -d \< ENTITY CONTENT ;}
121-
122-
#
123-
# main
124-
#
125-
126-
while [[ $# -gt 0 ]]; do
127-
case $1 in
128-
-\?|-h|--help)
129-
__usage --no-exit
130-
exit 0
131-
;;
132-
-c|--channel|-Channel)
133-
shift
134-
channel="${1:-}"
135-
[ -z "$channel" ] && __usage
136-
;;
137-
--config-file|-ConfigFile)
138-
shift
139-
config_file="${1:-}"
140-
[ -z "$config_file" ] && __usage
141-
;;
142-
-d|--dotnet-home|-DotNetHome)
143-
shift
144-
DOTNET_HOME="${1:-}"
145-
[ -z "$DOTNET_HOME" ] && __usage
146-
;;
147-
--path|-Path)
148-
shift
149-
repo_path="${1:-}"
150-
[ -z "$repo_path" ] && __usage
151-
;;
152-
-s|--tools-source|-ToolsSource)
153-
shift
154-
tools_source="${1:-}"
155-
[ -z "$tools_source" ] && __usage
156-
;;
157-
-u|--update|-Update)
158-
update=true
159-
;;
160-
--verbose|-Verbose)
161-
verbose=true
162-
;;
163-
--)
164-
shift
165-
break
166-
;;
167-
*)
168-
break
169-
;;
170-
esac
171-
shift
172-
done
173-
174-
if ! __machine_has unzip; then
175-
__error 'Missing required command: unzip'
176-
exit 1
177-
fi
178-
179-
if ! __machine_has curl && ! __machine_has wget; then
180-
__error 'Missing required command. Either wget or curl is required.'
181-
exit 1
182-
fi
183-
184-
if [ -f "$config_file" ]; then
185-
comment=false
186-
while __read_dom; do
187-
if [ "$comment" = true ]; then [[ $CONTENT == *'-->'* ]] && comment=false ; continue; fi
188-
if [[ $ENTITY == '!--'* ]]; then comment=true; continue; fi
189-
if [ -z "$channel" ] && [[ $ENTITY == "KoreBuildChannel" ]]; then channel=$CONTENT; fi
190-
if [ -z "$tools_source" ] && [[ $ENTITY == "KoreBuildToolsSource" ]]; then tools_source=$CONTENT; fi
191-
done < "$config_file"
192-
fi
193-
194-
[ -z "$channel" ] && channel='dev'
195-
[ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools'
1965

197-
get_korebuild
198-
install_tools "$tools_source" "$DOTNET_HOME"
199-
invoke_repository_build "$repo_path" "$@"
6+
# Call "sync" between "chmod" and execution to prevent "text file busy" error in Docker (aufs)
7+
chmod +x "$DIR/run.sh"; sync
8+
"$DIR/run.sh" default-build "$@"

run.cmd

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

build.ps1 run.ps1

+35-21
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
<#
55
.SYNOPSIS
6-
Build this repository
6+
Executes KoreBuild commands.
77
88
.DESCRIPTION
9-
Downloads korebuild if required. Then builds the repository.
9+
Downloads korebuild if required. Then executes the KoreBuild command. To see available commands, execute with `-Command help`.
10+
11+
.PARAMETER Command
12+
The KoreBuild command to run.
1013
1114
.PARAMETER Path
1215
The folder to build. Defaults to the folder containing this script.
@@ -24,31 +27,32 @@ The base url where build tools can be downloaded. Overrides the value from the c
2427
Updates KoreBuild to the latest version even if a lock file is present.
2528
2629
.PARAMETER ConfigFile
27-
The path to the configuration file that stores values. Defaults to version.xml.
30+
The path to the configuration file that stores values. Defaults to korebuild.json.
2831
29-
.PARAMETER MSBuildArgs
30-
Arguments to be passed to MSBuild
32+
.PARAMETER Arguments
33+
Arguments to be passed to the command
3134
3235
.NOTES
3336
This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be.
3437
When the lockfile is not present, KoreBuild will create one using latest available version from $Channel.
3538
36-
The $ConfigFile is expected to be an XML file. It is optional, and the configuration values in it are optional as well.
39+
The $ConfigFile is expected to be an JSON file. It is optional, and the configuration values in it are optional as well. Any options set
40+
in the file are overridden by command line parameters.
3741
3842
.EXAMPLE
3943
Example config file:
40-
```xml
41-
<!-- version.xml -->
42-
<Project>
43-
<PropertyGroup>
44-
<KoreBuildChannel>dev</KoreBuildChannel>
45-
<KoreBuildToolsSource>https://aspnetcore.blob.core.windows.net/buildtools</KoreBuildToolsSource>
46-
</PropertyGroup>
47-
</Project>
44+
```json
45+
{
46+
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json",
47+
"channel": "dev",
48+
"toolsSource": "https://aspnetcore.blob.core.windows.net/buildtools"
49+
}
4850
```
4951
#>
5052
[CmdletBinding(PositionalBinding = $false)]
5153
param(
54+
[Parameter(Mandatory=$true, Position = 0)]
55+
[string]$Command,
5256
[string]$Path = $PSScriptRoot,
5357
[Alias('c')]
5458
[string]$Channel,
@@ -58,9 +62,9 @@ param(
5862
[string]$ToolsSource,
5963
[Alias('u')]
6064
[switch]$Update,
61-
[string]$ConfigFile = (Join-Path $PSScriptRoot 'version.xml'),
65+
[string]$ConfigFile,
6266
[Parameter(ValueFromRemainingArguments = $true)]
63-
[string[]]$MSBuildArgs
67+
[string[]]$Arguments
6468
)
6569

6670
Set-StrictMode -Version 2
@@ -147,10 +151,20 @@ function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
147151

148152
# Load configuration or set defaults
149153

154+
$Path = Resolve-Path $Path
155+
if (!$ConfigFile) { $ConfigFile = Join-Path $Path 'korebuild.json' }
156+
150157
if (Test-Path $ConfigFile) {
151-
[xml] $config = Get-Content $ConfigFile
152-
if (!($Channel)) { [string] $Channel = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildChannel' }
153-
if (!($ToolsSource)) { [string] $ToolsSource = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildToolsSource' }
158+
try {
159+
$config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json
160+
if ($config) {
161+
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
162+
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
163+
}
164+
} catch {
165+
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
166+
Write-Warning $Error[0]
167+
}
154168
}
155169

156170
if (!$DotNetHome) {
@@ -169,8 +183,8 @@ $korebuildPath = Get-KoreBuild
169183
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
170184

171185
try {
172-
Install-Tools $ToolsSource $DotNetHome
173-
Invoke-RepositoryBuild $Path @MSBuildArgs
186+
Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile
187+
Invoke-KoreBuildCommand $Command @Arguments
174188
}
175189
finally {
176190
Remove-Module 'KoreBuild' -ErrorAction Ignore

0 commit comments

Comments
 (0)