diff --git a/BuildToolsCliVersion.txt b/BuildToolsCliVersion.txt new file mode 100644 index 000000000..dd7bc318f --- /dev/null +++ b/BuildToolsCliVersion.txt @@ -0,0 +1 @@ +1.0.0-preview2-002733 \ No newline at end of file diff --git a/BuildToolsVersion.txt b/BuildToolsVersion.txt index a49ec9c45..fe0296b40 100644 --- a/BuildToolsVersion.txt +++ b/BuildToolsVersion.txt @@ -1 +1 @@ -1.0.26-prerelease-00621-06 +1.0.26-prerelease-00621-06 \ No newline at end of file diff --git a/build.proj b/build.proj index a4890106a..88547f5a1 100644 --- a/build.proj +++ b/build.proj @@ -34,8 +34,8 @@ $(RepoRoot)/.dotnet_stage0/$(Architecture) $(Stage0Directory)/dotnet$(ExeExtension) - $(RepoRoot)/build_projects/dotnet-cli-build + $(RepoRoot)/.nuget @@ -85,4 +85,6 @@ + + diff --git a/build/Microsoft.DotNet.Cli.Run.targets b/build/Microsoft.DotNet.Cli.Run.targets new file mode 100644 index 000000000..d0f48571a --- /dev/null +++ b/build/Microsoft.DotNet.Cli.Run.targets @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/clean.cmd b/clean.cmd new file mode 100644 index 000000000..d6c44845f --- /dev/null +++ b/clean.cmd @@ -0,0 +1,12 @@ +@echo off + +REM Copyright (c) .NET Foundation and contributors. All rights reserved. +REM Licensed under the MIT license. See LICENSE file in the project root for full license information. + +if "%~1"=="" ( + @call run.cmd clean -? + @exit /b 1 +) else ( + @call run.cmd clean %* + @exit /b %ERRORLEVEL% +) diff --git a/clean.sh b/clean.sh new file mode 100755 index 000000000..4f56e5597 --- /dev/null +++ b/clean.sh @@ -0,0 +1,22 @@ +#!/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 )" +REPOROOT="$DIR" + +if [ "$#" -lt 1 ]; then + "$REPOROOT/run.sh" clean -? +else + "$REPOROOT/run.sh" clean "$@" +fi diff --git a/config.json b/config.json new file mode 100644 index 000000000..c98d5789f --- /dev/null +++ b/config.json @@ -0,0 +1,83 @@ +{ + "settings": { + "Project": { + "description": "Project where the commands are going to be applied.", + "valueType": "passThrough", + "values": [], + "defaultValue": "" + }, + "CleanArtifacts": { + "description": "MsBuild target that deletes the artifacts output directory.", + "valueType": "target", + "values": [], + "defaultValue": "" + }, + "CleanPackages": { + "description": "MsBuild target that deletes the repo-local nuget package directory.", + "valueType": "target", + "values": [], + "defaultValue": "" + }, + "CleanPackagesCache": { + "description": "MsBuild target that deletes the user-local nuget package cache.", + "valueType": "target", + "values": [], + "defaultValue": "" + }, + "CleanRepo": { + "description": "Cleans the entire repo of all non-git-added artifacts", + "valueType": "target", + "values": [], + "defaultValue": "" + }, + }, + "commands": { + "clean":{ + "alias":{ + "o":{ + "description": "Deletes the artifacts directory.", + "settings":{ + "CleanArtifacts": "default" + } + }, + "p":{ + "description": "Deletes the repo-local nuget package directory.", + "settings":{ + "CleanPackages": "default" + } + }, + "u": { + "description": "Deletes the user-local nuget package directory", + "settings": { + "CleanPackagesCache": "default" + } + }, + "a": { + "description": "Deletes all repo content that is not git-added", + "settings": { + "CleanRepo" : "default" + } + } + }, + "defaultValues":{ + "toolName": "msbuild", + "settings": { + "Project": "build.proj" + } + } + } + }, + "tools": { + "msbuild": { + "run": { + "windows": "build_tools\\msbuild.cmd", + "unix": "build_tools/msbuild.sh" + }, + "valueTypes": { + "property": "/p:{name}={value}", + "target": "/t:{name}", + "internal": "/{name}" + } + } + } +} diff --git a/init-tools.ps1 b/init-tools.ps1 index 909bab6e7..bb7f1e228 100644 --- a/init-tools.ps1 +++ b/init-tools.ps1 @@ -57,6 +57,25 @@ if (!(Test-Path "$BUILD_TOOLS_PACKAGE_PATH\init-tools.cmd")) 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 $env:DOTNET_INSTALL_DIR\dotnet.exe $BUILD_TOOLS_PATH" >> "$INIT_TOOLS_LOG" Write-Host "Done initializing tools." diff --git a/init-tools.sh b/init-tools.sh index 661dd7b7f..13e113ff6 100755 --- a/init-tools.sh +++ b/init-tools.sh @@ -17,12 +17,14 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" $DIR/scripts/obtain/dotnet-install.sh --channel $CHANNEL --verbose __init_tools_log=$DIR/init-tools.log -__DOTNET_CMD=$DOTNET_INSTALL_DIR/dotnet +__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=$DOTNET_INSTALL_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\": { } } }" @@ -36,7 +38,11 @@ if [ ! -e "$__PROJECT_JSON_FILE" ]; then "$__DOTNET_CMD" restore "$__PROJECT_JSON_FILE" --packages "$NUGET_PACKAGES" --source "$__BUILD_TOOLS_SOURCE" >> "$__init_tools_log" 2>&1 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 + fi + 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 echo "Initializing build tools..." @@ -46,3 +52,4 @@ if [ ! -e "$__PROJECT_JSON_FILE" ]; then else echo "Tools are already initialized" fi + diff --git a/run-build.ps1 b/run-build.ps1 index 22b61f32a..55fb02d9c 100644 --- a/run-build.ps1 +++ b/run-build.ps1 @@ -9,6 +9,7 @@ param( # This is here just to eat away this parameter because CI still passes this in. [string]$Targets="Default", [switch]$NoPackage, + [switch]$NoBuild, [switch]$Help, [Parameter(Position=0, ValueFromRemainingArguments=$true)] $ExtraParameters) @@ -21,6 +22,7 @@ if($Help) Write-Host " -Configuration Build the specified Configuration (Debug or Release, default: Debug)" Write-Host " -Architecture Build the specified architecture (x64 or x86 (supported only on Windows), default: x64)" Write-Host " -NoPackage Skip packaging targets" + Write-Host " -NoBuild Skip building the product" Write-Host " -Help Display this help message" exit 0 } @@ -66,5 +68,13 @@ $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 -dotnet build3 build.proj /p:Architecture=$Architecture $ExtraParameters -if($LASTEXITCODE -ne 0) { throw "Failed to build" } +if ($NoBuild) +{ + Write-Host "Not building due to --nobuild" + Write-Host "Command that would be run: 'dotnet build3 build.proj /p:Architecture=$Architecture $ExtraParameters'" +} +else +{ + dotnet build3 build.proj /p:Architecture=$Architecture $ExtraParameters + if($LASTEXITCODE -ne 0) { throw "Failed to build" } +} diff --git a/run-build.sh b/run-build.sh index 623e339af..df4282efe 100755 --- a/run-build.sh +++ b/run-build.sh @@ -19,6 +19,8 @@ OLDPATH="$PATH" ARCHITECTURE="x64" source "$REPOROOT/scripts/common/_prettyprint.sh" +BUILD=1 + # Set nuget package cache under the repo export NUGET_PACKAGES="$REPOROOT/.nuget/packages" @@ -42,6 +44,9 @@ while [[ $# > 0 ]]; do export DOTNET_INSTALL_SKIP_PREREQS=1 args=( "${args[@]/$1}" ) ;; + --nobuild) + BUILD=0 + ;; --architecture) ARCHITECTURE=$2 args=( "${args[@]/$1}" ) @@ -61,6 +66,7 @@ while [[ $# > 0 ]]; do echo " --configuration Build the specified Configuration (Debug or Release, default: Debug)" echo " --skip-prereqs Skip checks for pre-reqs in dotnet_install" echo " --nopackage Skip packaging targets" + echo " --nobuild Skip building, showing the command that would be used to build" echo " --docker Build in Docker using the Dockerfile located in scripts/docker/IMAGENAME" echo " --help Display this help message" exit 0 @@ -110,4 +116,9 @@ export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 echo "${args[@]}" -dotnet build3 build.proj /p:Architecture=$ARCHITECTURE "${args[@]}" \ No newline at end of file +if [ $BUILD -eq 1 ]; then + dotnet build3 build.proj /p:Architecture=$ARCHITECTURE "${args[@]}" +else + echo "Not building due to --nobuild" + echo "Command that would be run is: 'dotnet build3 build.proj /p:Architecture=$ARCHITECTURE ${args[@]}'" +fi diff --git a/run.cmd b/run.cmd new file mode 100644 index 000000000..5c0284a7d --- /dev/null +++ b/run.cmd @@ -0,0 +1,25 @@ +@if "%_echo%" neq "on" echo off +setlocal + +if not defined VisualStudioVersion ( + if defined VS140COMNTOOLS ( + call "%VS140COMNTOOLS%\VsDevCmd.bat" + goto :Run + ) + echo Error: Visual Studio 2015 required. + echo Please see https://github.com/dotnet/cli/blob/rel/1.0.0/Documentation/developer-guide.md for build instructions. + exit /b 1 +) + +:Run +powershell -NoProfile -NoLogo -Command "%~dp0build.cmd -NoBuild; exit $LastExitCode;" +set _toolRuntime=%~dp0build_tools +set _dotnet=%_toolRuntime%\dotnetcli\dotnet.exe + +echo Running: %_dotnet% %_toolRuntime%\run.exe %* +call %_dotnet% %_toolRuntime%\run.exe %~dp0config.json %* +if NOT [%ERRORLEVEL%]==[0] ( + exit /b 1 +) + +exit /b 0 \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 000000000..fd709519d --- /dev/null +++ b/run.sh @@ -0,0 +1,24 @@ +#!/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 )" +REPOROOT="$DIR" + +$DIR/build.sh "--nobuild" + +__toolRuntime=$REPOROOT/build_tools +__dotnet=$__toolRuntime/dotnetcli/dotnet + +echo "Running: $__dotnet $__toolRuntime/run.exe $@" +$__dotnet $__toolRuntime/run.exe $DIR/config.json "$@"