Skip to content

Commit 43b0575

Browse files
committed
build: update Recompiler (for develop)
1 parent 40f4d57 commit 43b0575

File tree

5 files changed

+26
-46
lines changed

5 files changed

+26
-46
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.CompilerServices;
22

3+
[assembly: InternalsVisibleTo("CSharpCompilerSettings.Recompiler")]
34
[assembly: InternalsVisibleTo("CSharpCompilerSettings.Editor")]
45
[assembly: InternalsVisibleTo("CSharpCompilerSettingsTests")]

Plugins/Recompiler/CSharpCompilerSettings.rsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
/r:"${APP_CONTENTS}/Managed/UnityEngine/UnityEngine.IMGUIModule.dll"
1212
/r:"${APP_CONTENTS}/Managed/UnityEngine/UnityEngine.JSONSerializeModule.dll"
1313
/r:"${APP_CONTENTS}/Managed/UnityEditor.dll"
14-
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/2.0-api/mscorlib.dll"
15-
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/2.0-api/System.dll"
16-
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/2.0-api/System.Core.dll"
14+
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/4.0-api/mscorlib.dll"
15+
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/4.0-api/System.dll"
16+
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/4.0-api/System.Core.dll"
1717

1818
"${PLUGIN_SOURCE}/AssemblyInfo.cs"
1919
"${PLUGIN_SOURCE}/Core.cs"

Plugins/Recompiler/ExternalCSharpCompiler.rsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
/optimize+
88

99
/r:"${APP_CONTENTS}/Managed/UnityEditor.dll"
10-
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/2.0-api/mscorlib.dll"
11-
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/2.0-api/System.dll"
12-
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/2.0-api/System.Core.dll"
10+
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/4.0-api/mscorlib.dll"
11+
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/4.0-api/System.dll"
12+
/r:"${APP_CONTENTS}/MonoBleedingEdge/lib/mono/4.0-api/System.Core.dll"
1313

1414
"${PLUGIN_SOURCE}/ExternalCSharpCompiler.cs"

Plugins/Recompiler/Recompiler.asmdef

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "CSharpCompilerSettings.Recompiler",
3-
"references": [],
3+
"references": [
4+
"CSharpCompilerSettings_"
5+
],
46
"optionalUnityReferences": [],
57
"includePlatforms": [
68
"Editor"

Plugins/Recompiler/Recompiler.cs

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,49 +56,27 @@ public void Compile()
5656
rspPath = "Temp/" + Path.GetFileName(rspPath);
5757
File.WriteAllText(rspPath, rsp);
5858

59-
// Detect csc tool exe.
60-
var mono = Application.platform != RuntimePlatform.WindowsEditor;
61-
var cscToolExe = appContents + "/Tools/RoslynNet46/csc.exe".Replace('/', Path.DirectorySeparatorChar);
62-
if (!File.Exists(cscToolExe))
63-
cscToolExe = appContents + "/Tools/Roslyn/csc.exe".Replace('/', Path.DirectorySeparatorChar);
64-
if (!File.Exists(cscToolExe))
65-
{
66-
cscToolExe = appContents + "/Tools/Roslyn/csc".Replace('/', Path.DirectorySeparatorChar);
67-
mono = false;
68-
}
59+
var compilerInfo = CompilerInfo.GetInstalledInfo("Microsoft.Net.Compilers.Toolset.3.5.0");
6960

70-
// Create compilation process.
71-
var psi = new ProcessStartInfo
72-
{
73-
CreateNoWindow = true,
74-
UseShellExecute = false,
75-
RedirectStandardError = true,
76-
RedirectStandardOutput = true,
77-
};
61+
// Setup recompile process.
62+
var psi = new ProcessStartInfo();
63+
compilerInfo.Setup(psi, rspPath, Application.platform);
7864

79-
if (!mono)
80-
{
81-
psi.FileName = Path.GetFullPath(cscToolExe);
82-
psi.Arguments = "/shared /noconfig @" + rspPath;
83-
}
84-
else
65+
using (var program = Type.GetType("UnityEditor.Utils.Program, UnityEditor").New(psi) as IDisposable)
8566
{
86-
psi.FileName = Path.Combine(appContents, "MonoBleedingEdge/bin/mono");
87-
psi.Arguments = cscToolExe + " /noconfig @" + rspPath;
88-
}
89-
90-
// Start compilation process.
91-
var assemblyName = Path.GetFileName(dllPath);
92-
Debug.LogFormat("<b>Recompile [{0}]: start compilation.</b>\n command = {1} {2}\n", assemblyName, psi.FileName, psi.Arguments);
93-
var p = Process.Start(psi);
94-
p.Exited += (_, __) =>
95-
{
96-
if (p.ExitCode == 0)
67+
// Start recompile.
68+
var assemblyName = Path.GetFileName(dllPath);
69+
Debug.LogFormat("<b>Recompile [{0}]: start compilation.</b>\n command = {1} {2}\n", assemblyName, psi.FileName, psi.Arguments);
70+
program.Call("Start");
71+
program.Call("WaitForExit");
72+
73+
// Check outputs.
74+
var exitCode = (int)program.Get("ExitCode");
75+
if (exitCode == 0)
9776
Debug.LogFormat("<b><color=#22aa22>Recompile [{0}]: success.</color></b>", assemblyName);
9877
else
99-
Debug.LogErrorFormat("<b><color=#aa2222>Recompile [{0}]: failure.</color></b>\n{1}\n\n{2}", assemblyName, p.StandardError.ReadToEnd(), p.StandardOutput.ReadToEnd());
100-
};
101-
p.EnableRaisingEvents = true;
78+
Debug.LogErrorFormat("<b><color=#aa2222>Recompile [{0}]: failure.</color></b>\n{1}", assemblyName, program.Call("GetAllOutput"));
79+
}
10280
}
10381
}
10482

@@ -137,7 +115,6 @@ private static void InitializeOnLoadMethod()
137115

138116
private static void RequestToRecompileIfNeeded(string assemblyPath, CompilerMessage[] messages)
139117
{
140-
Debug.Log(">>>>" + assemblyPath);
141118
// Skip: Compile error.
142119
if (messages.Any(x => x.type == CompilerMessageType.Error)) return;
143120

0 commit comments

Comments
 (0)