From 4d9bacd3f18da6ced1ede5252dced6825267cc2b Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 11 Oct 2017 11:00:53 -0700 Subject: [PATCH] Update build scripts and targets to use 2.0.x build tools --- .appveyor.yml | 1 + .gitignore | 1 - Directory.Build.props | 6 +-- Directory.Build.targets | 16 ++----- build.ps1 | 41 ++++++++++------- build.sh | 45 ++++++++++++++----- build/dependencies.props | 19 ++++++++ build/repo.props | 23 ---------- build/repo.targets | 7 --- build/sources.props | 17 +++++++ korebuild-lock.txt | 2 + korebuild.json | 4 ++ test/Templates.Test/Templates.Test.csproj | 23 +++++----- .../DependencyUpdater.csproj | 6 +-- .../PullRequestSubmitter.csproj | 6 +-- version.props | 9 ++++ version.xml | 8 ---- 17 files changed, 130 insertions(+), 104 deletions(-) create mode 100644 build/dependencies.props delete mode 100644 build/repo.props create mode 100644 build/sources.props create mode 100644 korebuild-lock.txt create mode 100644 korebuild.json create mode 100644 version.props delete mode 100644 version.xml diff --git a/.appveyor.yml b/.appveyor.yml index d7f1764fd4..dd76f2f348 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -7,6 +7,7 @@ branches: - master - release - dev + - /^rel\/.*/ - /^(.*\/)?ci-.*$/ build_script: - ps: .\build.ps1 diff --git a/.gitignore b/.gitignore index fde2a295c5..507c2de6bf 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,3 @@ node_modules .testPublish/ .vscode global.json -korebuild-lock.txt diff --git a/Directory.Build.props b/Directory.Build.props index e165c67fc6..6e7ba7e87f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,4 @@ - + - - - $(VersionSuffix)-$(BuildNumber) - diff --git a/Directory.Build.targets b/Directory.Build.targets index 8296c12835..246f7ac20c 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,14 +1,4 @@ - - - - <_BootstrapperFile Condition=" $([MSBuild]::IsOSUnixLike()) ">build.sh - <_BootstrapperFile Condition="! $([MSBuild]::IsOSUnixLike()) ">build.cmd - <_BootstrapperError> - Package references have not been pinned. Run './$(_BootstrapperFile) /t:Pin'. - Also, you can run './$(_BootstrapperFile) /t:Restore' which will pin *and* restore packages. '$(_BootstrapperFile)' can be found in '$(MSBuildThisFileDirectory)'. - - - - - + + + diff --git a/build.ps1 b/build.ps1 index d5eb4d5cf2..b7081bc1c2 100644 --- a/build.ps1 +++ b/build.ps1 @@ -24,7 +24,7 @@ The base url where build tools can be downloaded. Overrides the value from the c Updates KoreBuild to the latest version even if a lock file is present. .PARAMETER ConfigFile -The path to the configuration file that stores values. Defaults to version.xml. +The path to the configuration file that stores values. Defaults to version.props. .PARAMETER MSBuildArgs Arguments to be passed to MSBuild @@ -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 - - - - dev - https://aspnetcore.blob.core.windows.net/buildtools - - +```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.xml'), + [string]$ConfigFile = $null, [Parameter(ValueFromRemainingArguments = $true)] [string[]]$MSBuildArgs ) @@ -104,11 +103,11 @@ function Get-KoreBuild { } } catch { - Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore + remove-item -Recurse -Force $korebuildPath -ErrorAction Ignore throw } finally { - Remove-Item $tmpfile -ErrorAction Ignore + remove-item $tmpfile -ErrorAction Ignore } } @@ -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) { diff --git a/build.sh b/build.sh index 11cdbe5504..14d84a8773 100644 --- a/build.sh +++ b/build.sh @@ -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.xml" +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 The channel of KoreBuild to download. Overrides the value from the config file.." - echo " --config-file TThe path to the configuration file that stores values. Defaults to version.xml." + echo " --config-file The path to the configuration file that stores values. Defaults to korebuild.json." echo " -d|--dotnet-home The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet." echo " --path The directory to build. Defaults to the directory containing the script." echo " -s|--tools-source The base url where build tools can be downloaded. Overrides the value from the config file." @@ -82,7 +83,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() { @@ -117,8 +122,6 @@ __get_remote_file() { fi } -__read_dom () { local IFS=\> ; read -r -d \< ENTITY CONTENT ;} - # # main # @@ -138,6 +141,10 @@ while [[ $# -gt 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 @@ -181,14 +188,28 @@ if ! __machine_has curl && ! __machine_has wget; then exit 1 fi +[ -z "${config_file:-}" ] && config_file="$repo_path/korebuild.json" 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" + 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' diff --git a/build/dependencies.props b/build/dependencies.props new file mode 100644 index 0000000000..b0cfa47de7 --- /dev/null +++ b/build/dependencies.props @@ -0,0 +1,19 @@ + + + 2.0.2-beta-15522 + 15.3.409 + 15.3.409 + 15.3.0 + 0.26.0 + 0.18.0 + 3.4.0 + 15.15063.0 + 3.4.0 + 4.4.0 + 0.7.0 + 2.3.0 + 2.3.0 + + + + diff --git a/build/repo.props b/build/repo.props deleted file mode 100644 index 100a68ae64..0000000000 --- a/build/repo.props +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - https://dotnet.myget.org/f/aspnetcore-ci-dev - - - - - $(RepositoryRoot).deps\lineups - - - - - - diff --git a/build/repo.targets b/build/repo.targets index 552663d2a2..22222379bb 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -5,13 +5,6 @@ TaskName="PullRequestSubmitter.PullRequestTask" AssemblyFile="$(MSBuildThisFileDirectory)..\tools\PullRequestSubmitter\bin\Release\netcoreapp2.0\PullRequestSubmitter.dll" /> - - - - - - - - true - - - - - - - - - - + + + + + + + + + + diff --git a/tools/DependencyUpdater/DependencyUpdater.csproj b/tools/DependencyUpdater/DependencyUpdater.csproj index 0beb5f36be..ee85a128c6 100644 --- a/tools/DependencyUpdater/DependencyUpdater.csproj +++ b/tools/DependencyUpdater/DependencyUpdater.csproj @@ -6,7 +6,7 @@ - - + + - \ No newline at end of file + diff --git a/tools/PullRequestSubmitter/PullRequestSubmitter.csproj b/tools/PullRequestSubmitter/PullRequestSubmitter.csproj index 0cf93739cd..9c277b9304 100644 --- a/tools/PullRequestSubmitter/PullRequestSubmitter.csproj +++ b/tools/PullRequestSubmitter/PullRequestSubmitter.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/version.props b/version.props new file mode 100644 index 0000000000..7e4c6138cc --- /dev/null +++ b/version.props @@ -0,0 +1,9 @@ + + + 2.0.3 + rtm + $(VersionPrefix) + $(VersionPrefix)-$(VersionSuffix)-final + $(VersionSuffix)-$(BuildNumber) + + diff --git a/version.xml b/version.xml deleted file mode 100644 index b2c5cfd0fa..0000000000 --- a/version.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - dev - 2.1.0 - preview1 - - \ No newline at end of file