Use runtime context only where we require it

This commit is contained in:
Pavel Krymets 2016-02-16 08:42:00 -08:00
parent 9c7ec89392
commit 9fb99526a1
6 changed files with 63 additions and 36 deletions

View file

@ -83,7 +83,7 @@ namespace Microsoft.DotNet.ProjectModel
.WithRuntimeIdentifiers(runtimeIdentifiers)
.Build();
}
/// <summary>
/// Creates a project context for each framework located in the project at <paramref name="projectPath"/>
/// </summary>
@ -122,6 +122,19 @@ namespace Microsoft.DotNet.ProjectModel
.BuildAllTargets();
}
/// <summary>
/// Creates a project context based on existing context but using runtime target
/// </summary>
/// <param name="context"></param>
/// <param name="runtimeIdentifiers"></param>
/// <returns></returns>
public ProjectContext CreateRuntimeContext(IEnumerable<string> runtimeIdentifiers)
{
return Create(ProjectFile.ProjectFilePath, TargetFramework, runtimeIdentifiers);
}
public OutputPaths GetOutputPaths(string configuration, string buidBasePath = null, string outputPath = null)
{
return OutputPathsCalculator.GetOutputPaths(ProjectFile,

View file

@ -97,7 +97,7 @@ namespace Microsoft.DotNet.Tools.Build
private bool NeedsRebuilding(ProjectContext project, ProjectDependenciesFacade dependencies)
{
var compilerIO = GetCompileIO(project, _args.ConfigValue, _args.BuildBasePathValue, _args.OutputValue, dependencies, project == _rootProject);
var compilerIO = GetCompileIO(project, dependencies);
// rebuild if empty inputs / outputs
if (!(compilerIO.Outputs.Any() && compilerIO.Inputs.Any()))
@ -290,6 +290,12 @@ namespace Microsoft.DotNet.Tools.Build
args.Add(_args.ConfigValue);
args.Add(projectDependency.Project.ProjectDirectory);
if (!string.IsNullOrWhiteSpace(_args.RuntimeValue))
{
args.Add("--runtime");
args.Add(_args.RuntimeValue);
}
if (!string.IsNullOrWhiteSpace(_args.BuildBasePathValue))
{
args.Add("--build-base-path");
@ -310,6 +316,12 @@ namespace Microsoft.DotNet.Tools.Build
args.Add("--configuration");
args.Add(_args.ConfigValue);
if (!string.IsNullOrWhiteSpace(_args.RuntimeValue))
{
args.Add("--runtime");
args.Add(_args.RuntimeValue);
}
if (!string.IsNullOrEmpty(_args.OutputValue))
{
args.Add("--output");
@ -400,12 +412,13 @@ namespace Microsoft.DotNet.Tools.Build
private void MakeRunnable()
{
var outputPaths = _rootProject.GetOutputPaths(_args.ConfigValue, _args.BuildBasePathValue, _args.OutputValue);
var libraryExporter = _rootProject.CreateExporter(_args.ConfigValue, _args.BuildBasePathValue);
var executable = new Executable(_rootProject, outputPaths, libraryExporter);
var runtimeContext = _rootProject.CreateRuntimeContext(_args.GetRuntimes());
var outputPaths = runtimeContext.GetOutputPaths(_args.ConfigValue, _args.BuildBasePathValue, _args.OutputValue);
var libraryExporter = runtimeContext.CreateExporter(_args.ConfigValue, _args.BuildBasePathValue);
var executable = new Executable(runtimeContext, outputPaths, libraryExporter);
executable.MakeCompilationOutputRunnable();
PatchMscorlibNextToCoreClr(_rootProject, _args.ConfigValue);
PatchMscorlibNextToCoreClr(runtimeContext, _args.ConfigValue);
}
// Workaround: CoreCLR packaging doesn't include side by side mscorlib, so copy it at build
@ -475,8 +488,13 @@ namespace Microsoft.DotNet.Tools.Build
// computes all the inputs and outputs that would be used in the compilation of a project
// ensures that all paths are files
// ensures no missing inputs
public static CompilerIO GetCompileIO(ProjectContext project, string buildConfiguration, string buildBasePath, string outputPath, ProjectDependenciesFacade dependencies, bool isRootProject)
public CompilerIO GetCompileIO(ProjectContext project, ProjectDependenciesFacade dependencies)
{
var buildConfiguration = _args.ConfigValue;
var buildBasePath = _args.BuildBasePathValue;
var outputPath = _args.OutputValue;
var isRootProject = project == _rootProject;
var compilerIO = new CompilerIO(new List<string>(), new List<string>());
var calculator = project.GetOutputPaths(buildConfiguration, buildBasePath, outputPath);
var binariesOutputPath = calculator.CompilationOutputPath;
@ -497,7 +515,8 @@ namespace Microsoft.DotNet.Tools.Build
var allOutputPath = new List<string>(calculator.CompilationFiles.All());
if (isRootProject && project.ProjectFile.HasRuntimeOutput(buildConfiguration))
{
allOutputPath.AddRange(calculator.RuntimeFiles.All());
var runtimeContext = project.CreateRuntimeContext(_args.GetRuntimes());
allOutputPath.AddRange(runtimeContext.GetOutputPaths(buildConfiguration, buildBasePath, outputPath).RuntimeFiles.All());
}
// output: compiler outputs
foreach (var path in allOutputPath)

View file

@ -26,7 +26,8 @@ namespace Microsoft.DotNet.Tools.Compiler
success &= _managedCompiler.Compile(context, args);
if (args.IsNativeValue && success)
{
success &= _nativeCompiler.Compile(context, args);
var runtimeContext = context.CreateRuntimeContext(args.GetRuntimes());
success &= _nativeCompiler.Compile(runtimeContext, args);
}
}

View file

@ -116,22 +116,12 @@ namespace Microsoft.DotNet.Tools.Compiler
IsCppModeValue = _cppModeOption.HasValue();
CppCompilerFlagsValue = _cppCompilerFlagsOption.Value();
var rids = new List<string>();
if (string.IsNullOrEmpty(RuntimeValue))
{
rids.AddRange(PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers());
}
else
{
rids.Add(RuntimeValue);
}
IEnumerable<ProjectContext> contexts;
if (_frameworkOption.HasValue())
{
contexts = _frameworkOption.Values
.Select(f => ProjectContext.Create(ProjectPathValue, NuGetFramework.Parse(f), rids));
.Select(f => ProjectContext.Create(ProjectPathValue, NuGetFramework.Parse(f)));
}
else
{
@ -141,7 +131,7 @@ namespace Microsoft.DotNet.Tools.Compiler
}
else
{
contexts = ProjectContext.CreateContextForEachFramework(ProjectPathValue, settings: null, runtimeIdentifiers: rids);
contexts = ProjectContext.CreateContextForEachFramework(ProjectPathValue, settings: null);
}
}
@ -169,5 +159,18 @@ namespace Microsoft.DotNet.Tools.Compiler
return baseClassOptions.TryGetValue(optionTemplate, out option) && option.HasValue();
}
public IEnumerable<string> GetRuntimes()
{
var rids = new List<string>();
if (string.IsNullOrEmpty(RuntimeValue))
{
return PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers();
}
else
{
return new [] { RuntimeValue };
}
}
}
}

View file

@ -143,11 +143,14 @@ namespace Microsoft.DotNet.Tools.Compiler
{ "compile:ResponseFile", rsp }
};
if (!string.IsNullOrEmpty(context.RuntimeIdentifier))
if (context.ProjectFile.HasRuntimeOutput(args.ConfigValue))
{
var runtimeContext = context.CreateRuntimeContext(args.GetRuntimes());
var runtimeOutputPath = runtimeContext.GetOutputPaths(args.ConfigValue, args.BuildBasePathValue, args.OutputValue);
contextVariables.Add(
"compile:RuntimeOutputDir",
outputPaths.RuntimeOutputPath.TrimEnd('\\', '/'));
runtimeOutputPath.RuntimeOutputPath.TrimEnd('\\', '/'));
}
_scriptRunner.RunScripts(context, ScriptNames.PreCompile, contextVariables);

View file

@ -67,12 +67,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
_fixture.PreCompileScriptVariables["compile:ResponseFile"].Should().Be(ScriptVariablesFixture.ResponseFile);
}
[Fact]
public void It_does_not_pass_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_not_set_in()
{
_fixture.PreCompileScriptVariables.Should().NotContainKey("compile:RuntimeOutputDir");
}
[Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_set_in_the_ProjectContext()
{
@ -132,12 +126,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
_fixture.PostCompileScriptVariables["compile:CompilerExitCode"].Should().Be("0");
}
[Fact]
public void It_does_not_pass_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_not_set_in_the_ProjectContext()
{
_fixture.PostCompileScriptVariables.Should().NotContainKey("compile:RuntimeOutputDir");
}
[Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_set_in_the_ProjectContext()
{