From 007cfc1f9bdd290b0bc2f614c27cdddae90e438a Mon Sep 17 00:00:00 2001 From: Chris Rummel Date: Tue, 25 Oct 2016 18:51:41 -0500 Subject: [PATCH] Switch to using new bootstrap script to initialize buildtools. (#4349) * Switch to using new bootstrap script to initialize buildtools. * Set up the version-specific shared runtime symlink in run-build so buildtools doesn't have to care about it. * Address code review feedback. * Addressed code review feedback. * Change to using bootstrap script for Linux build as well. * Change to using latest for CLI. --- .cliversion | 1 + .toolversions | 2 + BuildToolsCliVersion.txt | 1 - BuildToolsVersion.txt | 1 - init-tools.ps1 | 82 ---------------------------------------- init-tools.sh | 56 --------------------------- run-build.ps1 | 30 ++++++++++++--- run-build.sh | 54 +++++++++++++++++++++++++- 8 files changed, 80 insertions(+), 147 deletions(-) create mode 100644 .cliversion create mode 100644 .toolversions delete mode 100644 BuildToolsCliVersion.txt delete mode 100644 BuildToolsVersion.txt delete mode 100644 init-tools.ps1 delete mode 100755 init-tools.sh diff --git a/.cliversion b/.cliversion new file mode 100644 index 000000000..a0f9a4b4b --- /dev/null +++ b/.cliversion @@ -0,0 +1 @@ +latest diff --git a/.toolversions b/.toolversions new file mode 100644 index 000000000..fd4b736d1 --- /dev/null +++ b/.toolversions @@ -0,0 +1,2 @@ +microsoft.dotnet.buildtools=1.0.26-prerelease-00802-01 +microsoft.dotnet.buildtools.run=1.0.0-prerelease-00807-04 \ No newline at end of file diff --git a/BuildToolsCliVersion.txt b/BuildToolsCliVersion.txt deleted file mode 100644 index dd7bc318f..000000000 --- a/BuildToolsCliVersion.txt +++ /dev/null @@ -1 +0,0 @@ -1.0.0-preview2-002733 \ No newline at end of file diff --git a/BuildToolsVersion.txt b/BuildToolsVersion.txt deleted file mode 100644 index fe0296b40..000000000 --- a/BuildToolsVersion.txt +++ /dev/null @@ -1 +0,0 @@ -1.0.26-prerelease-00621-06 \ No newline at end of file diff --git a/init-tools.ps1 b/init-tools.ps1 deleted file mode 100644 index 5176862d9..000000000 --- a/init-tools.ps1 +++ /dev/null @@ -1,82 +0,0 @@ -# -# Copyright (c) .NET Foundation and contributors. All rights reserved. -# Licensed under the MIT license. See LICENSE file in the project root for full license information. -# - -param( - [string]$Architecture="x64") - -$RepoRoot = "$PSScriptRoot" - -# Install a stage 0 -Write-Host "Installing .NET Core CLI Stage 0 from branchinfo channel" - -& "$RepoRoot\scripts\obtain\dotnet-install.ps1" -Channel $env:CHANNEL -Architecture $Architecture -Verbose -if($LASTEXITCODE -ne 0) { throw "Failed to install stage0" } - -# Put the stage0 on the path -$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH" - -# Disable first run since we want to control all package sources -$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - -# Setup BuildTools vars -$BUILD_TOOLS_VERSION = Get-Content "$RepoRoot\BuildToolsVersion.txt" -$BUILD_TOOLS_PATH=$RepoRoot + "\build_tools" -$BUILD_TOOLS_SOURCE='https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json' -$BUILD_TOOLS_SEMAPHORE=$BUILD_TOOLS_PATH + "\init-tools.completed" -$INIT_TOOLS_LOG=$RepoRoot + "\init-tools.log" -$PROJECT_JSON_FILE=$BUILD_TOOLS_PATH + "\project.json" -$PROJECT_JSON_CONTENTS="{ `"dependencies`": { `"Microsoft.DotNet.BuildTools`": `"" + $BUILD_TOOLS_VERSION + "`" }, `"frameworks`": { `"netcoreapp1.0`": { } } }" -$PACKAGES_DIR=$RepoRoot + "\.nuget\packages" -$BUILD_TOOLS_PACKAGE_PATH=$PACKAGES_DIR + "\Microsoft.DotNet.BuildTools\" + $BUILD_TOOLS_VERSION + "\lib" -$DOTNET_EXE_CMD=$env:DOTNET_INSTALL_DIR + "\dotnet.exe" - -# If build tools are already installed, escape -if (Test-Path "$BUILD_TOOLS_SEMAPHORE") -{ - Write-Host "Tools are already initialized" - exit 0 -} - -# Check for build tools -if (!(Test-Path "$BUILD_TOOLS_PATH")) -{ - mkdir "$BUILD_TOOLS_PATH" | Out-Null -} - -# Write the build tools project.json file -"$PROJECT_JSON_CONTENTS" | Set-Content "$PROJECT_JSON_FILE" - -# Restore build tools -$args="restore $PROJECT_JSON_FILE --packages $PACKAGES_DIR --source $BUILD_TOOLS_SOURCE" -Start-Process -FilePath $DOTNET_EXE_CMD -ArgumentList $args -Wait -RedirectStandardOutput $INIT_TOOLS_LOG -NoNewWindow -if (!(Test-Path "$BUILD_TOOLS_PACKAGE_PATH\init-tools.cmd")) -{ - Write-Host "ERROR: Could not restore build tools correctly. See '$INIT_TOOLS_LOG' for more details" - exit 1 -} - -# Bring down the CLI for build tools -$DOTNET_PATH=$BUILD_TOOLS_PATH + "\dotnetcli" - -Write-Host "Installing Build Tools CLI version..." -if (!(Test-Path "$DOTNET_PATH")) -{ - mkdir "$DOTNET_PATH" -} - -$DOTNET_VERSION = Get-Content "$RepoRoot\BuildToolsCliVersion.txt" -$DOTNET_LOCAL_PATH=$DOTNET_PATH -& "$RepoRoot\scripts\obtain\dotnet-install.ps1" -Channel "rel-1.0.0" -Version "$DOTNET_VERSION" -InstallDir "$DOTNET_LOCAL_PATH" - -if (!(Test-Path "$DOTNET_LOCAL_PATH")) -{ - Write-Host "Could not install Build Tools CLI version correctly" - exit 1 -} - -# Initialize build tools -cmd /c "$BUILD_TOOLS_PACKAGE_PATH\init-tools.cmd $RepoRoot $DOTNET_LOCAL_PATH\dotnet.exe $BUILD_TOOLS_PATH" >> "$INIT_TOOLS_LOG" -Write-Host "Done initializing tools." -Write-Host "Init-Tools completed for BuildTools Version: $BUILD_TOOLS_VERSION" > $BUILD_TOOLS_SEMAPHORE diff --git a/init-tools.sh b/init-tools.sh deleted file mode 100755 index 2b66c7f83..000000000 --- a/init-tools.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) .NET Foundation and contributors. All rights reserved. -# Licensed under the MIT license. See LICENSE file in the project root for full license information. -# - -set -e - -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - -$DIR/scripts/obtain/dotnet-install.sh --channel $CHANNEL --verbose - -__init_tools_log=$DIR/init-tools.log -__BUILD_TOOLS_CLI_VERSION=$(cat "$DIR/BuildToolsCliVersion.txt") -__BUILD_TOOLS_DIR=$DIR/build_tools -__BUILD_TOOLS_CLI_DIR=$__BUILD_TOOLS_DIR/dotnetcli/ -__BUILD_TOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json -__BUILD_TOOLS_PACKAGE_VERSION=$(cat $DIR/BuildToolsVersion.txt) -__BUILD_TOOLS_PATH=$NUGET_PACKAGES/Microsoft.DotNet.BuildTools/$__BUILD_TOOLS_PACKAGE_VERSION/lib -__BUILD_TOOLS_SEMAPHORE=$__BUILD_TOOLS_DIR/init-tools.completed -__DOTNET_CMD=$__BUILD_TOOLS_CLI_DIR/dotnet -__PROJECT_JSON_PATH=$__BUILD_TOOLS_DIR/$__BUILD_TOOLS_PACKAGE_VERSION -__PROJECT_JSON_FILE=$__PROJECT_JSON_PATH/project.json -__PROJECT_JSON_CONTENTS="{ \"dependencies\": { \"Microsoft.DotNet.BuildTools\": \"$__BUILD_TOOLS_PACKAGE_VERSION\" }, \"frameworks\": { \"netcoreapp1.0\": { } } }" - -if [ ! -e "$__PROJECT_JSON_FILE" ]; then - mkdir -p "$__PROJECT_JSON_PATH" - echo "$__PROJECT_JSON_CONTENTS" > "$__PROJECT_JSON_FILE" - - if [ ! -d "$__BUILD_TOOLS_CLI_DIR" ]; then - echo "Installing Build Tools CLI Version: $__BUILD_TOOLS_CLI_VERSION" - "$DIR/scripts/obtain/dotnet-install.sh" --channel rel-1.0.0 --version "$__BUILD_TOOLS_CLI_VERSION" --install-dir "$__BUILD_TOOLS_CLI_DIR" - fi - - if [ ! -d "$__BUILD_TOOLS_PATH" ]; then - echo "Restoring build tools version $__BUILD_TOOLS_PACKAGE_VERSION..." - "$__DOTNET_CMD" restore "$__PROJECT_JSON_FILE" --packages "$NUGET_PACKAGES" --source "$__BUILD_TOOLS_SOURCE" - - if [ ! -e "$__BUILD_TOOLS_PATH/init-tools.sh" ]; then echo "ERROR: Could not restore build tools correctly. See '$__init_tools_log' for more details."; fi - find . - fi - - echo "Initializing build tools..." - "$__BUILD_TOOLS_PATH/init-tools.sh" "$DIR" "$__DOTNET_CMD" "$__BUILD_TOOLS_DIR" >> "$__init_tools_log" 2>&1 - echo "Init-Tools completed for BuildTools Version: $__BUILD_TOOLS_PACKAGE_VERSION" > "$__BUILD_TOOLS_SEMAPHORE" - echo "Done initializing tools" -else - echo "Tools are already initialized" -fi - diff --git a/run-build.ps1 b/run-build.ps1 index 47bc812fb..43a56d4d2 100644 --- a/run-build.ps1 +++ b/run-build.ps1 @@ -59,15 +59,35 @@ if (!(Test-Path $env:DOTNET_INSTALL_DIR)) mkdir $env:DOTNET_INSTALL_DIR | Out-Null } -& "$RepoRoot\init-tools.ps1" -Architecture $Architecture -if($LASTEXITCODE -ne 0) { throw "Failed to install Init Tools" } +# Disable first run since we want to control all package sources +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 + +# set the base tools directory +$toolsLocalPath = Join-Path $PSScriptRoot "build_tools" +$bootStrapperPath = Join-Path $toolsLocalPath "bootstrap.ps1" +# if the boot-strapper script doesn't exist then download it +if ((Test-Path $bootStrapperPath) -eq 0) +{ + if ((Test-Path $toolsLocalPath) -eq 0) + { + mkdir $toolsLocalPath | Out-Null + } + + # download boot-strapper script + Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/buildtools/master/bootstrap/bootstrap.ps1" -OutFile $bootStrapperPath +} + +# now execute it +& $bootStrapperPath -RepositoryRoot (Get-Location) -ToolsLocalPath $toolsLocalPath -CliLocalPath $env:DOTNET_INSTALL_DIR | Out-File (Join-Path (Get-Location) "bootstrap.log") +if ($LastExitCode -ne 0) +{ + Write-Output "Boot-strapping failed with exit code $LastExitCode, see bootstrap.log for more information." + exit $LastExitCode +} # Put the stage0 on the path $env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH" -# Disable first run since we want to control all package sources -$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - if ($NoBuild) { Write-Host "Not building due to --nobuild" diff --git a/run-build.sh b/run-build.sh index 9c45a9b2f..f02ab20e4 100755 --- a/run-build.sh +++ b/run-build.sh @@ -6,6 +6,41 @@ set -e +machine_has() { + hash "$1" > /dev/null 2>&1 + return $? +} + +check_min_reqs() { + if ! machine_has "curl"; then + echo "run-build: Error: curl is required to download dotnet. Install curl to proceed." >&2 + return 1 + fi + return 0 +} + +# args: +# remote_path - $1 +# [out_path] - $2 - stdout if not provided +download() { + eval $invocation + + local remote_path=$1 + local out_path=${2:-} + + local failed=false + if [ -z "$out_path" ]; then + curl --retry 10 -sSL --create-dirs $remote_path || failed=true + else + curl --retry 10 -sSL --create-dirs -o $out_path $remote_path || failed=true + fi + + if [ "$failed" = true ]; then + echo "run-build: Error: Download failed" >&2 + return 1 + fi +} + SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" @@ -14,7 +49,6 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" REPOROOT="$DIR" -OLDPATH="$PATH" ARCHITECTURE="x64" source "$REPOROOT/scripts/common/_prettyprint.sh" @@ -98,7 +132,23 @@ done < "$REPOROOT/branchinfo.txt" [ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$ARCHITECTURE [ -d "$DOTNET_INSTALL_DIR" ] || mkdir -p $DOTNET_INSTALL_DIR -$REPOROOT/init-tools.sh +DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +toolsLocalPath="$REPOROOT/build_tools" +bootStrapperPath="$toolsLocalPath/bootstrap.sh" +if [ ! -f $bootStrapperPath ]; then + if [ ! -d $toolsLocalPath ]; then + mkdir $toolsLocalPath + fi + download "https://raw.githubusercontent.com/dotnet/buildtools/master/bootstrap/bootstrap.sh" "$bootStrapperPath" + chmod u+x $bootStrapperPath +fi + +$bootStrapperPath --repositoryRoot "$REPOROOT" --toolsLocalPath "$toolsLocalPath" --cliInstallPath $DOTNET_INSTALL_DIR > bootstrap.log + +if [ $? != 0 ]; then + echo "run-build: Error: Boot-strapping failed with exit code $?, see bootstrap.log for more information." >&2 + exit $? +fi # Put stage 0 on the PATH (for this shell only) PATH="$DOTNET_INSTALL_DIR:$PATH"