Skip to content

Commit 05df7a5

Browse files
committed
Add rsp support. #6
1 parent ebfb878 commit 05df7a5

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

core/IncrementalCompiler/CompileOptions.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Runtime.Serialization;
5+
using Microsoft.CodeAnalysis;
56

67
namespace IncrementalCompiler
78
{
@@ -89,14 +90,18 @@ public void ParseArgument(string[] args)
8990
}
9091
else if (arg.StartsWith("@"))
9192
{
92-
// more options in specified file
93-
var lines = File.ReadAllLines(arg.Substring(1));
94-
ParseArgument(lines);
93+
var subArgs = new List<string>();
94+
foreach (var line in File.ReadAllLines(arg.Substring(1)))
95+
{
96+
subArgs.AddRange(CommandLineParser.SplitCommandLineIntoArguments(line, removeHashComments: true));
97+
}
98+
ParseArgument(subArgs.ToArray());
9599
}
96100
else
97101
{
98102
var path = arg.Trim('"');
99-
Files.Add(path);
103+
if (path.Length > 0)
104+
Files.Add(path);
100105
}
101106
}
102107
}

extra/CompilerPlugin/CustomCSharpCompiler.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,11 @@ private string GetCompilerPath(List<string> arguments)
3737
return result;
3838
}
3939

40-
private string GetCompilerPathEx(List<string> arguments)
40+
private string GetUniversalCompilerPath()
4141
{
4242
var basePath = Path.Combine(Directory.GetCurrentDirectory(), "Compiler");
4343
var compilerPath = Path.Combine(basePath, "UniversalCompiler.exe");
44-
if (File.Exists(compilerPath))
45-
{
46-
return compilerPath;
47-
}
48-
49-
Debug.LogWarning($"Custom C# compiler not found in project directory ({compilerPath}), using the default compiler");
50-
return GetCompilerPath(arguments);
44+
return File.Exists(compilerPath) ? compilerPath : null;
5145
}
5246

5347
// Copy of MonoCSharpCompiler.StartCompiler()
@@ -61,9 +55,6 @@ protected override Program StartCompiler()
6155
"-target:library",
6256
"-nowarn:0169",
6357
"-out:" + PrepareFileName(_island._output),
64-
"-unsafe",
65-
"-define:__UNITY_PROCESSID__" + System.Diagnostics.Process.GetCurrentProcess().Id,
66-
"-define:__UNITY_PROFILE__" + Path.GetFileName(base.GetProfileDirectory()).Replace(".", "_")
6758
};
6859
foreach (var reference in _island._references)
6960
{
@@ -90,6 +81,23 @@ protected override Program StartCompiler()
9081
}
9182
}
9283

93-
return StartCompiler(_island._target, GetCompilerPathEx(arguments), arguments);
84+
var universalCompilerPath = GetUniversalCompilerPath();
85+
if (universalCompilerPath != null)
86+
{
87+
// use universal compiler.
88+
var defaultCompilerName = Path.GetFileNameWithoutExtension(GetCompilerPath(arguments));
89+
arguments.Add("-define:__UNITY_PROCESSID__" + System.Diagnostics.Process.GetCurrentProcess().Id);
90+
arguments.Add("-define:__UNITY_PROFILE__" + Path.GetFileName(base.GetProfileDirectory()).Replace(".", "_"));
91+
var rspFileName = "Assets/" + defaultCompilerName + ".rsp";
92+
if (File.Exists(rspFileName))
93+
arguments.Add("@" + rspFileName);
94+
return StartCompiler(_island._target, universalCompilerPath, arguments);
95+
}
96+
else
97+
{
98+
// fallback to the default compiler.
99+
Debug.LogWarning($"Universal C# compiler not found in project directory. Use the default compiler");
100+
return StartCompiler(_island._target, GetCompilerPath(arguments), arguments);
101+
}
94102
}
95103
}

0 commit comments

Comments
 (0)