From ce7ff1cf6b009c91bb30841ec7e674efe0ffe914 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 6 Sep 2017 17:59:04 -0700 Subject: [PATCH 1/4] Add build and test environment setup scripts, update developer guide --- Documentation/project-docs/developer-guide.md | 12 +++++--- scripts/cli-build-env.bat | 17 +++++++++++ scripts/cli-build-env.sh | 23 +++++++++++++++ scripts/cli-test-env.bat | 20 +++++++++++++ scripts/cli-test-env.sh | 28 +++++++++++++++++++ 5 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 scripts/cli-build-env.bat create mode 100644 scripts/cli-build-env.sh create mode 100644 scripts/cli-test-env.bat create mode 100644 scripts/cli-test-env.sh diff --git a/Documentation/project-docs/developer-guide.md b/Documentation/project-docs/developer-guide.md index 0391adefa..882a579ba 100644 --- a/Documentation/project-docs/developer-guide.md +++ b/Documentation/project-docs/developer-guide.md @@ -27,8 +27,8 @@ In order to build .NET Command Line Interface, you need the following installed ## Building/Running 1. Run `build.cmd` or `build.sh` from the root depending on your OS. If you don't want to execute tests, run `build.cmd /t:Compile` or `./build.sh /t:Compile`. - - To build the CLI in macOS Sierra, you need to set the DOTNET_RUNTIME_ID environment variable by running `export DOTNET_RUNTIME_ID=osx.10.11-x64`. -2. Use `artifacts/{RID}/stage2/dotnet` to try out the `dotnet` command. You can also add `artifacts/{os}-{arch}/stage2` to the PATH if you want to use the build output when invoking `dotnet` from the current console. + - To build the CLI in macOS Sierra, you need to set the DOTNET_RUNTIME_ID environment variable by running `export DOTNET_RUNTIME_ID=osx.10.11-x64`. +2. The CLI that is built (we call it stage 2) will be laid out in the `bin\2\{RID}\dotnet` folder. You can run `dotnet.exe` or `dotnet` from that folder to try out the `dotnet` command. ## A simple test Using the `dotnet` built in the previous step: @@ -40,8 +40,12 @@ Using the `dotnet` built in the previous step: ## Running tests -1. To run all tests invoke `build.cmd` or `build.sh` which will build the product and run the tests. -2. To run a specific test, cd into that test's directory and execute `dotnet test`. If using this approach, make sure to add `artifacts/{RID}/stage2` to your `PATH` and set the `NUGET_PACKAGES` environment variable to point to the repo's `.nuget/packages` directory. +1. To run all tests, invoke `build.cmd` or `build.sh` which will build the product and run the tests. +2. To run a specific test project: + - Run `scripts\cli-test-env.bat` on Windows, or [source](https://en.wikipedia.org/wiki/Source_(command)) `scripts/cli-test-env.sh` on Linux or OS X. This will add the stage 2 `dotnet` folder to your path and set up other environment variables which are used for running tests. + - `cd` into the test's directory + - Run `dotnet test` + - Refer to the command-line help for `dotnet test` if you want to run a specific test in the test project ## Adding a Command diff --git a/scripts/cli-build-env.bat b/scripts/cli-build-env.bat new file mode 100644 index 000000000..03b6ded6f --- /dev/null +++ b/scripts/cli-build-env.bat @@ -0,0 +1,17 @@ +@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. + +REM Get normalized version of parent path +for %%i in (%~dp0..\) DO ( + SET CLI_REPO_ROOT=%%~dpi +) + +title CLI Build (%CLI_REPO_ROOT%) + +REM Add Stage 0 CLI to path +set PATH=%CLI_REPO_ROOT%.dotnet_stage0\x64;%PATH% + +set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +set DOTNET_MULTILEVEL_LOOKUP=0 +set NUGET_PACKAGES=%CLI_REPO_ROOT%.nuget\packages \ No newline at end of file diff --git a/scripts/cli-build-env.sh b/scripts/cli-build-env.sh new file mode 100644 index 000000000..05231edcb --- /dev/null +++ b/scripts/cli-build-env.sh @@ -0,0 +1,23 @@ +#!/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. +# + +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 + +REPO_ROOT="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )" + +STAGE0_DIR=$REPO_ROOT.dotnet_stage0/x64 +export PATH=$STAGE0_DIR:$PATH + + +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_MULTILEVEL_LOOKUP=0 + +export NUGET_PACKAGES=$REPO_ROOT/.nuget/packages diff --git a/scripts/cli-test-env.bat b/scripts/cli-test-env.bat new file mode 100644 index 000000000..5e6f644fc --- /dev/null +++ b/scripts/cli-test-env.bat @@ -0,0 +1,20 @@ +@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. + +REM Get normalized version of parent path +for %%i in (%~dp0..\) DO ( + SET CLI_REPO_ROOT=%%~dpi +) + +title CLI Test (%CLI_REPO_ROOT%) + +REM Add Stage 2 CLI to path +set PATH=%CLI_REPO_ROOT%bin\2\win10-x64\dotnet + +set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +set DOTNET_MULTILEVEL_LOOKUP=0 +set NUGET_PACKAGES=%CLI_REPO_ROOT%.nuget\packages +set TEST_PACKAGES=%CLI_REPO_ROOT%bin\2\win10-x64\test\packages +set TEST_ARTIFACTS=%CLI_REPO_ROOT%bin\2\win10-x64\test\artifacts +set PreviousStageProps=%CLI_REPO_ROOT%bin\2\win10-x64\PreviousStage.props diff --git a/scripts/cli-test-env.sh b/scripts/cli-test-env.sh new file mode 100644 index 000000000..846a160ae --- /dev/null +++ b/scripts/cli-test-env.sh @@ -0,0 +1,28 @@ +#!/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. +# + +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 + +REPO_ROOT="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )" + +RID=linux-x64 + +STAGE2_DIR=$REPO_ROOT/bin/2/$RID/dotnet +export PATH=$STAGE2_DIR:$PATH + + +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_MULTILEVEL_LOOKUP=0 + +export NUGET_PACKAGES=$REPO_ROOT/.nuget/packages +export TEST_PACKAGES=$REPO_ROOT/bin/2/$RID/test/packages +export TEST_ARTIFACTS=$REPO_ROOT/bin/2/$RID/test/artifacts +export PreviousStageProps=$REPO_ROOT/bin/2/$RID/PreviousStage.props \ No newline at end of file From 987a5da85af3f38963c7f7601b53b481429c0aeb Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 6 Sep 2017 18:01:39 -0700 Subject: [PATCH 2/4] Delete old environment scripts which don't appear to be used or up to date --- scripts/dev-dotnet.ps1 | 24 ------------------------ scripts/dev-dotnet.sh | 25 ------------------------- scripts/unuse-dev.ps1 | 9 --------- scripts/use-dev.ps1 | 16 ---------------- 4 files changed, 74 deletions(-) delete mode 100644 scripts/dev-dotnet.ps1 delete mode 100755 scripts/dev-dotnet.sh delete mode 100644 scripts/unuse-dev.ps1 delete mode 100644 scripts/use-dev.ps1 diff --git a/scripts/dev-dotnet.ps1 b/scripts/dev-dotnet.ps1 deleted file mode 100644 index 9276b89d8..000000000 --- a/scripts/dev-dotnet.ps1 +++ /dev/null @@ -1,24 +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. -# - -$oldPath = $env:PATH -try { - # Put the stage2 output on the front of the path - if(!(Get-Command dotnet -ErrorAction SilentlyContinue)) { - throw "You need to have a version of 'dotnet' on your path so we can determine the RID" - } - - $rid = dotnet --version | where { $_ -match "^ Runtime Id:\s*(.*)$" } | foreach { $matches[1] } - $stage2 = "$PSScriptRoot\..\artifacts\$rid\stage2\bin" - if (Test-Path $stage2) { - $env:PATH="$stage2;$env:PATH" - } else { - Write-Host "You don't have a dev build in the 'artifacts\$rid\stage2' folder!" - } - - dotnet @args -} finally { - $env:PATH = $oldPath -} diff --git a/scripts/dev-dotnet.sh b/scripts/dev-dotnet.sh deleted file mode 100755 index e7d8e6eac..000000000 --- a/scripts/dev-dotnet.sh +++ /dev/null @@ -1,25 +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 )" - -source "$DIR/common/_common.sh" - -if [ -d "$STAGE2_DIR" ]; then - PATH=$STAGE2_DIR/bin:$PATH - dotnet "$@" -else - echo "You don't have a dev build!" 1>&2 - exit 1 -fi diff --git a/scripts/unuse-dev.ps1 b/scripts/unuse-dev.ps1 deleted file mode 100644 index fbf5f4c18..000000000 --- a/scripts/unuse-dev.ps1 +++ /dev/null @@ -1,9 +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. -# - -# Remove the stage2 output from the path -$splat = $env:PATH.Split(";") -$stripped = @($splat | where { $_ -notlike "*artifacts\win7-x64\stage2*" }) -$env:PATH = [string]::Join(";", $stripped) diff --git a/scripts/use-dev.ps1 b/scripts/use-dev.ps1 deleted file mode 100644 index acd2fff86..000000000 --- a/scripts/use-dev.ps1 +++ /dev/null @@ -1,16 +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. -# - -# Put the stage2 output on the front of the path -$stage2 = "$PSScriptRoot\..\artifacts\win10-x64\stage2" -if (Test-Path $stage2) { - $splat = $env:PATH.Split(";") - $stage2 = Convert-Path $stage2 - if ($splat -notcontains $stage2) { - $env:PATH="$stage2;$env:PATH" - } -} else { - Write-Host "You don't have a dev build in the 'artifacts\win10-x64\stage2' folder!" -} From ec9be1d0d1bddb2c6bf012f83cf4615b4e52f61d Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 7 Sep 2017 14:36:13 -0700 Subject: [PATCH 3/4] Update test environment script to work on Mac OS --- scripts/cli-test-env.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/cli-test-env.sh b/scripts/cli-test-env.sh index 846a160ae..2d334b057 100644 --- a/scripts/cli-test-env.sh +++ b/scripts/cli-test-env.sh @@ -13,7 +13,12 @@ done REPO_ROOT="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )" -RID=linux-x64 +if [ "$uname" = "Darwin" ] +then + RID=osx-x64 +else + RID=linux-x64 +fi STAGE2_DIR=$REPO_ROOT/bin/2/$RID/dotnet export PATH=$STAGE2_DIR:$PATH From d6189e64e624ba0426f66b60ddc7a6c8da5be723 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 7 Sep 2017 14:36:42 -0700 Subject: [PATCH 4/4] Remove workaround which is no longer necessary --- Documentation/project-docs/developer-guide.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/project-docs/developer-guide.md b/Documentation/project-docs/developer-guide.md index 882a579ba..7e8e76055 100644 --- a/Documentation/project-docs/developer-guide.md +++ b/Documentation/project-docs/developer-guide.md @@ -27,7 +27,6 @@ In order to build .NET Command Line Interface, you need the following installed ## Building/Running 1. Run `build.cmd` or `build.sh` from the root depending on your OS. If you don't want to execute tests, run `build.cmd /t:Compile` or `./build.sh /t:Compile`. - - To build the CLI in macOS Sierra, you need to set the DOTNET_RUNTIME_ID environment variable by running `export DOTNET_RUNTIME_ID=osx.10.11-x64`. 2. The CLI that is built (we call it stage 2) will be laid out in the `bin\2\{RID}\dotnet` folder. You can run `dotnet.exe` or `dotnet` from that folder to try out the `dotnet` command. ## A simple test