Changes to dotnet-compile
- Split dotnet-compile into dotnet-compile and dotnet-compile-{compiler} - We still need to figure out the protocol and responsibility but this change adds the needed indirection so that compilers can do their thing. - Updated the bootstrap script and kept the commands since we need them to bootstrap the world until we get updates. #52
This commit is contained in:
parent
586dbde67f
commit
cce7949a5a
11 changed files with 173 additions and 29 deletions
|
@ -150,8 +150,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
||||
var outputName = Path.Combine(outputPath, context.ProjectFile.Name + ".dll");
|
||||
|
||||
// Assemble csc args
|
||||
var cscArgs = new List<string>()
|
||||
// Assemble args
|
||||
var compilerArgs = new List<string>()
|
||||
{
|
||||
// Default suppressions
|
||||
"-nowarn:CS1701",
|
||||
|
@ -163,27 +163,31 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
};
|
||||
|
||||
// Add compilation options to the args
|
||||
ApplyCompilationOptions(compilationOptions, cscArgs);
|
||||
ApplyCompilationOptions(compilationOptions, compilerArgs);
|
||||
|
||||
foreach (var dependency in dependencies)
|
||||
{
|
||||
cscArgs.AddRange(dependency.CompilationAssemblies.Select(r => $"-r:\"{r}\""));
|
||||
cscArgs.AddRange(dependency.SourceReferences);
|
||||
compilerArgs.AddRange(dependency.CompilationAssemblies.Select(r => $"-r:\"{r}\""));
|
||||
compilerArgs.AddRange(dependency.SourceReferences);
|
||||
}
|
||||
|
||||
// Add project source files
|
||||
cscArgs.AddRange(context.ProjectFile.Files.SourceFiles);
|
||||
compilerArgs.AddRange(context.ProjectFile.Files.SourceFiles);
|
||||
|
||||
// TODO: Read this from the project
|
||||
const string compiler = "csc";
|
||||
|
||||
// Write RSP file
|
||||
var rsp = Path.Combine(outputPath, "dotnet-compile.csc.rsp");
|
||||
File.WriteAllLines(rsp, cscArgs);
|
||||
var rsp = Path.Combine(outputPath, $"dotnet-compile.{compiler}.rsp");
|
||||
File.WriteAllLines(rsp, compilerArgs);
|
||||
|
||||
var result = Command.Create("dotnet-compile-csc", $"\"{rsp}\"")
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.RunAsync()
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
// Execute CSC!
|
||||
var result = RunCsc($"-noconfig @\"{rsp}\"")
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.RunAsync()
|
||||
.Result;
|
||||
return result.ExitCode == 0;
|
||||
}
|
||||
|
||||
|
@ -214,23 +218,9 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
outputs.Add(project);
|
||||
}
|
||||
|
||||
private static Command RunCsc(string cscArgs)
|
||||
{
|
||||
// Locate CoreRun
|
||||
string hostRoot = Environment.GetEnvironmentVariable("DOTNET_CSC_PATH");
|
||||
if (string.IsNullOrEmpty(hostRoot))
|
||||
{
|
||||
hostRoot = AppContext.BaseDirectory;
|
||||
}
|
||||
var corerun = Path.Combine(hostRoot, Constants.CoreRunName);
|
||||
var cscExe = Path.Combine(hostRoot, "csc.exe");
|
||||
return File.Exists(corerun) && File.Exists(cscExe)
|
||||
? Command.Create(corerun, $@"""{cscExe}"" {cscArgs}")
|
||||
: Command.Create("csc", cscArgs);
|
||||
}
|
||||
|
||||
private static void ApplyCompilationOptions(CompilerOptions compilationOptions, List<string> cscArgs)
|
||||
{
|
||||
// TODO: Move compilation arguments into the compiler itself
|
||||
var targetType = compilationOptions.EmitEntryPoint.GetValueOrDefault() ? "exe" : "library";
|
||||
|
||||
cscArgs.Add($"-target:{targetType}");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue