Skip to content

Commit 84bde54

Browse files
committed
Update extra tools from alexzzzz's code (1.6.1)
1 parent 910545b commit 84bde54

File tree

16 files changed

+456
-331
lines changed

16 files changed

+456
-331
lines changed

build.fsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Target "Build" (fun _ ->
2929
)
3030

3131
Target "Package" (fun _ ->
32-
// pack IncrementalCompiler.exe with dependent module dlls to ics.exe
32+
// pack IncrementalCompiler.exe with dependent module dlls to packed one
3333
let errorCode = Shell.Exec("./packages/ILRepack/tools/ILRepack.exe",
34-
"/wildcards /out:ics.exe IncrementalCompiler.exe *.dll",
34+
"/wildcards /out:IncrementalCompiler.packed.exe IncrementalCompiler.exe *.dll",
3535
"./core/IncrementalCompiler/bin/Release")
3636
// let's make package
3737
for target in ["Unity4"; "Unity5"] do
@@ -43,9 +43,9 @@ Target "Package" (fun _ ->
4343
CreateDir editorDir
4444
CreateDir compilerDir
4545
// copy output files
46-
"./core/IncrementalCompiler/bin/Release/ics.exe" |> CopyFile compilerDir
46+
"./core/IncrementalCompiler/bin/Release/IncrementalCompiler.packed.exe" |> CopyFile (compilerDir @@ "IncrementalCompiler.exe")
4747
"./extra/CompilerPlugin." + target + "/bin/Release/Unity.PureCSharpTests.dll" |> CopyFile (editorDir @@ "CompilerPlugin.dll")
48-
"./extra/UniversalCompiler/bin/Release/smcs.exe" |> CopyFile compilerDir
48+
"./extra/UniversalCompiler/bin/Release/UniversalCompiler.exe" |> CopyFile compilerDir
4949
"./tools/pdb2mdb/pdb2mdb.exe" |> CopyFile compilerDir
5050
// create zipped packages
5151
!! (targetDir @@ "**") |> Zip targetDir (binDir @@ "IncrementalCompiler." + target + ".zip")

core/IncrementalCompiler/@repack.bat

Lines changed: 0 additions & 2 deletions
This file was deleted.

core/IncrementalCompiler/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
// You can specify all the values or you can default the Build and Revision Numbers
3030
// by using the '*' as shown below:
3131
// [assembly: AssemblyVersion("1.0.*")]
32-
[assembly: AssemblyVersion("1.0.0")]
33-
[assembly: AssemblyFileVersion("1.0.0")]
32+
[assembly: AssemblyVersion("1.1.0")]
33+
[assembly: AssemblyFileVersion("1.1.0")]

extra/CompilerPlugin/CustomCSharpCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public CustomCSharpCompiler(MonoIsland island, bool runUpdater) : base(island, r
2222
private string GetCompilerPath(List<string> arguments)
2323
{
2424
var basePath = Path.Combine(Directory.GetCurrentDirectory(), "Compiler");
25-
var compilerPath = Path.Combine(basePath, "smcs.exe");
25+
var compilerPath = Path.Combine(basePath, "UniversalCompiler.exe");
2626
if (File.Exists(compilerPath))
2727
{
2828
return compilerPath;

extra/CompilerPlugin/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
[assembly: AssemblyConfiguration("")]
1414
[assembly: AssemblyCompany("Saladbowl Creative")]
1515
[assembly: AssemblyProduct("Unity3D.IncrementalCompiler")]
16-
[assembly: AssemblyCopyright("Copyright © Saladbowl Creative 2016")]
1716

1817
// Setting ComVisible to false makes the types in this assembly not visible
1918
// to COM components. If you need to access a type in this assembly from
@@ -33,5 +32,5 @@
3332
// You can specify all the values or you can default the Build and Revision Numbers
3433
// by using the '*' as shown below:
3534
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("1.0.0")]
37-
[assembly: AssemblyFileVersion("1.0.0")]
35+
[assembly: AssemblyVersion("1.1.0")]
36+
[assembly: AssemblyFileVersion("1.1.0")]
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
7+
internal abstract class Compiler
8+
{
9+
protected enum ProcessRuntime
10+
{
11+
CLR40,
12+
CLR20,
13+
}
14+
15+
public abstract string Name { get; }
16+
public virtual bool NeedsPdb2MdbConversion => false;
17+
18+
protected readonly Logger logger;
19+
protected readonly string compilerPath;
20+
protected readonly string pbd2MdbPath;
21+
22+
protected readonly List<string> outputLines = new List<string>();
23+
protected readonly List<string> errorLines = new List<string>();
24+
25+
protected Compiler(Logger logger, string compilerPath, string pbd2MdbPath = null)
26+
{
27+
this.logger = logger;
28+
this.compilerPath = compilerPath;
29+
this.pbd2MdbPath = pbd2MdbPath;
30+
}
31+
32+
public int Compile(Platform platform, string unityEditorDataDir, string responseFile)
33+
{
34+
var process = CreateCompilerProcess(platform, unityEditorDataDir, responseFile);
35+
process.OutputDataReceived += (sender, e) => outputLines.Add(e.Data);
36+
process.ErrorDataReceived += (sender, e) => errorLines.Add(e.Data);
37+
38+
logger?.Append($"Process: {process.StartInfo.FileName}");
39+
logger?.Append($"Arguments: {process.StartInfo.Arguments}");
40+
41+
process.Start();
42+
process.BeginOutputReadLine();
43+
process.BeginErrorReadLine();
44+
process.WaitForExit();
45+
logger?.Append($"Exit code: {process.ExitCode}");
46+
47+
return process.ExitCode;
48+
}
49+
50+
public virtual void PrintCompilerOutputAndErrors()
51+
{
52+
var lines = (from line in outputLines
53+
let trimmedLine = line?.Trim()
54+
where string.IsNullOrEmpty(trimmedLine) == false
55+
select trimmedLine).ToList();
56+
57+
logger?.Append($"- Compiler output ({lines.Count} {(lines.Count == 1 ? "line" : "lines")}):");
58+
59+
for (int i = 0; i < lines.Count; i++)
60+
{
61+
Console.Out.WriteLine(lines[i]);
62+
logger?.Append($"{i}: {lines[i]}");
63+
}
64+
65+
lines = (from line in errorLines
66+
let trimmedLine = line?.Trim()
67+
where string.IsNullOrEmpty(trimmedLine) == false
68+
select trimmedLine).ToList();
69+
70+
logger?.Append("");
71+
logger?.Append($"- Compiler errors ({lines.Count} {(lines.Count == 1 ? "line" : "lines")}):");
72+
73+
for (int i = 0; i < lines.Count; i++)
74+
{
75+
Console.Error.WriteLine(lines[i]);
76+
logger?.Append($"{i}: {lines[i]}");
77+
}
78+
}
79+
80+
protected abstract Process CreateCompilerProcess(Platform platform, string unityEditorDataDir, string responseFile);
81+
82+
public virtual void ConvertDebugSymbols(Platform platform, string libraryPath, string unityEditorDataDir) { }
83+
84+
protected static ProcessStartInfo CreateOSDependentStartInfo(Platform platform, ProcessRuntime processRuntime, string processPath, string processArguments,
85+
string unityEditorDataDir)
86+
{
87+
ProcessStartInfo startInfo;
88+
89+
if (platform == Platform.Windows)
90+
{
91+
switch (processRuntime)
92+
{
93+
case ProcessRuntime.CLR20:
94+
var runtimePath = Path.Combine(unityEditorDataDir, @"Mono/bin/mono.exe");
95+
startInfo = new ProcessStartInfo(runtimePath, $"\"{processPath}\" {processArguments}");
96+
break;
97+
98+
case ProcessRuntime.CLR40:
99+
startInfo = new ProcessStartInfo(processPath, processArguments);
100+
break;
101+
102+
default:
103+
throw new ArgumentOutOfRangeException(nameof(processRuntime), processRuntime, null);
104+
}
105+
}
106+
else
107+
{
108+
string runtimePath;
109+
switch (processRuntime)
110+
{
111+
case ProcessRuntime.CLR40:
112+
if (File.Exists("/usr/local/bin/mono"))
113+
{
114+
runtimePath = "/usr/local/bin/mono";
115+
}
116+
else
117+
{
118+
runtimePath = Path.Combine(unityEditorDataDir, "MonoBleedingEdge/bin/mono");
119+
}
120+
break;
121+
122+
case ProcessRuntime.CLR20:
123+
runtimePath = Path.Combine(unityEditorDataDir, @"Mono/bin/mono");
124+
break;
125+
126+
default:
127+
throw new ArgumentOutOfRangeException(nameof(processRuntime), processRuntime, null);
128+
}
129+
130+
startInfo = new ProcessStartInfo(runtimePath, $"\"{processPath}\" {processArguments}");
131+
132+
if (processRuntime != ProcessRuntime.CLR20)
133+
{
134+
// Since we already are running under old mono runtime, we need to remove
135+
// these variables before launching the different version of the runtime.
136+
var vars = startInfo.EnvironmentVariables;
137+
vars.Remove("MONO_PATH");
138+
vars.Remove("MONO_CFG_DIR");
139+
}
140+
}
141+
142+
startInfo.RedirectStandardError = true;
143+
startInfo.RedirectStandardOutput = true;
144+
startInfo.UseShellExecute = false;
145+
146+
return startInfo;
147+
}
148+
149+
public virtual void PrintPdb2MdbOutputAndErrors()
150+
{
151+
throw new NotSupportedException();
152+
}
153+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Linq;
5+
6+
internal class Incremental60Compiler : Compiler
7+
{
8+
public override string Name => "Incremental C# Compiler C# 6.0";
9+
public override bool NeedsPdb2MdbConversion => true;
10+
11+
public Incremental60Compiler(Logger logger, string directory)
12+
: base(logger, Path.Combine(directory, "IncrementalCompiler.exe"), Path.Combine(directory, "pdb2mdb.exe")) { }
13+
14+
public static bool IsAvailable(string directory) => File.Exists(Path.Combine(directory, "IncrementalCompiler.exe")) &&
15+
File.Exists(Path.Combine(directory, "pdb2mdb.exe"));
16+
17+
protected override Process CreateCompilerProcess(Platform platform, string unityEditorDataDir, string responseFile)
18+
{
19+
var systemDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.dll");
20+
var systemCoreDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Core.dll");
21+
var systemXmlDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Xml.dll");
22+
var mscorlibDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/mscorlib.dll");
23+
24+
string processArguments = "-nostdlib+ -noconfig "
25+
+ $"-r:\"{mscorlibDllPath}\" "
26+
+ $"-r:\"{systemDllPath}\" "
27+
+ $"-r:\"{systemCoreDllPath}\" "
28+
+ $"-r:\"{systemXmlDllPath}\" " + responseFile;
29+
30+
var process = new Process();
31+
process.StartInfo = CreateOSDependentStartInfo(platform, ProcessRuntime.CLR40, compilerPath, processArguments, unityEditorDataDir);
32+
return process;
33+
}
34+
35+
public override void ConvertDebugSymbols(Platform platform, string libraryPath, string unityEditorDataDir)
36+
{
37+
outputLines.Clear();
38+
39+
var process = new Process();
40+
process.StartInfo = CreateOSDependentStartInfo(platform, ProcessRuntime.CLR40, pbd2MdbPath, libraryPath, unityEditorDataDir);
41+
process.OutputDataReceived += (sender, e) => outputLines.Add(e.Data);
42+
43+
logger?.Append($"Process: {process.StartInfo.FileName}");
44+
logger?.Append($"Arguments: {process.StartInfo.Arguments}");
45+
46+
process.Start();
47+
process.BeginOutputReadLine();
48+
process.WaitForExit();
49+
logger?.Append($"Exit code: {process.ExitCode}");
50+
51+
var pdbPath = Path.Combine("Temp", Path.GetFileNameWithoutExtension(libraryPath) + ".pdb");
52+
File.Delete(pdbPath);
53+
}
54+
55+
public override void PrintPdb2MdbOutputAndErrors()
56+
{
57+
var lines = (from line in outputLines
58+
let trimmedLine = line?.Trim()
59+
where string.IsNullOrEmpty(trimmedLine) == false
60+
select trimmedLine).ToList();
61+
62+
logger?.Append($"- pdb2mdb.exe output ({lines.Count} {(lines.Count == 1 ? "line" : "lines")}):");
63+
64+
for (int i = 0; i < lines.Count; i++)
65+
{
66+
Console.Out.WriteLine(lines[i]);
67+
logger?.Append($"{i}: {lines[i]}");
68+
}
69+
}
70+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Linq;
5+
6+
internal class Microsoft60Compiler : Compiler
7+
{
8+
public override string Name => "Microsoft C# 6.0";
9+
public override bool NeedsPdb2MdbConversion => true;
10+
11+
public Microsoft60Compiler(Logger logger, string directory)
12+
: base(logger, Path.Combine(directory, "csc.exe"), Path.Combine(directory, "pdb2mdb.exe")) { }
13+
14+
public static bool IsAvailable(string directory) => File.Exists(Path.Combine(directory, "csc.exe")) &&
15+
File.Exists(Path.Combine(directory, "pdb2mdb.exe"));
16+
17+
protected override Process CreateCompilerProcess(Platform platform, string unityEditorDataDir, string responseFile)
18+
{
19+
var systemDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.dll");
20+
var systemCoreDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Core.dll");
21+
var systemXmlDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Xml.dll");
22+
var mscorlibDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/mscorlib.dll");
23+
24+
string processArguments = "-nostdlib+ -noconfig "
25+
+ $"-r:\"{mscorlibDllPath}\" "
26+
+ $"-r:\"{systemDllPath}\" "
27+
+ $"-r:\"{systemCoreDllPath}\" "
28+
+ $"-r:\"{systemXmlDllPath}\" " + responseFile;
29+
30+
var process = new Process();
31+
process.StartInfo = CreateOSDependentStartInfo(platform, ProcessRuntime.CLR40, compilerPath, processArguments, unityEditorDataDir);
32+
return process;
33+
}
34+
35+
public override void ConvertDebugSymbols(Platform platform, string libraryPath, string unityEditorDataDir)
36+
{
37+
outputLines.Clear();
38+
39+
var process = new Process();
40+
process.StartInfo = CreateOSDependentStartInfo(platform, ProcessRuntime.CLR40, pbd2MdbPath, libraryPath, unityEditorDataDir);
41+
process.OutputDataReceived += (sender, e) => outputLines.Add(e.Data);
42+
43+
logger?.Append($"Process: {process.StartInfo.FileName}");
44+
logger?.Append($"Arguments: {process.StartInfo.Arguments}");
45+
46+
process.Start();
47+
process.BeginOutputReadLine();
48+
process.WaitForExit();
49+
logger?.Append($"Exit code: {process.ExitCode}");
50+
51+
var pdbPath = Path.Combine("Temp", Path.GetFileNameWithoutExtension(libraryPath) + ".pdb");
52+
File.Delete(pdbPath);
53+
}
54+
55+
public override void PrintCompilerOutputAndErrors()
56+
{
57+
// Microsoft's compiler writes all warnings and errors to the standard output channel,
58+
// so move them to the error channel skipping first 3 lines that are just part of the header.
59+
60+
while (outputLines.Count > 3)
61+
{
62+
var line = outputLines[3];
63+
outputLines.RemoveAt(3);
64+
errorLines.Add(line);
65+
}
66+
67+
base.PrintCompilerOutputAndErrors();
68+
}
69+
70+
public override void PrintPdb2MdbOutputAndErrors()
71+
{
72+
var lines = (from line in outputLines
73+
let trimmedLine = line?.Trim()
74+
where string.IsNullOrEmpty(trimmedLine) == false
75+
select trimmedLine).ToList();
76+
77+
logger?.Append($"- pdb2mdb.exe output ({lines.Count} {(lines.Count == 1 ? "line" : "lines")}):");
78+
79+
for (int i = 0; i < lines.Count; i++)
80+
{
81+
Console.Out.WriteLine(lines[i]);
82+
logger?.Append($"{i}: {lines[i]}");
83+
}
84+
}
85+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Diagnostics;
2+
3+
internal class Mono30Compiler : Compiler
4+
{
5+
public Mono30Compiler(Logger logger, string compilerPath) : base(logger, compilerPath, null) { }
6+
public override string Name => "Mono C# 3.0";
7+
8+
protected override Process CreateCompilerProcess(Platform platform, string unityEditorDataDir, string responseFile)
9+
{
10+
var process = new Process();
11+
process.StartInfo = CreateOSDependentStartInfo(platform, ProcessRuntime.CLR20, compilerPath, responseFile, unityEditorDataDir);
12+
return process;
13+
}
14+
}

0 commit comments

Comments
 (0)