Merge pull request #1208 from AustinWise/intrinsicInvoke

Invoke intrinsic commands directly instead of creating a process.
This commit is contained in:
David Fowler 2016-02-04 11:10:16 -08:00
commit d1b8eb9967
6 changed files with 28 additions and 55 deletions

View file

@ -281,12 +281,9 @@ namespace Microsoft.DotNet.Tools.Build
args.Add(_args.ConfigValue); args.Add(_args.ConfigValue);
args.Add(projectDependency.Project.ProjectDirectory); args.Add(projectDependency.Project.ProjectDirectory);
var compileResult = Command.CreateDotNet("compile", args) var compileResult = CommpileCommand.Run(args.ToArray());
.ForwardStdOut()
.ForwardStdErr()
.Execute();
return compileResult.ExitCode == 0; return compileResult == 0;
} }
private bool InvokeCompileOnRootProject() private bool InvokeCompileOnRootProject()
@ -339,12 +336,9 @@ namespace Microsoft.DotNet.Tools.Build
args.Add(_rootProject.ProjectDirectory); args.Add(_rootProject.ProjectDirectory);
var compileResult = Command.CreateDotNet("compile", args) var compileResult = CommpileCommand.Run(args.ToArray());
.ForwardStdOut()
.ForwardStdErr()
.Execute();
var succeeded = compileResult.ExitCode == 0; var succeeded = compileResult == 0;
if (succeeded) if (succeeded)
{ {

View file

@ -147,12 +147,9 @@ namespace Microsoft.DotNet.Tools.Compiler
// Need CoreRT Framework published to nuget // Need CoreRT Framework published to nuget
// Do Native Compilation // Do Native Compilation
var result = Command.CreateDotNet("compile-native", new string[] { "--rsp", $"{rsp}" }) var result = Native.CompileNativeCommand.Run(new string[] { "--rsp", $"{rsp}" });
.ForwardStdErr()
.ForwardStdOut()
.Execute();
return result.ExitCode == 0; return result == 0;
} }
private static bool CompileProject(ProjectContext context, CompilerCommandApp args) private static bool CompileProject(ProjectContext context, CompilerCommandApp args)
@ -378,13 +375,9 @@ namespace Microsoft.DotNet.Tools.Compiler
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen-resx.rsp"); var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen-resx.rsp");
File.WriteAllLines(rsp, arguments); File.WriteAllLines(rsp, arguments);
var result = var result = Resgen.ResgenCommand.Run(new[] { $"@{rsp}" });
Command.CreateDotNet("resgen", new[] { $"@{rsp}" })
.ForwardStdErr()
.ForwardStdOut()
.Execute();
if (result.ExitCode != 0) if (result != 0)
{ {
return false; return false;
} }
@ -429,11 +422,8 @@ namespace Microsoft.DotNet.Tools.Compiler
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen.rsp"); var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen.rsp");
File.WriteAllLines(rsp, arguments); File.WriteAllLines(rsp, arguments);
var result = Command.CreateDotNet("resgen", new[] { $"@{rsp}" }) var result = Resgen.ResgenCommand.Run(new[] { $"@{rsp}" });
.ForwardStdErr() if (result != 0)
.ForwardStdOut()
.Execute();
if (result.ExitCode != 0)
{ {
return false; return false;
} }

View file

@ -58,12 +58,9 @@ namespace Microsoft.DotNet.Tools.Pack
argsBuilder.Add($"{_project.ProjectFilePath}"); argsBuilder.Add($"{_project.ProjectFilePath}");
var result = Command.CreateDotNet("build", argsBuilder) var result = Build.BuildCommand.Run(argsBuilder.ToArray());
.ForwardStdOut()
.ForwardStdErr()
.Execute();
return result.ExitCode; return result;
} }
return 0; return 0;

View file

@ -106,7 +106,7 @@ namespace Microsoft.DotNet.Tools.Publish
} }
// Compile the project (and transitively, all it's dependencies) // Compile the project (and transitively, all it's dependencies)
var result = Command.CreateDotNet("build", var result = Build.BuildCommand.Run(
new string[] { new string[] {
"--framework", "--framework",
$"{context.TargetFramework.DotNetFrameworkName}", $"{context.TargetFramework.DotNetFrameworkName}",
@ -115,12 +115,9 @@ namespace Microsoft.DotNet.Tools.Publish
"--configuration", "--configuration",
configuration, configuration,
context.ProjectFile.ProjectDirectory context.ProjectFile.ProjectDirectory
}) });
.ForwardStdErr()
.ForwardStdOut()
.Execute();
if (result.ExitCode != 0) if (result != 0)
{ {
return false; return false;
} }

View file

@ -52,14 +52,14 @@ namespace Microsoft.DotNet.Tools.Repl.Csi
return context; return context;
} }
private static CommandResult CompileProject(ProjectContext projectContext, string configuration, out string tempOutputDir) private static int CompileProject(ProjectContext projectContext, string configuration, out string tempOutputDir)
{ {
tempOutputDir = Path.Combine(projectContext.ProjectDirectory, "bin", ".dotnetrepl", Guid.NewGuid().ToString("N")); tempOutputDir = Path.Combine(projectContext.ProjectDirectory, "bin", ".dotnetrepl", Guid.NewGuid().ToString("N"));
Reporter.Output.WriteLine($"Compiling {projectContext.RootProject.Identity.Name.Yellow()} for {projectContext.TargetFramework.DotNetFrameworkName.Yellow()} to use with the {"C# REPL".Yellow()} environment."); Reporter.Output.WriteLine($"Compiling {projectContext.RootProject.Identity.Name.Yellow()} for {projectContext.TargetFramework.DotNetFrameworkName.Yellow()} to use with the {"C# REPL".Yellow()} environment.");
// --temp-output is actually the intermediate output folder and can be the same as --output for our temporary compilation (`dotnet run` can be seen doing the same) // --temp-output is actually the intermediate output folder and can be the same as --output for our temporary compilation (`dotnet run` can be seen doing the same)
return Command.CreateDotNet($"build", new [] return Build.BuildCommand.Run(new[]
{ {
$"--output", $"--output",
$"{tempOutputDir}", $"{tempOutputDir}",
@ -70,10 +70,7 @@ namespace Microsoft.DotNet.Tools.Repl.Csi
$"--configuration", $"--configuration",
$"{configuration}", $"{configuration}",
$"{projectContext.ProjectDirectory}" $"{projectContext.ProjectDirectory}"
}) });
.ForwardStdOut(onlyIfVerbose: true)
.ForwardStdErr()
.Execute();
} }
private static IEnumerable<string> GetRuntimeDependencies(ProjectContext projectContext, string buildConfiguration) private static IEnumerable<string> GetRuntimeDependencies(ProjectContext projectContext, string buildConfiguration)
@ -151,10 +148,10 @@ namespace Microsoft.DotNet.Tools.Repl.Csi
var compileResult = CompileProject(projectContext, buildConfiguration, out tempOutputDir); var compileResult = CompileProject(projectContext, buildConfiguration, out tempOutputDir);
if (compileResult.ExitCode != 0) if (compileResult != 0)
{ {
Reporter.Error.WriteLine($"Project compilation failed. Exiting REPL".Red()); Reporter.Error.WriteLine($"Project compilation failed. Exiting REPL".Red());
return compileResult.ExitCode; return compileResult;
} }
string responseFile = CreateResponseFile(projectContext, buildConfiguration, tempOutputDir); string responseFile = CreateResponseFile(projectContext, buildConfiguration, tempOutputDir);

View file

@ -90,7 +90,7 @@ namespace Microsoft.DotNet.Tools.Run
var tempDir = Path.Combine(_context.ProjectDirectory, "bin", ".dotnetrun", Guid.NewGuid().ToString("N")); var tempDir = Path.Combine(_context.ProjectDirectory, "bin", ".dotnetrun", Guid.NewGuid().ToString("N"));
// Compile to that directory // Compile to that directory
var result = Command.CreateDotNet($"build", new [] var result = Build.BuildCommand.Run(new[]
{ {
$"--output", $"--output",
$"{tempDir}", $"{tempDir}",
@ -101,14 +101,11 @@ namespace Microsoft.DotNet.Tools.Run
$"--configuration", $"--configuration",
$"{Configuration}", $"{Configuration}",
$"{_context.ProjectFile.ProjectDirectory}" $"{_context.ProjectFile.ProjectDirectory}"
}) });
.ForwardStdOut(onlyIfVerbose: true)
.ForwardStdErr()
.Execute();
if (result.ExitCode != 0) if (result != 0)
{ {
return result.ExitCode; return result;
} }
// Now launch the output and give it the results // Now launch the output and give it the results
@ -149,7 +146,8 @@ namespace Microsoft.DotNet.Tools.Run
.ForwardStdOut() .ForwardStdOut()
.ForwardStdErr() .ForwardStdErr()
.EnvironmentVariable("DOTNET_HOME", dotnetHome) .EnvironmentVariable("DOTNET_HOME", dotnetHome)
.Execute(); .Execute()
.ExitCode;
// Clean up // Clean up
if (!PreserveTemporary) if (!PreserveTemporary)
@ -157,7 +155,7 @@ namespace Microsoft.DotNet.Tools.Run
Directory.Delete(tempDir, recursive: true); Directory.Delete(tempDir, recursive: true);
} }
return result.ExitCode; return result;
} }
private static int RunInteractive(string scriptName) private static int RunInteractive(string scriptName)