Skip to content

Commit 083d551

Browse files
committed
Add external compiler options
1 parent c1d5010 commit 083d551

File tree

7 files changed

+81
-0
lines changed

7 files changed

+81
-0
lines changed

build.fsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Target "Package" (fun _ ->
4444
CreateDir compilerDir
4545
// copy output files
4646
"./core/IncrementalCompiler/bin/Release/IncrementalCompiler.packed.exe" |> CopyFile (compilerDir @@ "IncrementalCompiler.exe")
47+
"./core/IncrementalCompiler/IncrementalCompiler.xml" |> CopyFile compilerDir
4748
"./extra/CompilerPlugin." + target + "/bin/Release/Unity.PureCSharpTests.dll" |> CopyFile (editorDir @@ "CompilerPlugin.dll")
4849
"./extra/UniversalCompiler/bin/Release/UniversalCompiler.exe" |> CopyFile compilerDir
4950
"./tools/pdb2mdb/pdb2mdb.exe" |> CopyFile compilerDir

core/IncrementalCompiler/CompileOptions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55

66
namespace IncrementalCompiler
77
{
8+
public enum DebugSymbolFileType
9+
{
10+
None,
11+
Pdb,
12+
PdbToMdb,
13+
Mdb
14+
}
15+
16+
public enum PrebuiltOutputReuseType
17+
{
18+
None,
19+
WhenNoChange,
20+
WhenNoSourceChange
21+
}
22+
823
[DataContract]
924
public class CompileOptions
1025
{
@@ -14,6 +29,8 @@ public class CompileOptions
1429
[DataMember] public List<string> Defines = new List<string>();
1530
[DataMember] public List<string> References = new List<string>();
1631
[DataMember] public List<string> Files = new List<string>();
32+
[DataMember] public DebugSymbolFileType DebugSymbolFile;
33+
[DataMember] public PrebuiltOutputReuseType PrebuiltOutputReuse;
1734

1835
public void ParseArgument(string[] args)
1936
{

core/IncrementalCompiler/IncrementalCompiler.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="Program.cs" />
7575
<Compile Include="Program.Dev.cs" />
7676
<Compile Include="Properties\AssemblyInfo.cs" />
77+
<Compile Include="Settings.cs" />
7778
</ItemGroup>
7879
<ItemGroup>
7980
<None Include="App.config" />
@@ -89,6 +90,9 @@
8990
<Name>RoslynMdbWriter</Name>
9091
</ProjectReference>
9192
</ItemGroup>
93+
<ItemGroup>
94+
<Content Include="IncrementalCompiler.xml" />
95+
</ItemGroup>
9296
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
9397
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
9498
Other similar extension points exist, see Microsoft.Common.targets.

core/IncrementalCompiler/IncrementalCompiler.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><Settings> <!-- DebugSymbolFile: Type of debugging symbol file. - None : Nothing - Mdb : Create mono debug database (MDB) with embedded RoslynMdbWriter - Pdb : Create program database (PDB) - PdbToMdb : Create MDB file using pdb2mdb tool from generated pdb --> <DebugSymbolFile>Mdb</DebugSymbolFile> <!-- PrebuiltOutputReuse: - None : Alway emit fresh one - WhenNoChange : When nothing changed in sources and references, reuse prebuilt results. - WhenNoSourceChange : When nothing changed in sources and references (except update of some references), reuse prebuilt results. --> <PrebuiltOutputReuse>WhenNoChange</PrebuiltOutputReuse></Settings>

core/IncrementalCompiler/Program.Dev.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static int RunAsDev(string[] args)
1919

2020
var workDirectory = args[1];
2121
var reponseFile = args[2];
22+
var settings = Settings.Load() ?? Settings.Default;
2223

2324
var logger = LogManager.GetLogger("Dev");
2425
logger.Info("Started");
@@ -40,6 +41,8 @@ static int RunAsDev(string[] args)
4041
options.WorkDirectory = curPath;
4142
options.References = options.References.Distinct().ToList();
4243
options.Files = options.Files.Distinct().ToList();
44+
options.DebugSymbolFile = settings.DebugSymbolFile;
45+
options.PrebuiltOutputReuse = settings.PrebuiltOutputReuse;
4346

4447
var parentProcessId = Process.GetCurrentProcess().Id;
4548

core/IncrementalCompiler/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,25 @@ static int RunAsClient(string[] args)
5757
var logger = LogManager.GetLogger("Client");
5858
logger.Info("Started");
5959

60+
Settings settings;
61+
try
62+
{
63+
settings = Settings.Load() ?? Settings.Default;
64+
}
65+
catch (Exception e)
66+
{
67+
logger.Error(e, "Failed in loading settings.");
68+
return 1;
69+
}
70+
6071
var currentPath = Directory.GetCurrentDirectory();
6172
var options = new CompileOptions();
6273
options.ParseArgument(args);
6374
options.WorkDirectory = currentPath;
6475
options.References = options.References.Distinct().ToList();
6576
options.Files = options.Files.Distinct().ToList();
77+
options.DebugSymbolFile = settings.DebugSymbolFile;
78+
options.PrebuiltOutputReuse = settings.PrebuiltOutputReuse;
6679

6780
logger.Info("CurrentDir: {0}", Directory.GetCurrentDirectory());
6881
logger.Info("Output: {0}", options.Output);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.IO;
2+
using System.Reflection;
3+
using System.Xml.Serialization;
4+
5+
namespace IncrementalCompiler
6+
{
7+
public class Settings
8+
{
9+
public DebugSymbolFileType DebugSymbolFile;
10+
public PrebuiltOutputReuseType PrebuiltOutputReuse;
11+
12+
public static Settings Default = new Settings
13+
{
14+
DebugSymbolFile = DebugSymbolFileType.Mdb,
15+
PrebuiltOutputReuse = PrebuiltOutputReuseType.WhenNoChange,
16+
};
17+
18+
public static Settings Load()
19+
{
20+
var fileName = Path.ChangeExtension(Assembly.GetEntryAssembly().Location, ".xml");
21+
if (File.Exists(fileName) == false)
22+
return null;
23+
24+
using (var stream = new FileStream(fileName, FileMode.Open))
25+
{
26+
return Load(stream);
27+
}
28+
}
29+
30+
public static Settings Load(Stream stream)
31+
{
32+
var deserializer = new XmlSerializer(typeof(Settings));
33+
return (Settings)deserializer.Deserialize(stream);
34+
}
35+
36+
public static void Save(Stream stream, Settings settings)
37+
{
38+
var serializer = new XmlSerializer(typeof(Settings));
39+
serializer.Serialize(stream, settings);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)