From fd9cb55f1a74679c59b349b671d4df5b3dbdb9db Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Wed, 2 Nov 2016 23:01:57 -0700 Subject: [PATCH] Add msbuild-based stage0 where possible (#4597) * Add msbuild-based stage0 where possible * Fix bash initialization script * Windows Fixes * Fix dotnet deb tool --- build.proj | 8 ++- build/Microsoft.DotNet.Cli.Compile.targets | 2 +- build/Microsoft.DotNet.Cli.Prepare.targets | 13 ++-- build/Microsoft.DotNet.Cli.Test.targets | 67 ++++++++++--------- build/Microsoft.DotNet.Cli.tasks | 9 ++- .../Microsoft.DotNet.Cli.LzmaArchive.targets | 10 +-- .../Microsoft.DotNet.Cli.Installer.DEB.proj | 10 +-- ...Microsoft.DotNet.Cli.Installer.MSI.targets | 2 +- .../Microsoft.DotNet.Cli.Nupkg.targets | 26 +++---- .../dotnet-cli-build/DotNetBuild.cs | 14 +--- ...BuildMsbuildLegacy.cs => DotNetBuildPJ.cs} | 18 +++-- build_projects/dotnet-cli-build/DotNetPack.cs | 18 +---- ...etPackMsbuildLegacy.cs => DotNetPackPJ.cs} | 22 ++++-- ...ishMsbuildLegacy.cs => DotNetPublishPJ.cs} | 4 +- .../dotnet-cli-build/DotNetRestore.cs | 9 +-- .../DotNetRestoreMsbuildLegacy.cs | 56 ---------------- .../dotnet-cli-build/DotNetRestorePJ.cs | 59 ++++++++++++++++ .../DotNetRestoreProjectJson.cs | 59 ---------------- run-build.ps1 | 25 ++++++- run-build.sh | 15 ++++- .../RepoDirectoriesProvider.cs | 2 +- 21 files changed, 218 insertions(+), 230 deletions(-) rename build_projects/dotnet-cli-build/{DotNetBuildMsbuildLegacy.cs => DotNetBuildPJ.cs} (77%) rename build_projects/dotnet-cli-build/{DotNetPackMsbuildLegacy.cs => DotNetPackPJ.cs} (79%) rename build_projects/dotnet-cli-build/{DotNetPublishMsbuildLegacy.cs => DotNetPublishPJ.cs} (96%) delete mode 100644 build_projects/dotnet-cli-build/DotNetRestoreMsbuildLegacy.cs create mode 100644 build_projects/dotnet-cli-build/DotNetRestorePJ.cs delete mode 100644 build_projects/dotnet-cli-build/DotNetRestoreProjectJson.cs diff --git a/build.proj b/build.proj index 987b159a4..0a3e7a050 100644 --- a/build.proj +++ b/build.proj @@ -32,7 +32,9 @@ $(RepoRoot)/.dotnet_stage0/$(Architecture) + $(RepoRoot)/.dotnet_stage0PJ/$(Architecture) $(Stage0Directory)/dotnet$(ExeExtension) + $(Stage0PjDirectory)/dotnet$(ExeExtension) $(RepoRoot)/build_projects/dotnet-cli-build $(RepoRoot)/.nuget @@ -55,7 +57,8 @@ DependsOnTargets="MSBuildWorkaroundTarget; RestoreDotnetCliBuildFramework"> - + @@ -72,7 +75,8 @@ $(ExtraRestoreArgs) --disable-parallel - + diff --git a/build/Microsoft.DotNet.Cli.Compile.targets b/build/Microsoft.DotNet.Cli.Compile.targets index cc79410e7..ed53e1d0e 100644 --- a/build/Microsoft.DotNet.Cli.Compile.targets +++ b/build/Microsoft.DotNet.Cli.Compile.targets @@ -103,7 +103,7 @@ DestinationFiles="@(HackFilesToCopy->'$(SdkOutputDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" /> - False True $(Stage0Directory) + $(Stage0PjDirectory) $(RepoRoot)/artifacts/$(Rid) $(BaseOutputDirectory)/tools @@ -189,7 +190,8 @@ - + @@ -213,7 +215,8 @@ - + @@ -237,8 +240,10 @@ - - + + diff --git a/build/Microsoft.DotNet.Cli.Test.targets b/build/Microsoft.DotNet.Cli.Test.targets index 45d6db400..aea5d4f0a 100644 --- a/build/Microsoft.DotNet.Cli.Test.targets +++ b/build/Microsoft.DotNet.Cli.Test.targets @@ -14,6 +14,7 @@ DependsOnTargets="PrepareTests; BuildTestAssets; BuildTests;"> + : %3b @@ -39,7 +40,7 @@ EnvironmentVariables=$(RunTestEnvironmentVariables); TestProjectName=%(TestProjects.OutputName); TestResultXmlDir=$(TestResultXmlDir); - ToolPath=$(Stage0Directory); + ToolPath=$(Stage0PjDirectory); WorkingDirectory=%(TestProjects.ProjectDir) @@ -70,10 +71,11 @@ SetupTestProjectData;" Inputs="%(TestProjects.BuildInputs)" Outputs="%(TestProjects.BuildOutput)"> - + + + - + - + - + @@ -177,7 +180,7 @@ @@ -188,9 +191,9 @@ Inputs="@(RestoreDesktopTestAssetProjectsInputs)" Outputs="@(RestoreDesktopTestAssetProjectsInputs->'%(RelativeDir)/project.lock.json')"> - + @@ -205,12 +208,12 @@ Inputs="%(TestPackageProject.PackInputs)" Outputs="%(TestPackageProject.PackOutputs)"> - + - + - + - + - + - + - - + diff --git a/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets b/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets index 51dae6f99..6ee62455a 100644 --- a/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets +++ b/build/compile/Microsoft.DotNet.Cli.LzmaArchive.targets @@ -25,11 +25,11 @@ - + diff --git a/build/package/Microsoft.DotNet.Cli.Installer.DEB.proj b/build/package/Microsoft.DotNet.Cli.Installer.DEB.proj index a14369b3e..8ba69f90f 100644 --- a/build/package/Microsoft.DotNet.Cli.Installer.DEB.proj +++ b/build/package/Microsoft.DotNet.Cli.Installer.DEB.proj @@ -49,7 +49,7 @@ ReplacementStrings="@(DebianConfigTokenValues -> '%(ReplacementString)')" /> - @@ -135,9 +135,9 @@ - + + -DotnetDir '$(Stage0PjDirectory)'" /> - + - + DependsOnTargets="Init; SetupProjectsToPack" + Condition=" '$(OS)' == 'Windows_NT' "> - + + + diff --git a/build_projects/dotnet-cli-build/DotNetBuild.cs b/build_projects/dotnet-cli-build/DotNetBuild.cs index 41dd18716..ee57e1f82 100644 --- a/build_projects/dotnet-cli-build/DotNetBuild.cs +++ b/build_projects/dotnet-cli-build/DotNetBuild.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli.Build protected override string Args { - get { return $"{GetProjectPath()} {GetConfiguration()} {GetFramework()} {GetBuildBasePath()}"; } + get { return $"{GetProjectPath()} {GetConfiguration()} {GetFramework()}"; } } public string BuildBasePath { get; set; } @@ -22,17 +22,7 @@ namespace Microsoft.DotNet.Cli.Build public string Framework { get; set; } public string ProjectPath { get; set; } - - private string GetBuildBasePath() - { - if (!string.IsNullOrEmpty(BuildBasePath)) - { - return $"--build-base-path {BuildBasePath}"; - } - - return null; - } - + private string GetConfiguration() { if (!string.IsNullOrEmpty(Configuration)) diff --git a/build_projects/dotnet-cli-build/DotNetBuildMsbuildLegacy.cs b/build_projects/dotnet-cli-build/DotNetBuildPJ.cs similarity index 77% rename from build_projects/dotnet-cli-build/DotNetBuildMsbuildLegacy.cs rename to build_projects/dotnet-cli-build/DotNetBuildPJ.cs index c9523efcb..e0650cbe3 100644 --- a/build_projects/dotnet-cli-build/DotNetBuildMsbuildLegacy.cs +++ b/build_projects/dotnet-cli-build/DotNetBuildPJ.cs @@ -3,16 +3,16 @@ namespace Microsoft.DotNet.Cli.Build { - public class DotNetBuildMsbuildLegacy : DotNetTool + public class DotNetBuildPJ : DotNetTool { protected override string Command { - get { return "build3"; } + get { return "build"; } } protected override string Args { - get { return $"{GetProjectPath()} {GetConfiguration()} {GetFramework()}"; } + get { return $"{GetProjectPath()} {GetConfiguration()} {GetFramework()} {GetBuildBasePath()}"; } } public string BuildBasePath { get; set; } @@ -22,7 +22,17 @@ namespace Microsoft.DotNet.Cli.Build public string Framework { get; set; } public string ProjectPath { get; set; } - + + private string GetBuildBasePath() + { + if (!string.IsNullOrEmpty(BuildBasePath)) + { + return $"--build-base-path {BuildBasePath}"; + } + + return null; + } + private string GetConfiguration() { if (!string.IsNullOrEmpty(Configuration)) diff --git a/build_projects/dotnet-cli-build/DotNetPack.cs b/build_projects/dotnet-cli-build/DotNetPack.cs index f94659a47..60005785a 100644 --- a/build_projects/dotnet-cli-build/DotNetPack.cs +++ b/build_projects/dotnet-cli-build/DotNetPack.cs @@ -12,15 +12,13 @@ namespace Microsoft.DotNet.Cli.Build protected override string Args { - get { return $"{GetProjectPath()} {GetConfiguration()} {GetNoBuild()} {GetBuildBasePath()} {GetOutput()} {GetVersionSuffix()}"; } + get { return $"{GetProjectPath()} {GetConfiguration()} {GetNoBuild()} {GetOutput()} {GetVersionSuffix()}"; } } public string Configuration { get; set; } public bool NoBuild { get; set; } - - public string BuildBasePath { get; set; } - + public string Output { get; set; } public string ProjectPath { get; set; } @@ -46,17 +44,7 @@ namespace Microsoft.DotNet.Cli.Build return null; } - - private string GetBuildBasePath() - { - if (!string.IsNullOrEmpty(BuildBasePath)) - { - return $"--build-base-path {BuildBasePath}"; - } - - return null; - } - + private string GetOutput() { if (!string.IsNullOrEmpty(Output)) diff --git a/build_projects/dotnet-cli-build/DotNetPackMsbuildLegacy.cs b/build_projects/dotnet-cli-build/DotNetPackPJ.cs similarity index 79% rename from build_projects/dotnet-cli-build/DotNetPackMsbuildLegacy.cs rename to build_projects/dotnet-cli-build/DotNetPackPJ.cs index 7bc8be718..ff061c679 100644 --- a/build_projects/dotnet-cli-build/DotNetPackMsbuildLegacy.cs +++ b/build_projects/dotnet-cli-build/DotNetPackPJ.cs @@ -3,22 +3,24 @@ namespace Microsoft.DotNet.Cli.Build { - public class DotNetPackMsbuildLegacy : DotNetTool + public class DotNetPackPJ : DotNetTool { protected override string Command { - get { return "pack3"; } + get { return "pack"; } } protected override string Args { - get { return $"{GetProjectPath()} {GetConfiguration()} {GetNoBuild()} {GetOutput()} {GetVersionSuffix()}"; } + get { return $"{GetProjectPath()} {GetConfiguration()} {GetNoBuild()} {GetBuildBasePath()} {GetOutput()} {GetVersionSuffix()}"; } } public string Configuration { get; set; } public bool NoBuild { get; set; } - + + public string BuildBasePath { get; set; } + public string Output { get; set; } public string ProjectPath { get; set; } @@ -44,7 +46,17 @@ namespace Microsoft.DotNet.Cli.Build return null; } - + + private string GetBuildBasePath() + { + if (!string.IsNullOrEmpty(BuildBasePath)) + { + return $"--build-base-path {BuildBasePath}"; + } + + return null; + } + private string GetOutput() { if (!string.IsNullOrEmpty(Output)) diff --git a/build_projects/dotnet-cli-build/DotNetPublishMsbuildLegacy.cs b/build_projects/dotnet-cli-build/DotNetPublishPJ.cs similarity index 96% rename from build_projects/dotnet-cli-build/DotNetPublishMsbuildLegacy.cs rename to build_projects/dotnet-cli-build/DotNetPublishPJ.cs index feca222ce..0e09f4eea 100644 --- a/build_projects/dotnet-cli-build/DotNetPublishMsbuildLegacy.cs +++ b/build_projects/dotnet-cli-build/DotNetPublishPJ.cs @@ -3,11 +3,11 @@ namespace Microsoft.DotNet.Cli.Build { - public class DotNetPublishMsbuildLegacy : DotNetTool + public class DotNetPublishPJ : DotNetTool { protected override string Command { - get { return "publish3"; } + get { return "publish"; } } protected override string Args diff --git a/build_projects/dotnet-cli-build/DotNetRestore.cs b/build_projects/dotnet-cli-build/DotNetRestore.cs index 888485d47..9b86678d9 100644 --- a/build_projects/dotnet-cli-build/DotNetRestore.cs +++ b/build_projects/dotnet-cli-build/DotNetRestore.cs @@ -12,9 +12,11 @@ namespace Microsoft.DotNet.Cli.Build protected override string Args { - get { return $"{GetSource()} {GetPackages()} {GetSkipInvalidConfigurations()} {GetDisableParallel()}"; } + get { return $"{Root} {GetSource()} {GetPackages()} {GetSkipInvalidConfigurations()}"; } } + public string Root { get; set; } + public string Source { get; set; } public string Packages { get; set; } @@ -50,10 +52,5 @@ namespace Microsoft.DotNet.Cli.Build return null; } - - private string GetDisableParallel() - { - return "--disable-parallel"; - } } } diff --git a/build_projects/dotnet-cli-build/DotNetRestoreMsbuildLegacy.cs b/build_projects/dotnet-cli-build/DotNetRestoreMsbuildLegacy.cs deleted file mode 100644 index 25a61413c..000000000 --- a/build_projects/dotnet-cli-build/DotNetRestoreMsbuildLegacy.cs +++ /dev/null @@ -1,56 +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. - -namespace Microsoft.DotNet.Cli.Build -{ - public class DotNetRestoreMsbuildLegacy : DotNetTool - { - protected override string Command - { - get { return "restore3"; } - } - - protected override string Args - { - get { return $"{Root} {GetSource()} {GetPackages()} {GetSkipInvalidConfigurations()}"; } - } - - public string Root { get; set; } - - public string Source { get; set; } - - public string Packages { get; set; } - - public bool SkipInvalidConfigurations { get; set; } - - private string GetSource() - { - if (!string.IsNullOrEmpty(Source)) - { - return $"--source {Source}"; - } - - return null; - } - - private string GetPackages() - { - if (!string.IsNullOrEmpty(Packages)) - { - return $"--packages {Packages}"; - } - - return null; - } - - private string GetSkipInvalidConfigurations() - { - if (SkipInvalidConfigurations) - { - return "/p:SkipInvalidConfigurations=true"; - } - - return null; - } - } -} diff --git a/build_projects/dotnet-cli-build/DotNetRestorePJ.cs b/build_projects/dotnet-cli-build/DotNetRestorePJ.cs new file mode 100644 index 000000000..74b621e97 --- /dev/null +++ b/build_projects/dotnet-cli-build/DotNetRestorePJ.cs @@ -0,0 +1,59 @@ +// 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. + +namespace Microsoft.DotNet.Cli.Build +{ + public class DotNetRestorePJ : DotNetTool + { + protected override string Command + { + get { return "restore"; } + } + + protected override string Args + { + get { return $"{GetVerbosity()} {GetFallbackSource()} {GetPackages()} {GetDisableParallel()}"; } + } + + public string FallbackSource { get; set; } + + public string Packages { get; set; } + + public string Verbosity { get; set; } + + private string GetFallbackSource() + { + if (!string.IsNullOrEmpty(FallbackSource)) + { + return $"--fallbacksource {FallbackSource}"; + } + + return null; + } + + private string GetPackages() + { + if (!string.IsNullOrEmpty(Packages)) + { + return $"--packages {Packages}"; + } + + return null; + } + + private string GetVerbosity() + { + if (!string.IsNullOrEmpty(Verbosity)) + { + return $"--verbosity {Verbosity}"; + } + + return null; + } + + private string GetDisableParallel() + { + return "--disable-parallel"; + } + } +} diff --git a/build_projects/dotnet-cli-build/DotNetRestoreProjectJson.cs b/build_projects/dotnet-cli-build/DotNetRestoreProjectJson.cs deleted file mode 100644 index 81f70d15f..000000000 --- a/build_projects/dotnet-cli-build/DotNetRestoreProjectJson.cs +++ /dev/null @@ -1,59 +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. - -namespace Microsoft.DotNet.Cli.Build -{ - public class DotNetRestoreProjectJson : DotNetTool - { - protected override string Command - { - get { return "restore-projectjson"; } - } - - protected override string Args - { - get { return $"{GetVerbosity()} {GetFallbackSource()} {GetPackages()} {GetDisableParallel()}"; } - } - - public string FallbackSource { get; set; } - - public string Packages { get; set; } - - public string Verbosity { get; set; } - - private string GetFallbackSource() - { - if (!string.IsNullOrEmpty(FallbackSource)) - { - return $"--fallbacksource {FallbackSource}"; - } - - return null; - } - - private string GetPackages() - { - if (!string.IsNullOrEmpty(Packages)) - { - return $"--packages {Packages}"; - } - - return null; - } - - private string GetVerbosity() - { - if (!string.IsNullOrEmpty(Verbosity)) - { - return $"--verbosity {Verbosity}"; - } - - return null; - } - - private string GetDisableParallel() - { - return "--disable-parallel"; - } - } -} diff --git a/run-build.ps1 b/run-build.ps1 index 2a425e6c7..e0b236558 100644 --- a/run-build.ps1 +++ b/run-build.ps1 @@ -49,6 +49,17 @@ cat "$RepoRoot\branchinfo.txt" | ForEach-Object { } # Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot +if (!$env:DOTNET_INSTALL_DIR_PJ) +{ + $env:DOTNET_INSTALL_DIR_PJ="$RepoRoot\.dotnet_stage0PJ\$Architecture" +} + +if (!(Test-Path $env:DOTNET_INSTALL_DIR_PJ)) +{ + mkdir $env:DOTNET_INSTALL_DIR_PJ | Out-Null +} + +# Also create an install directory for a post-PJnistic CLI if (!$env:DOTNET_INSTALL_DIR) { $env:DOTNET_INSTALL_DIR="$RepoRoot\.dotnet_stage0\$Architecture" @@ -78,13 +89,25 @@ if ((Test-Path $bootStrapperPath) -eq 0) } # now execute it -& $bootStrapperPath -RepositoryRoot (Get-Location) -ToolsLocalPath $toolsLocalPath -CliLocalPath $env:DOTNET_INSTALL_DIR -Architecture $Architecture | Out-File (Join-Path (Get-Location) "bootstrap.log") +& $bootStrapperPath -RepositoryRoot (Get-Location) -ToolsLocalPath $toolsLocalPath -CliLocalPath $env:DOTNET_INSTALL_DIR_PJ -Architecture $Architecture | 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 } +# install the post-PJnistic stage0 +$dotnetInstallPath = Join-Path $toolsLocalPath "dotnet-install.ps1" + +Write-Host "$dotnetInstallPath -Version ""latest"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" +Invoke-Expression "$dotnetInstallPath -Version ""latest"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" +if ($LastExitCode -ne 0) +{ + Write-Output "The .NET CLI installation failed with exit code $LastExitCode" + exit $LastExitCode +} + + # Put the stage0 on the path $env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH" diff --git a/run-build.sh b/run-build.sh index c842f7e2a..5f4d73cba 100755 --- a/run-build.sh +++ b/run-build.sh @@ -129,6 +129,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_PJ" ] && export DOTNET_INSTALL_DIR_PJ=$REPOROOT/.dotnet_stage0PJ/$ARCHITECTURE +[ -d "$DOTNET_INSTALL_DIR_PJ" ] || mkdir -p $DOTNET_INSTALL_DIR_PJ + +# Also create an install directory for a post-PJnistic CLI [ -z "$DOTNET_INSTALL_DIR" ] && export DOTNET_INSTALL_DIR=$REPOROOT/.dotnet_stage0/$ARCHITECTURE [ -d "$DOTNET_INSTALL_DIR" ] || mkdir -p $DOTNET_INSTALL_DIR @@ -138,6 +142,7 @@ export __INIT_TOOLS_RESTORE_ARGS="$__INIT_TOOLS_RESTORE_ARGS --disable-parallel" DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 toolsLocalPath="$REPOROOT/build_tools" bootStrapperPath="$toolsLocalPath/bootstrap.sh" +dotnetInstallPath="$toolsLocalPath/dotnet-install.sh" if [ ! -f $bootStrapperPath ]; then if [ ! -d $toolsLocalPath ]; then mkdir $toolsLocalPath @@ -146,13 +151,21 @@ if [ ! -f $bootStrapperPath ]; then chmod u+x $bootStrapperPath fi -$bootStrapperPath --repositoryRoot "$REPOROOT" --toolsLocalPath "$toolsLocalPath" --cliInstallPath $DOTNET_INSTALL_DIR --architecture $ARCHITECTURE > bootstrap.log +$bootStrapperPath --repositoryRoot "$REPOROOT" --toolsLocalPath "$toolsLocalPath" --cliInstallPath $DOTNET_INSTALL_DIR_PJ --architecture $ARCHITECTURE > bootstrap.log if [ $? != 0 ]; then echo "run-build: Error: Boot-strapping failed with exit code $?, see bootstrap.log for more information." >&2 exit $? fi +# now execute the script +echo "installing CLI: $dotnetInstallPath --version \"latest\" --install-dir $DOTNET_INSTALL_DIR --architecture \"$ARCHITECTURE\"" +$dotnetInstallPath --version "latest" --install-dir $DOTNET_INSTALL_DIR --architecture "$ARCHITECTURE" +if [ $? != 0 ]; then + echo "run-build: Error: Boot-strapping post-PJ stage0 with exit code $?." >&2 + exit $? +fi + # Put stage 0 on the PATH (for this shell only) PATH="$DOTNET_INSTALL_DIR:$PATH" diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs index c8ad0e772..d20542db1 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/RepoDirectoriesProvider.cs @@ -73,7 +73,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private string GetPjDotnetPath() { - return new DirectoryInfo(Path.Combine(RepoRoot, ".dotnet_stage0")) + return new DirectoryInfo(Path.Combine(RepoRoot, ".dotnet_stage0PJ")) .GetDirectories().First() .GetFiles("dotnet*").First() .FullName;