From 413cf152ae3e4ff03da600a884677e36203c84a0 Mon Sep 17 00:00:00 2001 From: Austin Wise Date: Wed, 3 Feb 2016 12:04:09 -0800 Subject: [PATCH] Invoke intrinsic commands directly instead of creating a process. --- .../commands/dotnet-build/CompileContext.cs | 16 +++++--------- src/dotnet/commands/dotnet-compile/Program.cs | 22 +++++-------------- .../dotnet-pack/BuildProjectCommand.cs | 7 ++---- .../commands/dotnet-publish/PublishCommand.cs | 9 +++----- .../commands/dotnet-repl-csi/Program.cs | 13 +++++------ src/dotnet/commands/dotnet-run/RunCommand.cs | 16 ++++++-------- 6 files changed, 28 insertions(+), 55 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/CompileContext.cs b/src/dotnet/commands/dotnet-build/CompileContext.cs index 14262c07f..8086ac62d 100644 --- a/src/dotnet/commands/dotnet-build/CompileContext.cs +++ b/src/dotnet/commands/dotnet-build/CompileContext.cs @@ -280,13 +280,10 @@ namespace Microsoft.DotNet.Tools.Build args.Add("--configuration"); args.Add(_args.ConfigValue); args.Add(projectDependency.Project.ProjectDirectory); - - var compileResult = Command.CreateDotNet("compile", args) - .ForwardStdOut() - .ForwardStdErr() - .Execute(); - return compileResult.ExitCode == 0; + var compileResult = CommpileCommand.Run(args.ToArray()); + + return compileResult == 0; } private bool InvokeCompileOnRootProject() @@ -339,12 +336,9 @@ namespace Microsoft.DotNet.Tools.Build args.Add(_rootProject.ProjectDirectory); - var compileResult = Command.CreateDotNet("compile", args) - .ForwardStdOut() - .ForwardStdErr() - .Execute(); + var compileResult = CommpileCommand.Run(args.ToArray()); - var succeeded = compileResult.ExitCode == 0; + var succeeded = compileResult == 0; if (succeeded) { diff --git a/src/dotnet/commands/dotnet-compile/Program.cs b/src/dotnet/commands/dotnet-compile/Program.cs index f2eaf014b..ac7d4516d 100644 --- a/src/dotnet/commands/dotnet-compile/Program.cs +++ b/src/dotnet/commands/dotnet-compile/Program.cs @@ -147,12 +147,9 @@ namespace Microsoft.DotNet.Tools.Compiler // Need CoreRT Framework published to nuget // Do Native Compilation - var result = Command.CreateDotNet("compile-native", new string[] { "--rsp", $"{rsp}" }) - .ForwardStdErr() - .ForwardStdOut() - .Execute(); + var result = Native.CompileNativeCommand.Run(new string[] { "--rsp", $"{rsp}" }); - return result.ExitCode == 0; + return result == 0; } 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"); File.WriteAllLines(rsp, arguments); - var result = - Command.CreateDotNet("resgen", new[] { $"@{rsp}" }) - .ForwardStdErr() - .ForwardStdOut() - .Execute(); + var result = Resgen.ResgenCommand.Run(new[] { $"@{rsp}" }); - if (result.ExitCode != 0) + if (result != 0) { return false; } @@ -429,11 +422,8 @@ namespace Microsoft.DotNet.Tools.Compiler var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen.rsp"); File.WriteAllLines(rsp, arguments); - var result = Command.CreateDotNet("resgen", new[] { $"@{rsp}" }) - .ForwardStdErr() - .ForwardStdOut() - .Execute(); - if (result.ExitCode != 0) + var result = Resgen.ResgenCommand.Run(new[] { $"@{rsp}" }); + if (result != 0) { return false; } diff --git a/src/dotnet/commands/dotnet-pack/BuildProjectCommand.cs b/src/dotnet/commands/dotnet-pack/BuildProjectCommand.cs index d14f07f16..e461b425e 100644 --- a/src/dotnet/commands/dotnet-pack/BuildProjectCommand.cs +++ b/src/dotnet/commands/dotnet-pack/BuildProjectCommand.cs @@ -58,12 +58,9 @@ namespace Microsoft.DotNet.Tools.Pack argsBuilder.Add($"{_project.ProjectFilePath}"); - var result = Command.CreateDotNet("build", argsBuilder) - .ForwardStdOut() - .ForwardStdErr() - .Execute(); + var result = Build.BuildCommand.Run(argsBuilder.ToArray()); - return result.ExitCode; + return result; } return 0; diff --git a/src/dotnet/commands/dotnet-publish/PublishCommand.cs b/src/dotnet/commands/dotnet-publish/PublishCommand.cs index 25ae7b2c2..4089e7133 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommand.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommand.cs @@ -106,7 +106,7 @@ namespace Microsoft.DotNet.Tools.Publish } // Compile the project (and transitively, all it's dependencies) - var result = Command.CreateDotNet("build", + var result = Build.BuildCommand.Run( new string[] { "--framework", $"{context.TargetFramework.DotNetFrameworkName}", @@ -115,12 +115,9 @@ namespace Microsoft.DotNet.Tools.Publish "--configuration", configuration, context.ProjectFile.ProjectDirectory - }) - .ForwardStdErr() - .ForwardStdOut() - .Execute(); + }); - if (result.ExitCode != 0) + if (result != 0) { return false; } diff --git a/src/dotnet/commands/dotnet-repl-csi/Program.cs b/src/dotnet/commands/dotnet-repl-csi/Program.cs index 5375b0c0d..5fd0d169d 100644 --- a/src/dotnet/commands/dotnet-repl-csi/Program.cs +++ b/src/dotnet/commands/dotnet-repl-csi/Program.cs @@ -52,14 +52,14 @@ namespace Microsoft.DotNet.Tools.Repl.Csi 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")); 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) - return Command.CreateDotNet($"build", new [] + return Build.BuildCommand.Run(new[] { $"--output", $"{tempOutputDir}", @@ -70,10 +70,7 @@ namespace Microsoft.DotNet.Tools.Repl.Csi $"--configuration", $"{configuration}", $"{projectContext.ProjectDirectory}" - }) - .ForwardStdOut(onlyIfVerbose: true) - .ForwardStdErr() - .Execute(); + }); } private static IEnumerable GetRuntimeDependencies(ProjectContext projectContext, string buildConfiguration) @@ -151,10 +148,10 @@ namespace Microsoft.DotNet.Tools.Repl.Csi var compileResult = CompileProject(projectContext, buildConfiguration, out tempOutputDir); - if (compileResult.ExitCode != 0) + if (compileResult != 0) { Reporter.Error.WriteLine($"Project compilation failed. Exiting REPL".Red()); - return compileResult.ExitCode; + return compileResult; } string responseFile = CreateResponseFile(projectContext, buildConfiguration, tempOutputDir); diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 30c819712..23987bdba 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -90,7 +90,7 @@ namespace Microsoft.DotNet.Tools.Run var tempDir = Path.Combine(_context.ProjectDirectory, "bin", ".dotnetrun", Guid.NewGuid().ToString("N")); // Compile to that directory - var result = Command.CreateDotNet($"build", new [] + var result = Build.BuildCommand.Run(new[] { $"--output", $"{tempDir}", @@ -101,14 +101,11 @@ namespace Microsoft.DotNet.Tools.Run $"--configuration", $"{Configuration}", $"{_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 @@ -149,7 +146,8 @@ namespace Microsoft.DotNet.Tools.Run .ForwardStdOut() .ForwardStdErr() .EnvironmentVariable("DOTNET_HOME", dotnetHome) - .Execute(); + .Execute() + .ExitCode; // Clean up if (!PreserveTemporary) @@ -157,7 +155,7 @@ namespace Microsoft.DotNet.Tools.Run Directory.Delete(tempDir, recursive: true); } - return result.ExitCode; + return result; } private static int RunInteractive(string scriptName)