define cosntants for csharp parse options.
This commit is contained in:
@@ -16,6 +16,8 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
class CsScriptBase : AssemblyLoadContext
|
class CsScriptBase : AssemblyLoadContext
|
||||||
{
|
{
|
||||||
|
public static readonly List<string> PreprocessingSymbols = new List<string>();
|
||||||
|
|
||||||
public const string NET_ONE_TIME_SCRIPT_ASSEMBLY = "NetOneTimeScriptAssembly";
|
public const string NET_ONE_TIME_SCRIPT_ASSEMBLY = "NetOneTimeScriptAssembly";
|
||||||
public const string NET_SCRIPT_ASSEMBLY = "NetScriptAssembly";
|
public const string NET_SCRIPT_ASSEMBLY = "NetScriptAssembly";
|
||||||
|
|
||||||
@@ -27,6 +29,15 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public CsScriptBase() : base(isCollectible: true) { }
|
public CsScriptBase() : base(isCollectible: true) { }
|
||||||
|
|
||||||
|
static CsScriptBase()
|
||||||
|
{
|
||||||
|
#if SERVER
|
||||||
|
PreprocessingSymbols.Add("SERVER");
|
||||||
|
#else
|
||||||
|
PreprocessingSymbols.Add("CLIENT");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public static SyntaxTree AssemblyInfoSyntaxTree(string asmName = null)
|
public static SyntaxTree AssemblyInfoSyntaxTree(string asmName = null)
|
||||||
{
|
{
|
||||||
Revision[asmName] = (int)Revision[asmName] + 1;
|
Revision[asmName] = (int)Revision[asmName] + 1;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
foreach (var file in src)
|
foreach (var file in src)
|
||||||
{
|
{
|
||||||
var tree = SyntaxFactory.ParseSyntaxTree(File.ReadAllText(file), CSharpParseOptions.Default, file);
|
var tree = SyntaxFactory.ParseSyntaxTree(File.ReadAllText(file), CSharpParseOptions.Default.WithPreprocessorSymbols(PreprocessingSymbols), file);
|
||||||
var error = CsScriptFilter.FilterSyntaxTree(tree as CSharpSyntaxTree); // Check file content for prohibited stuff
|
var error = CsScriptFilter.FilterSyntaxTree(tree as CSharpSyntaxTree); // Check file content for prohibited stuff
|
||||||
if (error != null) throw new Exception(error);
|
if (error != null) throw new Exception(error);
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace Barotrauma
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
code = ToOneTimeScript(code);
|
code = ToOneTimeScript(code);
|
||||||
var syntaxTree = SyntaxFactory.ParseSyntaxTree(code, CSharpParseOptions.Default);
|
var syntaxTree = SyntaxFactory.ParseSyntaxTree(code, CSharpParseOptions.Default.WithPreprocessorSymbols(PreprocessingSymbols));
|
||||||
var compilation = CSharpCompilation.Create(NET_ONE_TIME_SCRIPT_ASSEMBLY, new[] { AssemblyInfoSyntaxTree(NET_ONE_TIME_SCRIPT_ASSEMBLY), syntaxTree }, defaultReferences, compileOptions);
|
var compilation = CSharpCompilation.Create(NET_ONE_TIME_SCRIPT_ASSEMBLY, new[] { AssemblyInfoSyntaxTree(NET_ONE_TIME_SCRIPT_ASSEMBLY), syntaxTree }, defaultReferences, compileOptions);
|
||||||
|
|
||||||
Assembly assembly = null;
|
Assembly assembly = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user