Skip to content

Commit 1608239

Browse files
committed
Issue oleg-shilo#203: precompiler/context["CompilerOptions"] doesn't appear to work
1 parent 7e10dac commit 1608239

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

Source/Precompiler.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ namespace csscript
1515
/// </summary>
1616
internal class PrecompilationContext
1717
{
18-
///// <summary>
19-
///// Full path of the script being passed for pre-compilation.
20-
///// </summary>
21-
//public string ScriptFileName;
22-
///// <summary>
23-
///// Flag, which indicates if the script passed for pre-compilation is an entry script (primary script).
24-
///// <para>This field can be used to determine the pre-compilation algorithm based on the entry script. For example
25-
///// generating the <c>static Main()</c> wrapper for classless scripts should be done only for an entry script but not for other included/imported script. </para>
26-
///// </summary>
27-
//public bool IsPrimaryScript = true;
2818
/// <summary>
2919
/// Collection of the referenced assemblies to be added to the process script referenced assemblies.
3020
/// <para>You may want to add new items to the referenced assemblies because of the pre-compilation logic (e.g. some code using assemblies not referenced by the primary script
@@ -51,6 +41,11 @@ internal class PrecompilationContext
5141
/// </summary>
5242
public List<string> NewSearchDirs = new List<string>();
5343

44+
/// <summary>
45+
/// Additional compiler options to be passed to the script compiler
46+
/// </summary>
47+
public string NewCompilerOptions;
48+
5449
/// <summary>
5550
/// Collection of the process assembly and script probing directories.
5651
/// </summary>

Source/Utils.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ internal static PrecompilationContext Precompile(string scriptFile, string[] fil
14141414
contextData["NewSearchDirs"] = context.NewSearchDirs;
14151415
contextData["NewReferences"] = context.NewReferences;
14161416
contextData["NewIncludes"] = context.NewIncludes;
1417+
contextData["NewCompilerOptions"] = "";
14171418
contextData["SearchDirs"] = context.SearchDirs;
14181419
contextData["ConsoleEncoding"] = options.consoleEncoding;
14191420
contextData["CompilerOptions"] = options.compilerOptions;
@@ -1470,6 +1471,7 @@ internal static PrecompilationContext Precompile(string scriptFile, string[] fil
14701471
}
14711472
}
14721473

1474+
context.NewCompilerOptions = (string)contextData["NewCompilerOptions"];
14731475
options.searchDirs = options.searchDirs.ConcatWith(context.NewSearchDirs);
14741476

14751477
foreach (string asm in context.NewReferences)

Source/cscscript/CSScriptLibrary.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/csscript.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,8 +1734,11 @@ string Compile(string scriptFileName)
17341734
context.NewDependencies.AddRange(context.NewIncludes);
17351735
}
17361736

1737+
Utils.AddCompilerOptions(compilerParams, context.NewCompilerOptions);
1738+
17371739
string[] additionalDependencies = context.NewDependencies.ToArray();
17381740

1741+
compilerParams.ReferencedAssemblies.AddRange(context.NewReferences.ToArray());
17391742
AddReferencedAssemblies(compilerParams, scriptFileName, parser);
17401743

17411744
//add resources referenced from code
@@ -1823,8 +1826,6 @@ string Compile(string scriptFileName)
18231826
if (!Directory.Exists(outDir))
18241827
Directory.CreateDirectory(outDir);
18251828

1826-
//compilerParams.ReferencedAssemblies.Add(this.GetType().Assembly.Location);
1827-
18281829
CompilerResults results;
18291830
if (generateExe)
18301831
{

0 commit comments

Comments
 (0)