From 48cd38cd92fa06782c40754b0aeeba7e1eb4aa0f Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Mon, 30 Nov 2015 12:17:41 -0800 Subject: [PATCH] avoid dropping deps file when publishing also, avoid requiring a dependency on Microsoft.NETCore.Runtime fixes #157 --- scripts/dev-dotnet.ps1 | 14 ++++++++ scripts/dev-dotnet.sh | 26 +++++++++++++++ .../Program.cs | 20 +++++++---- src/Microsoft.DotNet.Tools.Init/project.json | 2 -- src/Microsoft.DotNet.Tools.Publish/Program.cs | 33 ++++++++++++++++++- 5 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 scripts/dev-dotnet.ps1 create mode 100644 scripts/dev-dotnet.sh diff --git a/scripts/dev-dotnet.ps1 b/scripts/dev-dotnet.ps1 new file mode 100644 index 000000000..bd53ad84e --- /dev/null +++ b/scripts/dev-dotnet.ps1 @@ -0,0 +1,14 @@ +$oldPath = $env:PATH +try { + # Put the stage2 output on the front of the path + $stage2 = "$PSScriptRoot\..\artifacts\win7-x64\stage2\bin" + if (Test-Path $stage2) { + $env:PATH="$stage2;$env:PATH" + } else { + Write-Host "You don't have a dev build in the 'artifacts\win7-x64\stage2' folder!" + } + + dotnet @args +} finally { + $env:PATH = $oldPath +} diff --git a/scripts/dev-dotnet.sh b/scripts/dev-dotnet.sh new file mode 100644 index 000000000..12bab2731 --- /dev/null +++ b/scripts/dev-dotnet.sh @@ -0,0 +1,26 @@ +#!/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="$( cd -P "$DIR/.." && pwd )" + +source "$DIR/_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/src/Microsoft.DotNet.Tools.Compiler/Program.cs b/src/Microsoft.DotNet.Tools.Compiler/Program.cs index 326533606..33fdb8fc1 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/Program.cs +++ b/src/Microsoft.DotNet.Tools.Compiler/Program.cs @@ -34,6 +34,7 @@ namespace Microsoft.DotNet.Tools.Compiler var framework = app.Option("-f|--framework ", "Compile a specific framework", CommandOptionType.MultipleValue); var configuration = app.Option("-c|--configuration ", "Configuration under which to build", CommandOptionType.SingleValue); var noProjectDependencies = app.Option("--no-project-dependencies", "Skips building project references.", CommandOptionType.NoValue); + var noHost = app.Option("--no-host", "Set this to skip publishing a runtime host when building for CoreCLR", CommandOptionType.NoValue); var project = app.Argument("", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory"); // Native Args @@ -69,7 +70,7 @@ namespace Microsoft.DotNet.Tools.Compiler ProjectContext.CreateContextForEachFramework(path); foreach (var context in contexts) { - success &= Compile(context, configValue, outputValue, intermediateOutput.Value(), buildProjectReferences); + success &= Compile(context, configValue, outputValue, intermediateOutput.Value(), buildProjectReferences, noHost.HasValue()); if (isNative && success) { success &= CompileNative(context, configValue, outputValue, buildProjectReferences, intermediateValue, archValue, ilcArgsValue, ilcPathValue, isCppMode); @@ -181,7 +182,7 @@ namespace Microsoft.DotNet.Tools.Compiler return result.ExitCode == 0; } - private static bool Compile(ProjectContext context, string configuration, string outputOptionValue, string intermediateOutputValue, bool buildProjectReferences) + private static bool Compile(ProjectContext context, string configuration, string outputOptionValue, string intermediateOutputValue, bool buildProjectReferences, bool noHost) { // Set up Output Paths string outputPath = GetOutputPath(context, configuration, outputOptionValue); @@ -214,7 +215,14 @@ namespace Microsoft.DotNet.Tools.Compiler foreach (var projectDependency in Sort(projects)) { // Skip compiling project dependencies since we've already figured out the build order - var compileResult = Command.Create("dotnet-compile", $"--framework {projectDependency.Framework} --configuration {configuration} --output \"{outputPath}\" --temp-output \"{intermediateOutputPath}\" --no-project-dependencies \"{projectDependency.Project.ProjectDirectory}\"") + var compileResult = Command.Create("dotnet-compile", + $"--framework {projectDependency.Framework} " + + $"--configuration {configuration} " + + $"--output \"{outputPath}\" " + + $"--temp-output \"{intermediateOutputPath}\" " + + "--no-project-dependencies " + + (noHost ? "--no-host " : string.Empty) + + $"\"{projectDependency.Project.ProjectDirectory}\"") .ForwardStdOut() .ForwardStdErr() .Execute(); @@ -228,10 +236,10 @@ namespace Microsoft.DotNet.Tools.Compiler projects.Clear(); } - return CompileProject(context, configuration, outputPath, intermediateOutputPath, dependencies); + return CompileProject(context, configuration, outputPath, intermediateOutputPath, dependencies, noHost); } - private static bool CompileProject(ProjectContext context, string configuration, string outputPath, string intermediateOutputPath, List dependencies) + private static bool CompileProject(ProjectContext context, string configuration, string outputPath, string intermediateOutputPath, List dependencies, bool noHost) { Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}"); var sw = Stopwatch.StartNew(); @@ -361,7 +369,7 @@ namespace Microsoft.DotNet.Tools.Compiler var success = result.ExitCode == 0; - if (success && compilationOptions.EmitEntryPoint.GetValueOrDefault()) + if (success && !noHost && compilationOptions.EmitEntryPoint.GetValueOrDefault()) { var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, new[] { RuntimeIdentifier.Current }); MakeRunnable(runtimeContext, diff --git a/src/Microsoft.DotNet.Tools.Init/project.json b/src/Microsoft.DotNet.Tools.Init/project.json index f3f981350..a2a762b3f 100644 --- a/src/Microsoft.DotNet.Tools.Init/project.json +++ b/src/Microsoft.DotNet.Tools.Init/project.json @@ -5,8 +5,6 @@ "emitEntryPoint": true }, "dependencies": { - "Microsoft.NETCore.Runtime": "1.0.1-beta-23504", - "System.Console": "4.0.0-beta-23504", "System.Collections": "4.0.11-beta-23504", "System.Linq": "4.0.1-beta-23504", diff --git a/src/Microsoft.DotNet.Tools.Publish/Program.cs b/src/Microsoft.DotNet.Tools.Publish/Program.cs index dd08d1a09..c2da80ea0 100644 --- a/src/Microsoft.DotNet.Tools.Publish/Program.cs +++ b/src/Microsoft.DotNet.Tools.Publish/Program.cs @@ -118,7 +118,12 @@ namespace Microsoft.DotNet.Tools.Publish } // Compile the project (and transitively, all it's dependencies) - var result = Command.Create("dotnet-compile", $"--framework \"{context.TargetFramework.DotNetFrameworkName}\" --output \"{outputPath}\" --configuration \"{configuration}\" \"{context.ProjectFile.ProjectDirectory}\"") + var result = Command.Create("dotnet-compile", + $"--framework \"{context.TargetFramework.DotNetFrameworkName}\" " + + $"--output \"{outputPath}\" " + + $"--configuration \"{configuration}\" " + + "--no-host " + + $"\"{context.ProjectFile.ProjectDirectory}\"") .ForwardStdErr() .ForwardStdOut() .Execute(); @@ -170,8 +175,34 @@ namespace Microsoft.DotNet.Tools.Publish // Copy the host File.Copy(hostPath, outputExe, overwrite: true); + + // Publish the runtime + var runtimePath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "runtime", "coreclr")); + if(!Directory.Exists(runtimePath)) + { + Reporter.Error.WriteLine($"Unable to find runtime in expected location: {runtimePath}"); + return 1; + } + Reporter.Verbose.WriteLine($"Publishing runtime from {runtimePath.Cyan()}"); + CopyFolder(runtimePath, outputPath); + return 0; } + + private static void CopyFolder(string sourceFolder, string targetFolder) + { + foreach (var filePath in Directory.EnumerateFiles(sourceFolder)) + { + var fileName = Path.GetFileName(filePath); + File.Copy(filePath, Path.Combine(targetFolder, fileName), overwrite: true); + } + + foreach (var folderPath in Directory.EnumerateDirectories(sourceFolder)) + { + var folderName = new DirectoryInfo(folderPath).Name; + CopyFolder(folderPath, Path.Combine(targetFolder, folderName)); + } + } private static void PublishFiles(IEnumerable files, string outputPath) {