diff --git a/build.cmd b/build.cmd index bd617d268..cbf5108a7 100644 --- a/build.cmd +++ b/build.cmd @@ -3,5 +3,5 @@ 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. -powershell -NoProfile -NoLogo -Command "%~dp0build_projects\dotnet-cli-build\build.ps1 %*; exit $LastExitCode;" +powershell -NoProfile -NoLogo -Command "%~dp0run-build.ps1 %*; exit $LastExitCode;" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/build.proj b/build.proj index 3935e56a4..314ba3bdd 100644 --- a/build.proj +++ b/build.proj @@ -12,9 +12,6 @@ .ps1 .sh - -NoRun - --norun - Prepare;Compile;Test;Package;Publish $(MSBuildThisFileDirectory)/build_projects/dotnet-cli-build/bin/dotnet-cli-build $(CLIBuildFileName).dll @@ -30,6 +27,11 @@ 1.0.2 1.0.2 + + $(RepoRoot)/.dotnet_stage0/$(Architecture) + .exe + + $(Stage0Path)/dotnet$(ExeExtension) @@ -48,7 +50,13 @@ Inputs="@(DotnetCliBuildFrameworkInputs)" Outputs="$(CLIBuildDll)" DependsOnTargets="MSBuildWorkaroundTarget"> - + + $(MSBuildThisFileDirectory)/build_projects/dotnet-cli-build + + + + + diff --git a/build.sh b/build.sh index ae1cde343..2c9737f7f 100755 --- a/build.sh +++ b/build.sh @@ -49,12 +49,12 @@ args=($temp) dockerbuild() { - BUILD_COMMAND=/opt/code/build_projects/dotnet-cli-build/build.sh $DIR/scripts/dockerrun.sh --non-interactive "$@" + BUILD_COMMAND=/opt/code/run-build.sh $DIR/scripts/dockerrun.sh --non-interactive "$@" } # Check if we need to build in docker if [ ! -z "$BUILD_IN_DOCKER" ]; then dockerbuild "${args[@]}" else - $DIR/build_projects/dotnet-cli-build/build.sh "${args[@]}" + $DIR/run-build.sh "${args[@]}" fi diff --git a/build/Microsoft.DotNet.Cli.Compile.targets b/build/Microsoft.DotNet.Cli.Compile.targets index 919c0a057..62ccbfe11 100644 --- a/build/Microsoft.DotNet.Cli.Compile.targets +++ b/build/Microsoft.DotNet.Cli.Compile.targets @@ -27,7 +27,7 @@ @(CompileStageInputs) $(Stage1Directory) $(Stage1SymbolsDirectory) - $(Stage0Path)/dotnet$(ExeExtension) + $(DotnetStage0) @(CompileStageInputs) @@ -72,12 +72,6 @@ - - - - - - @@ -155,6 +149,14 @@ Lines="$(CommitHash);$(SdkVersion)" Overwrite="true" /> + + + + + + + + diff --git a/build/Microsoft.DotNet.Cli.Prepare.targets b/build/Microsoft.DotNet.Cli.Prepare.targets index e4da334aa..482997252 100644 --- a/build/Microsoft.DotNet.Cli.Prepare.targets +++ b/build/Microsoft.DotNet.Cli.Prepare.targets @@ -22,12 +22,7 @@ - - $(RepoRoot)/.dotnet_stage0/Windows/$(Architecture) - $(RepoRoot)/.dotnet_stage0/Darwin - $(RepoRoot)/.dotnet_stage0/Linux - .exe - + $(Stage0Path) $(RepoRoot)/artifacts/$(Rid) @@ -131,21 +126,21 @@ <_DownloadAndExtractItem Include="DownloadedSharedFrameworkInstallerFile" - Condition="!Exists('$(DownloadedSharedFrameworkInstallerFile)')"> + Condition="!Exists('$(DownloadedSharedFrameworkInstallerFile)') And '$(InstallerExtension)' != ''"> $(CoreSetupInstallerBlobRootUrl)/$(SharedFrameworkVersion)/$(DownloadedSharedFrameworkInstallerFileName) $(DownloadedSharedFrameworkInstallerFile) <_DownloadAndExtractItem Include="DownloadedSharedHostInstallerFile" - Condition="!Exists('$(DownloadedSharedHostInstallerFile)')"> + Condition="!Exists('$(DownloadedSharedHostInstallerFile)') And '$(InstallerExtension)' != ''"> $(CoreSetupInstallerBlobRootUrl)/$(SharedHostVersion)/$(DownloadedSharedHostInstallerFileName) $(DownloadedSharedHostInstallerFile) <_DownloadAndExtractItem Include="DownloadedHostFxrInstallerFile" - Condition="!Exists('$(DownloadedHostFxrInstallerFile)')"> + Condition="!Exists('$(DownloadedHostFxrInstallerFile)') And '$(InstallerExtension)' != ''"> $(CoreSetupInstallerBlobRootUrl)/$(HostFxrVersion)/$(DownloadedHostFxrInstallerFileName) $(DownloadedHostFxrInstallerFile) diff --git a/build/package/Microsoft.DotNet.Cli.Installer.DEB.targets b/build/package/Microsoft.DotNet.Cli.Installer.DEB.targets index 13bf3b7df..0bcba8086 100644 --- a/build/package/Microsoft.DotNet.Cli.Installer.DEB.targets +++ b/build/package/Microsoft.DotNet.Cli.Installer.DEB.targets @@ -4,7 +4,6 @@ - + - diff --git a/build_projects/dotnet-cli-build/DebTargets.cs b/build_projects/dotnet-cli-build/DebTargets.cs index cf5435cf8..b55a1a260 100644 --- a/build_projects/dotnet-cli-build/DebTargets.cs +++ b/build_projects/dotnet-cli-build/DebTargets.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Runtime.InteropServices; +using Microsoft.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.InternalAbstractions; @@ -13,6 +14,9 @@ namespace Microsoft.DotNet.Cli.Build { public class DebTargets : Task { + [Required] + public string CLISDKRoot { get; set; } + public override bool Execute() { BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly().CreateBuildContext(); @@ -21,7 +25,7 @@ namespace Microsoft.DotNet.Cli.Build return GenerateDebs(c).Success; } - public static BuildTargetResult GenerateDebs(BuildTargetContext c) + public BuildTargetResult GenerateDebs(BuildTargetContext c) { if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu)) { @@ -32,7 +36,7 @@ namespace Microsoft.DotNet.Cli.Build return c.Success(); } - public static BuildTargetResult GenerateSdkDeb(BuildTargetContext c) + public BuildTargetResult GenerateSdkDeb(BuildTargetContext c) { if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu)) { @@ -53,7 +57,6 @@ namespace Microsoft.DotNet.Cli.Build var debFile = c.BuildContext.Get("SdkInstallerFile"); var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages"); var previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb"; - var sdkPublishRoot = c.BuildContext.Get("CLISDKRoot"); var sharedFxDebianPackageName = Monikers.GetDebianSharedFrameworkPackageName(CliDependencyVersions.SharedFrameworkVersion); var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sdk"); @@ -67,7 +70,7 @@ namespace Microsoft.DotNet.Cli.Build Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"), "-v", version, - "-i", sdkPublishRoot, + "-i", CLISDKRoot, "-o", debFile, "-p", packageName, "-b", Monikers.CLISdkBrandName, diff --git a/build_projects/dotnet-cli-build/InstallerTargets.cs b/build_projects/dotnet-cli-build/InstallerTargets.cs index fd1acdc80..42f928ea9 100644 --- a/build_projects/dotnet-cli-build/InstallerTargets.cs +++ b/build_projects/dotnet-cli-build/InstallerTargets.cs @@ -6,9 +6,14 @@ namespace Microsoft.DotNet.Cli.Build { public static BuildTargetResult GenerateInstaller(BuildTargetContext c) { + var debTargets = new DebTargets + { + CLISDKRoot = c.BuildContext.Get("CLISDKRoot") + }; + MsiTargets.GenerateMsisAndBundles(c); PkgTargets.GeneratePkgs(c); - DebTargets.GenerateDebs(c); + debTargets.GenerateDebs(c); return c.Success(); } diff --git a/build_projects/dotnet-cli-build/build.ps1 b/build_projects/dotnet-cli-build/build.ps1 deleted file mode 100644 index bbc5dde50..000000000 --- a/build_projects/dotnet-cli-build/build.ps1 +++ /dev/null @@ -1,91 +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]$Configuration="Debug", - [string[]]$Targets=@("Default"), - [string]$Architecture="x64", - [switch]$NoPackage, - [switch]$NoRun, - [switch]$Help) - -if($Help) -{ - Write-Host "Usage: .\build.ps1 [-Configuration ] [-Targets ] [-Architecture ] [-NoPackage] [-Help]" - Write-Host "" - Write-Host "Options:" - Write-Host " -Configuration Build the specified Configuration (Debug or Release, default: Debug)" - Write-Host " -Targets Comma separated build targets to run (Init, Compile, Publish, etc.; Default is a full build and publish)" - Write-Host " -Architecture Build the specified architecture (x64 or x86 (supported only on Windows), default: x64)" - Write-Host " -NoPackage Skip packaging targets" - Write-Host " -NoRun Skip running the build" - Write-Host " -Help Display this help message" - exit 0 -} - -$env:CONFIGURATION = $Configuration; -$RepoRoot = "$PSScriptRoot\..\.." -$env:NUGET_PACKAGES = "$RepoRoot\.nuget\packages" - -if($NoPackage) -{ - $env:DOTNET_BUILD_SKIP_PACKAGING=1 -} -else -{ - $env:DOTNET_BUILD_SKIP_PACKAGING=0 -} - -# Load Branch Info -cat "$RepoRoot\branchinfo.txt" | ForEach-Object { - if(!$_.StartsWith("#") -and ![String]::IsNullOrWhiteSpace($_)) { - $splat = $_.Split([char[]]@("="), 2) - Set-Content "env:\$($splat[0])" -Value $splat[1] - } -} - -# Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot -if (!$env:DOTNET_INSTALL_DIR) -{ - $env:DOTNET_INSTALL_DIR="$RepoRoot\.dotnet_stage0\Windows\$Architecture" -} - -if (!(Test-Path $env:DOTNET_INSTALL_DIR)) -{ - mkdir $env:DOTNET_INSTALL_DIR | Out-Null -} - -# 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 - -# Restore the build scripts -Write-Host "Restoring Build Script projects..." -pushd "$PSScriptRoot" -dotnet restore -if($LASTEXITCODE -ne 0) { throw "Failed to restore" } -popd - -# Publish the builder -Write-Host "Compiling Build Scripts..." -dotnet publish "$PSScriptRoot" -o "$PSScriptRoot\bin" --framework netcoreapp1.0 -if($LASTEXITCODE -ne 0) { throw "Failed to compile build scripts" } - -if(!$NoRun) -{ - # Run the builder - Write-Host "Invoking Build Scripts..." - Write-Host " Configuration: $env:CONFIGURATION" - & "$PSScriptRoot\bin\dotnet-cli-build.exe" @Targets - if($LASTEXITCODE -ne 0) { throw "Build failed" } -} diff --git a/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs b/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs index 82762ce56..7e6451e98 100644 --- a/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs +++ b/build_projects/shared-build-targets-utils/Utils/DotNetCli.cs @@ -55,17 +55,9 @@ namespace Microsoft.DotNet.Cli.Build private static string GetStage0Path() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", - RuntimeEnvironment.OperatingSystemPlatform.ToString(), - RuntimeEnvironment.RuntimeArchitecture); - } - else - { - return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", RuntimeEnvironment.OperatingSystemPlatform.ToString()); - } - + return Path.Combine(Directory.GetCurrentDirectory(), + ".dotnet_stage0", + RuntimeEnvironment.RuntimeArchitecture); } } } diff --git a/build_projects/update-dependencies/update-dependencies.ps1 b/build_projects/update-dependencies/update-dependencies.ps1 index 4ecef6840..319f10f62 100644 --- a/build_projects/update-dependencies/update-dependencies.ps1 +++ b/build_projects/update-dependencies/update-dependencies.ps1 @@ -25,7 +25,7 @@ $AppPath = "$PSScriptRoot" # Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot if (!$env:DOTNET_INSTALL_DIR) { - $env:DOTNET_INSTALL_DIR="$RepoRoot\.dotnet_stage0\Windows\$Architecture" + $env:DOTNET_INSTALL_DIR="$RepoRoot\.dotnet_stage0\$Architecture" } # Install a stage 0 diff --git a/init-tools.ps1 b/init-tools.ps1 new file mode 100644 index 000000000..250505650 --- /dev/null +++ b/init-tools.ps1 @@ -0,0 +1,40 @@ +# +# 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" + +# Load Branch Info +cat "$RepoRoot\branchinfo.txt" | ForEach-Object { + if(!$_.StartsWith("#") -and ![String]::IsNullOrWhiteSpace($_)) { + $splat = $_.Split([char[]]@("="), 2) + Set-Content "env:\$($splat[0])" -Value $splat[1] + } +} + +# Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot +if (!$env:DOTNET_INSTALL_DIR) +{ + $env:DOTNET_INSTALL_DIR="$RepoRoot\.dotnet_stage0\$Architecture" +} + +if (!(Test-Path $env:DOTNET_INSTALL_DIR)) +{ + mkdir $env:DOTNET_INSTALL_DIR | Out-Null +} + +# 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 \ No newline at end of file diff --git a/init-tools.sh b/init-tools.sh new file mode 100755 index 000000000..446c4eb85 --- /dev/null +++ b/init-tools.sh @@ -0,0 +1,17 @@ +#!/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 \ No newline at end of file diff --git a/run-build.ps1 b/run-build.ps1 new file mode 100644 index 000000000..07a620c3c --- /dev/null +++ b/run-build.ps1 @@ -0,0 +1,41 @@ +# +# 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]$Configuration="Debug", + [string]$Architecture="x64", + [switch]$NoPackage, + [switch]$Help) + +if($Help) +{ + Write-Host "Usage: .\build.ps1 [-Configuration ] [-Architecture ] [-NoPackage] [-Help]" + Write-Host "" + Write-Host "Options:" + 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 " -Help Display this help message" + exit 0 +} + +$env:CONFIGURATION = $Configuration; +$RepoRoot = "$PSScriptRoot" +$env:NUGET_PACKAGES = "$RepoRoot\.nuget\packages" + +if($NoPackage) +{ + $env:DOTNET_BUILD_SKIP_PACKAGING=1 +} +else +{ + $env:DOTNET_BUILD_SKIP_PACKAGING=0 +} + +& "$RepoRoot\init-tools.ps1" -Architecture $Architecture +if($LASTEXITCODE -ne 0) { throw "Failed to install Init Tools" } + +dotnet build3 build.proj /p:Architecture=$Architecture +if($LASTEXITCODE -ne 0) { throw "Failed to build" } diff --git a/build_projects/dotnet-cli-build/build.sh b/run-build.sh similarity index 66% rename from build_projects/dotnet-cli-build/build.sh rename to run-build.sh index 11fee896c..d7e5cd3bf 100755 --- a/build_projects/dotnet-cli-build/build.sh +++ b/run-build.sh @@ -13,11 +13,15 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli [[ "$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" OLDPATH="$PATH" -REPOROOT="$DIR/../.." +ARCHITECTURE="x64" source "$REPOROOT/scripts/common/_prettyprint.sh" +# Set nuget package cache under the repo +export NUGET_PACKAGES="$REPOROOT/.nuget/packages" + while [[ $# > 0 ]]; do lowerI="$(echo $1 | awk '{print tolower($0)}')" case $lowerI in @@ -25,16 +29,9 @@ while [[ $# > 0 ]]; do export CONFIGURATION=$2 shift ;; - --targets) - IFS=',' read -r -a targets <<< $2 - shift - ;; --nopackage) export DOTNET_BUILD_SKIP_PACKAGING=1 ;; - --norun) - export DOTNET_BUILD_SKIP_RUN=1 - ;; --skip-prereqs) # Allow CI to disable prereqs check since the CI has the pre-reqs but not ldconfig it seems export DOTNET_INSTALL_SKIP_PREREQS=1 @@ -44,10 +41,8 @@ while [[ $# > 0 ]]; do echo "" echo "Options:" echo " --configuration Build the specified Configuration (Debug or Release, default: Debug)" - echo " --targets Comma separated build targets to run (Init, Compile, Publish, etc.; Default is a full build and publish)" echo " --skip-prereqs Skip checks for pre-reqs in dotnet_install" echo " --nopackage Skip packaging targets" - echo " --norun Skip running the build" echo " --docker Build in Docker using the Dockerfile located in scripts/docker/IMAGENAME" echo " --help Display this help message" exit 0 @@ -60,25 +55,6 @@ while [[ $# > 0 ]]; do shift done -# Set nuget package cache under the repo -export NUGET_PACKAGES="$REPOROOT/.nuget/packages" - -# Set up the environment to be used for building with clang. -if which "clang-3.5" > /dev/null 2>&1; then - export CC="$(which clang-3.5)" - export CXX="$(which clang++-3.5)" -elif which "clang-3.6" > /dev/null 2>&1; then - export CC="$(which clang-3.6)" - export CXX="$(which clang++-3.6)" -elif which clang > /dev/null 2>&1; then - export CC="$(which clang)" - export CXX="$(which clang++)" -else - error "Unable to find Clang Compiler" - error "Install clang-3.5 or clang3.6" - exit 1 -fi - # Load Branch Info while read line; do if [[ $line != \#* ]]; then @@ -88,10 +64,10 @@ while read line; do done < "$REPOROOT/branchinfo.txt" # Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot -[ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$(uname) +[ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$ARCHITECTURE [ -d "$DOTNET_INSTALL_DIR" ] || mkdir -p $DOTNET_INSTALL_DIR -$REPOROOT/scripts/obtain/dotnet-install.sh --channel $CHANNEL --verbose +$REPOROOT/init-tools.sh # Put stage 0 on the PATH (for this shell only) PATH="$DOTNET_INSTALL_DIR:$PATH" @@ -107,23 +83,4 @@ fi # Disable first run since we want to control all package sources export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 -# Restore the build scripts -echo "Restoring Build Script projects..." -( - cd "$DIR" - dotnet restore -) - -# Build the builder -echo "Compiling Build Scripts..." -dotnet publish "$DIR" -o "$DIR/bin" --framework netcoreapp1.0 - -if [ -z "$DOTNET_BUILD_SKIP_RUN" ]; then - export PATH="$OLDPATH" - # Run the builder - echo "Invoking Build Scripts..." - echo "Configuration: $CONFIGURATION" - - $DIR/bin/dotnet-cli-build ${targets[@]} -fi -exit $? +dotnet build3 build.proj /p:Architecture=$ARCHITECTURE \ No newline at end of file