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:
David Fowler 2015-10-18 01:17:13 -07:00
parent 586dbde67f
commit cce7949a5a
11 changed files with 173 additions and 29 deletions

View file

@ -34,6 +34,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dnxhost", "dnxhost", "{0773
scripts\dnxhost\dotnet-publish.cmd = scripts\dnxhost\dotnet-publish.cmd
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Tools.Compiler.Csc", "src\Microsoft.DotNet.Tools.Compiler.Csc\Microsoft.DotNet.Tools.Compiler.Csc.xproj", "{B559378C-FC03-45FA-893C-71784F28E0A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -60,6 +62,10 @@ Global
{303677D5-7312-4C3F-BAEE-BEB1A9BD9FE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{303677D5-7312-4C3F-BAEE-BEB1A9BD9FE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{303677D5-7312-4C3F-BAEE-BEB1A9BD9FE6}.Release|Any CPU.Build.0 = Release|Any CPU
{B559378C-FC03-45FA-893C-71784F28E0A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B559378C-FC03-45FA-893C-71784F28E0A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B559378C-FC03-45FA-893C-71784F28E0A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B559378C-FC03-45FA-893C-71784F28E0A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -71,5 +77,6 @@ Global
{391D6AD6-0FD5-4E1E-A4C8-6B5439D197B5} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{303677D5-7312-4C3F-BAEE-BEB1A9BD9FE6} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{07731125-77D7-4B83-B7B2-C865C6B8A6E8} = {13F8C30C-1011-459C-82B2-0ACDD73EDA18}
{B559378C-FC03-45FA-893C-71784F28E0A2} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
EndGlobalSection
EndGlobal

View file

@ -49,6 +49,7 @@ dnu restore "$REPOROOT" --runtime osx.10.10-x64 --runtime ubuntu.14.04-x64 --run
echo "Building basic dotnet tools using Stage 0 (DNX hosted)"
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli"
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler"
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"
# Add stage1 to the path and use it to build stage2
@ -57,4 +58,5 @@ export PATH=$STAGE1_DIR:$PATH
echo "Building stage2 dotnet using stage1 ..."
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE2_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE2_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE2_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE2_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"

View file

@ -51,6 +51,10 @@ echo Building stage1 dotnet-compile.exe ...
dotnet-publish --framework dnxcore50 --runtime %RID% --output "%STAGE1_DIR%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Compiler"
if errorlevel 1 goto fail
echo Building stage1 dotnet-compile-csc.exe ...
dotnet-publish --framework dnxcore50 --runtime %RID% --output "%STAGE1_DIR%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Compiler.Csc"
if errorlevel 1 goto fail
echo Building stage1 dotnet-publish.exe ...
dotnet-publish --framework dnxcore50 --runtime %RID% --output "%STAGE1_DIR%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Publish"
if errorlevel 1 goto fail
@ -73,6 +77,10 @@ echo Building stage2 dotnet-compile.exe ...
dotnet publish --framework dnxcore50 --runtime %RID% --output "%STAGE2_DIR%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Compiler"
if errorlevel 1 goto fail
echo Building stage2 dotnet-compile-csc.exe ...
dotnet publish --framework dnxcore50 --runtime %RID% --output "%STAGE2_DIR%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Compiler.Csc"
if errorlevel 1 goto fail
echo Building stage2 dotnet-publish.exe ...
dotnet publish --framework dnxcore50 --runtime %RID% --output "%STAGE2_DIR%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Publish"
if errorlevel 1 goto fail

View file

@ -4,6 +4,9 @@
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet": "Microsoft.DotNet.Cli"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>b559378c-fc03-45fa-893c-71784f28e0a2</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Tools.Compiler.Csc</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,52 @@
using System;
using System.IO;
using Microsoft.Dnx.Runtime.Common.CommandLine;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Tools.Compiler.Csc
{
public class Program
{
public static void Main(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
var app = new CommandLineApplication();
app.Name = "dotnet compile csc";
app.FullName = "CSharp compiler";
app.Description = "CSharp Compiler for the .NET Platform";
app.HelpOption("-h|--help");
var responseFileArg = app.Argument("<CONFIG>", "The response file to pass to the compiler.");
app.OnExecute(() =>
{
// Execute CSC!
var result = RunCsc($"-noconfig @\"{responseFileArg.Value}\"")
.ForwardStdErr()
.ForwardStdOut()
.RunAsync()
.Result;
return result.ExitCode;
});
app.Execute(args);
}
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);
}
}
}

View file

@ -0,0 +1,23 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft.DotNet.Tools.Compiler.Csc")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.DotNet.Tools.Compiler.Csc")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b559378c-fc03-45fa-893c-71784f28e0a2")]

View file

@ -0,0 +1,33 @@
{
"name": "dotnet-compile-csc",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet-compile-csc": "Microsoft.DotNet.Tools.Compiler.Csc"
},
"dependencies": {
"Microsoft.NETCore.TestHost": "1.0.0-*",
"Microsoft.NETCore.Runtime": "1.0.1-*",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",
"System.Diagnostics.Process": "4.1.0-*",
"System.IO.FileSystem": "4.0.1-*",
"Microsoft.Extensions.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Extensions.CommandLineUtils.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Net.Compilers.netcore": "1.1.0-*"
},
"frameworks": {
"dnxcore50": { }
}
}

View file

@ -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}");

View file

@ -4,6 +4,9 @@
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet-compile": "Microsoft.DotNet.Tools.Compiler"
},
"dependencies": {
"Microsoft.NETCore.TestHost": "1.0.0-*",
"Microsoft.NETCore.Runtime": "1.0.1-*",

View file

@ -4,6 +4,9 @@
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet-publish": "Microsoft.DotNet.Tools.Publish"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",
"System.Console": "4.0.0-*",