Make publish do less work

- Added a runtime switch to build and compile
- Flow the runtime from publish through build and compile
This commit is contained in:
David Fowler 2016-01-29 09:21:55 -08:00 committed by Livar Cunha
parent 4e365921f7
commit b16ecff0e9
6 changed files with 48 additions and 48 deletions

View file

@ -23,6 +23,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
public static void MakeCompilationOutputRunnable(this ProjectContext context, string outputPath, string configuration) public static void MakeCompilationOutputRunnable(this ProjectContext context, string outputPath, string configuration)
{ {
// REVIEW: This shouldn't be copied on compile
context context
.ProjectFile .ProjectFile
.Files .Files
@ -34,10 +35,15 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
if (context.TargetFramework.IsDesktop()) if (context.TargetFramework.IsDesktop())
{ {
// On full framework, copy all dependencies to the output path
exporter exporter
.GetDependencies() .GetDependencies()
.SelectMany(e => e.RuntimeAssets()) .SelectMany(e => e.RuntimeAssets())
.CopyTo(outputPath); .CopyTo(outputPath);
// Generate binding redirects
var outputName = context.GetOutputPathCalculator(outputPath).GetAssemblyPath(configuration);
context.GenerateBindingRedirects(exporter, outputName);
} }
else else
{ {
@ -45,10 +51,12 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
.GetDependencies(LibraryType.Package) .GetDependencies(LibraryType.Package)
.WriteDepsTo(Path.Combine(outputPath, context.ProjectFile.Name + FileNameSuffixes.Deps)); .WriteDepsTo(Path.Combine(outputPath, context.ProjectFile.Name + FileNameSuffixes.Deps));
// On core clr, only copy project references
exporter.GetDependencies(LibraryType.Project) exporter.GetDependencies(LibraryType.Project)
.SelectMany(e => e.RuntimeAssets()) .SelectMany(e => e.RuntimeAssets())
.CopyTo(outputPath); .CopyTo(outputPath);
// TODO: Pick a host based on the RID
CoreHost.CopyTo(outputPath, context.ProjectFile.Name + Constants.ExeSuffix); CoreHost.CopyTo(outputPath, context.ProjectFile.Name + Constants.ExeSuffix);
} }
} }

View file

@ -274,15 +274,17 @@ namespace Microsoft.DotNet.Tools.Build
args.Add("--framework"); args.Add("--framework");
args.Add($"{projectDependency.Framework}"); args.Add($"{projectDependency.Framework}");
if (!string.IsNullOrEmpty(_args.RuntimeValue))
{
args.Add("--runtime");
args.Add(_args.RuntimeValue);
}
args.Add("--configuration"); args.Add("--configuration");
args.Add(_args.ConfigValue); args.Add(_args.ConfigValue);
args.Add(projectDependency.Project.ProjectDirectory); args.Add(projectDependency.Project.ProjectDirectory);
if (_args.NoHostValue)
{
args.Add("--no-host");
}
var compileResult = Command.Create("dotnet-compile", args) var compileResult = Command.Create("dotnet-compile", args)
.ForwardStdOut() .ForwardStdOut()
.ForwardStdErr() .ForwardStdErr()
@ -297,6 +299,11 @@ namespace Microsoft.DotNet.Tools.Build
var args = new List<string>(); var args = new List<string>();
args.Add("--framework"); args.Add("--framework");
args.Add(_rootProject.TargetFramework.ToString()); args.Add(_rootProject.TargetFramework.ToString());
if (!string.IsNullOrEmpty(_args.RuntimeValue))
{
args.Add("--runtime");
args.Add(_args.RuntimeValue);
}
args.Add("--configuration"); args.Add("--configuration");
args.Add(_args.ConfigValue); args.Add(_args.ConfigValue);
args.Add("--output"); args.Add("--output");
@ -304,11 +311,6 @@ namespace Microsoft.DotNet.Tools.Build
args.Add("--temp-output"); args.Add("--temp-output");
args.Add(_args.IntermediateValue); args.Add(_args.IntermediateValue);
if (_args.NoHostValue)
{
args.Add("--no-host");
}
//native args //native args
if (_args.IsNativeValue) if (_args.IsNativeValue)
{ {

View file

@ -23,8 +23,8 @@ namespace Microsoft.DotNet.Tools.Compiler
private CommandOption _outputOption; private CommandOption _outputOption;
private CommandOption _intermediateOutputOption; private CommandOption _intermediateOutputOption;
private CommandOption _frameworkOption; private CommandOption _frameworkOption;
private CommandOption _runtimeOption;
private CommandOption _configurationOption; private CommandOption _configurationOption;
private CommandOption _noHostOption;
private CommandArgument _projectArgument; private CommandArgument _projectArgument;
private CommandOption _nativeOption; private CommandOption _nativeOption;
private CommandOption _archOption; private CommandOption _archOption;
@ -39,8 +39,8 @@ namespace Microsoft.DotNet.Tools.Compiler
public string ProjectPathValue { get; set; } public string ProjectPathValue { get; set; }
public string OutputValue { get; set; } public string OutputValue { get; set; }
public string IntermediateValue { get; set; } public string IntermediateValue { get; set; }
public string RuntimeValue{ get; set; }
public string ConfigValue { get; set; } public string ConfigValue { get; set; }
public bool NoHostValue { get; set; }
public bool IsNativeValue { get; set; } public bool IsNativeValue { get; set; }
public string ArchValue { get; set; } public string ArchValue { get; set; }
public string IlcArgsValue { get; set; } public string IlcArgsValue { get; set; }
@ -75,7 +75,7 @@ namespace Microsoft.DotNet.Tools.Compiler
_intermediateOutputOption = _app.Option("-t|--temp-output <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue); _intermediateOutputOption = _app.Option("-t|--temp-output <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue);
_frameworkOption = _app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.MultipleValue); _frameworkOption = _app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.MultipleValue);
_configurationOption = _app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue); _configurationOption = _app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
_noHostOption = _app.Option("--no-host", "Set this to skip publishing a runtime host when building for CoreCLR", CommandOptionType.NoValue); _runtimeOption = _app.Option("-r|--runtime <RUNTIME_IDENTIFIER>", "Target runtime to publish for", CommandOptionType.SingleValue);
_projectArgument = _app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory"); _projectArgument = _app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");
// Native Args // Native Args
@ -103,7 +103,7 @@ namespace Microsoft.DotNet.Tools.Compiler
OutputValue = _outputOption.Value(); OutputValue = _outputOption.Value();
IntermediateValue = _intermediateOutputOption.Value(); IntermediateValue = _intermediateOutputOption.Value();
ConfigValue = _configurationOption.Value() ?? Constants.DefaultConfiguration; ConfigValue = _configurationOption.Value() ?? Constants.DefaultConfiguration;
NoHostValue = _noHostOption.HasValue(); RuntimeValue = _runtimeOption.Value();
IsNativeValue = _nativeOption.HasValue(); IsNativeValue = _nativeOption.HasValue();
ArchValue = _archOption.Value(); ArchValue = _archOption.Value();

View file

@ -10,9 +10,7 @@ using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.ProjectModel.Utilities;
using NuGet.Frameworks;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
@ -318,35 +316,28 @@ namespace Microsoft.DotNet.Tools.Compiler
success &= GenerateCultureResourceAssemblies(context.ProjectFile, dependencies, outputPath); success &= GenerateCultureResourceAssemblies(context.ProjectFile, dependencies, outputPath);
} }
bool generateBindingRedirects = false; if (success)
if (success && !args.NoHostValue && compilationOptions.EmitEntryPoint.GetValueOrDefault())
{ {
generateBindingRedirects = true; // TODO: Make this opt in via another mechanism
var rids = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); var makeRunnable = compilationOptions.EmitEntryPoint.GetValueOrDefault() ||
var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, rids); !string.IsNullOrEmpty(context.ProjectFile.TestRunner);
runtimeContext
.MakeCompilationOutputRunnable(outputPath, args.ConfigValue);
}
else if (!string.IsNullOrEmpty(context.ProjectFile.TestRunner))
{
generateBindingRedirects = true;
var projectContext =
ProjectContext.Create(context.ProjectDirectory, context.TargetFramework,
new[] { PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() });
// Don't generate a deps file if we're on desktop if (makeRunnable)
if (!context.TargetFramework.IsDesktop())
{ {
projectContext var rids = new List<string>();
.CreateExporter(args.ConfigValue) if (string.IsNullOrEmpty(args.RuntimeValue))
.GetDependencies(LibraryType.Package) {
.WriteDepsTo(Path.Combine(outputPath, projectContext.ProjectFile.Name + FileNameSuffixes.Deps)); rids.AddRange(PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers());
} }
} else
{
rids.Add(args.RuntimeValue);
}
if (generateBindingRedirects && context.TargetFramework.IsDesktop()) var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, rids);
{ runtimeContext
context.GenerateBindingRedirects(exporter, outputName); .MakeCompilationOutputRunnable(outputPath, args.ConfigValue);
}
} }
return PrintSummary(diagnostics, sw, success); return PrintSummary(diagnostics, sw, success);

View file

@ -3,10 +3,8 @@
using Microsoft.Dnx.Runtime.Common.CommandLine; using Microsoft.Dnx.Runtime.Common.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using System; using System;
using System.IO; using System.IO;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Publish namespace Microsoft.DotNet.Tools.Publish
{ {

View file

@ -109,10 +109,11 @@ namespace Microsoft.DotNet.Tools.Publish
new string[] { new string[] {
"--framework", "--framework",
$"{context.TargetFramework.DotNetFrameworkName}", $"{context.TargetFramework.DotNetFrameworkName}",
"--runtime",
context.RuntimeIdentifier,
"--configuration", "--configuration",
$"{configuration}", configuration,
"--no-host", context.ProjectFile.ProjectDirectory
$"{context.ProjectFile.ProjectDirectory}"
}) })
.ForwardStdErr() .ForwardStdErr()
.ForwardStdOut() .ForwardStdOut()