Backport #388 to rel/2.0.2 - add support for korebuild.json

This commit is contained in:
Nate McMaster 2017-09-19 11:51:56 -07:00
Родитель 60338bc298
Коммит 95739991d4
8 изменённых файлов: 87 добавлений и 33 удалений

Просмотреть файл

@ -5,11 +5,7 @@ param(
[Alias('p')]
[string]$Path = $PSScriptRoot,
[Alias('d')]
[string]$DotNetHome = $(`
if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
else { Join-Path $PSScriptRoot '.dotnet'} ),
[string]$DotNetHome = $null,
[Alias('s')]
[string]$ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools',
[Parameter(ValueFromRemainingArguments = $true)]
@ -18,6 +14,13 @@ param(
$ErrorActionPreference = 'Stop'
if (!$DotNetHome) {
$DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
else { Join-Path $PSScriptRoot '.dotnet'}
}
try {
Import-Module -Force -Scope Local $PSScriptRoot/sdk/KoreBuild/KoreBuild.psd1
Install-Tools $ToolsSource $DotNetHome

Просмотреть файл

Просмотреть файл

@ -33,18 +33,17 @@ Arguments to be passed to MSBuild
This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be.
When the lockfile is not present, KoreBuild will create one using latest available version from $Channel.
The $ConfigFile is expected to be an XML file. It is optional, and the configuration values in it are optional as well.
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
in the file are overridden by command line parameters.
.EXAMPLE
Example config file:
```xml
<!-- version.props -->
<Project>
<PropertyGroup>
<KoreBuildChannel>dev</KoreBuildChannel>
<KoreBuildToolsSource>https://aspnetcore.blob.core.windows.net/buildtools</KoreBuildToolsSource>
</PropertyGroup>
</Project>
```json
{
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json",
"channel": "dev",
"toolsSource": "https://aspnetcore.blob.core.windows.net/buildtools"
}
```
#>
[CmdletBinding(PositionalBinding = $false)]
@ -58,7 +57,7 @@ param(
[string]$ToolsSource,
[Alias('u')]
[switch]$Update,
[string]$ConfigFile = (Join-Path $PSScriptRoot 'version.props'),
[string]$ConfigFile = $null,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$MSBuildArgs
)
@ -147,10 +146,20 @@ function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
# Load configuration or set defaults
$Path = Resolve-Path $Path
if (!$ConfigFile) { $ConfigFile = Join-Path $Path 'korebuild.json' }
if (Test-Path $ConfigFile) {
[xml] $config = Get-Content $ConfigFile
if (!($Channel)) { [string] $Channel = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildChannel' }
if (!($ToolsSource)) { [string] $ToolsSource = Select-Xml -Xml $config -XPath '/Project/PropertyGroup/KoreBuildToolsSource' }
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]
}
}
if (!$DotNetHome) {

47
scripts/build.sh → scripts/bootstrapper/build.sh Executable file → Normal file
Просмотреть файл

@ -8,10 +8,11 @@ set -euo pipefail
RESET="\033[0m"
RED="\033[0;31m"
YELLOW="\033[0;33m"
MAGENTA="\033[0;95m"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[ -z "${DOTNET_HOME:-}"] && DOTNET_HOME="$HOME/.dotnet"
config_file="$DIR/version.props"
config_file="$DIR/korebuild.json"
verbose=false
update=false
repo_path="$DIR"
@ -30,7 +31,7 @@ __usage() {
echo "Options:"
echo " --verbose Show verbose output."
echo " -c|--channel <CHANNEL> The channel of KoreBuild to download. Overrides the value from the config file.."
echo " --config-file <FILE> TThe path to the configuration file that stores values. Defaults to version.props."
echo " --config-file <FILE> The path to the configuration file that stores values. Defaults to korebuild.json."
echo " -d|--dotnet-home <DIR> The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
echo " --path <PATH> The directory to build. Defaults to the directory containing the script."
echo " -s|--tools-source <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
@ -81,7 +82,11 @@ get_korebuild() {
}
__error() {
echo -e "${RED}$@${RESET}" 1>&2
echo -e "${RED}error: $*${RESET}" 1>&2
}
__warn() {
echo -e "${YELLOW}warning: $*${RESET}"
}
__machine_has() {
@ -113,8 +118,6 @@ __get_remote_file() {
fi
}
__read_dom () { local IFS=\> ; read -d \< ENTITY CONTENT ;}
#
# main
#
@ -134,6 +137,10 @@ while [[ $# > 0 ]]; do
shift
config_file="${1:-}"
[ -z "$config_file" ] && __usage
if [ ! -f "$config_file" ]; then
__error "Invalid value for --config-file. $config_file does not exist."
exit 1
fi
;;
-d|--dotnet-home|-DotNetHome)
shift
@ -177,14 +184,28 @@ if ! __machine_has curl && ! __machine_has wget; then
exit 1
fi
if [ -f $config_file ]; then
comment=false
while __read_dom; do
if [ "$comment" = true ]; then [[ $CONTENT == *'-->'* ]] && comment=false ; continue; fi
if [[ $ENTITY == '!--'* ]]; then comment=true; continue; fi
if [ -z "$channel" ] && [[ $ENTITY == "KoreBuildChannel" ]]; then channel=$CONTENT; fi
if [ -z "$tools_source" ] && [[ $ENTITY == "KoreBuildToolsSource" ]]; then tools_source=$CONTENT; fi
done < $config_file
[ -z "${config_file:-}" ] && config_file="$repo_path/korebuild.json"
if [ -f "$config_file" ]; then
if __machine_has jq ; then
if jq '.' "$config_file" >/dev/null ; then
config_channel="$(jq -r 'select(.channel!=null) | .channel' "$config_file")"
config_tools_source="$(jq -r 'select(.toolsSource!=null) | .toolsSource' "$config_file")"
else
__warn "$config_file is invalid JSON. Its settings will be ignored."
fi
elif __machine_has python ; then
if python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then
config_channel="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")"
config_tools_source="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")"
else
__warn "$config_file is invalid JSON. Its settings will be ignored."
fi
else
__warn 'Missing required command: jq or pyton. Could not parse the JSON file. Its settings will be ignored.'
fi
[ ! -z "${config_channel:-}" ] && channel="$config_channel"
[ ! -z "${config_tools_source:-}" ] && tools_source="$config_tools_source"
fi
[ -z "$channel" ] && channel='dev'

Просмотреть файл

@ -28,7 +28,7 @@ namespace KoreBuild.FunctionalTests
}
}
public string ScriptsDir { get; } = Path.Combine(_solutionDir, "scripts");
public string ScriptsDir { get; } = Path.Combine(_solutionDir, "scripts", "bootstrapper");
public string ToolsSource { get; } = Path.Combine(_solutionDir, "artifacts");
public string TestAssets { get; } = Path.Combine(_solutionDir, "testassets");

Просмотреть файл

@ -0,0 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/rel/2.0.2/tools/korebuild.schema.json",
"channel": "rel/2.0.2"
}

Просмотреть файл

@ -1,6 +1,5 @@
<Project>
<PropertyGroup>
<KoreBuildChannel>rel/2.0.2</KoreBuildChannel>
<VersionPrefix>2.0.2</VersionPrefix>
<VersionSuffix>alpha</VersionSuffix>
</PropertyGroup>

Просмотреть файл

@ -0,0 +1,18 @@
{
"title": "Config file for KoreBuild",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"toolsSource": {
"description": "The remote source used to download KoreBuild. Can be a file path.",
"type": "string",
"default": "https://aspnetcore.blob.core.windows.net/buildtools"
},
"channel": {
"description": "The channel of KoreBuild used to select a version when korebuild-lock.txt is not present.",
"type": "string",
"default": "dev",
"enum": ["dev", "rel/2.0.0"]
}
}
}