diff --git a/src/cscompiler/CSCompiler.hx b/src/cscompiler/CSCompiler.hx index 1b5f629..89fa0eb 100644 --- a/src/cscompiler/CSCompiler.hx +++ b/src/cscompiler/CSCompiler.hx @@ -2,6 +2,9 @@ package cscompiler; #if (macro || cs_runtime) +import sys.io.File; + +import haxe.io.Path; import haxe.macro.Expr; import haxe.macro.Type; @@ -24,6 +27,7 @@ using reflaxe.helpers.TypeHelper; // --- import cscompiler.components.*; +import cscompiler.config.Define; /** The class that manages the generation of the C# code. @@ -126,18 +130,31 @@ namespace Haxe { } /** - Generates the .csproj file. + Adds a .csproj file to the output directory. + + If the Define `no-csproj` is specified, then nothing is added. + + Otherwise, if the Define `csproj` specifies a path to an existing + .csproj file, then that is used. + + Otherwise, a default .csproj is generated. **/ function setupCsProj() { - if(!Context.defined("no-csproj")) { - appendToExtraFile("build.csproj", csProjContent()); + if (D_NoCsproj.isDefined()) { + return; + } + if (!D_Csproj.isDefined()) { + appendToExtraFile("build.csproj", csProjDefaultContent()); + return; } + final path = new Path(Context.resolvePath(D_Csproj.getValue())); + appendToExtraFile('${path.file}.${path.ext}', File.getContent(path.toString())); } /** - Returns the content of the .csproj file. + Returns the default content of the .csproj file. **/ - function csProjContent() { + function csProjDefaultContent() { return StringTools.trim(' diff --git a/src/cscompiler/config/Define.hx b/src/cscompiler/config/Define.hx index 7288cf1..259014d 100644 --- a/src/cscompiler/config/Define.hx +++ b/src/cscompiler/config/Define.hx @@ -5,21 +5,41 @@ package cscompiler.config; import reflaxe.helpers.Context; // same as haxe.macro.Context /** - Lists all the custom defines available for configuring Reflaxe/C#. + Lists all the custom defines available for configuring Reflaxe/C#. **/ @:using(cscompiler.config.Define.DefineTools) enum abstract Define(String) from String to String { + /** + -D csproj=[path to file] + + When set, the csproj at the specified path will be used for C# + instead of an auto-generated csproj. + + This will be ignored when the `Define` `no-csproj` is set. + **/ + var D_Csproj = "csproj"; + /** -D namespace_style=[default|pascal] - Default value: `default` + Default value: `default` Determines how namespace names are generated for C#. - If set to `pascal`, snake-case package names are converted - to pascal-case C# namespaces. + If set to `pascal`, snake-case package names are converted + to pascal-case C# namespaces. **/ var D_NamespaceStyle = "namespace_style"; + + /** + -D no-csproj + + When set, a csproj file will not be generated C#. + + This also applies to any csproj file specified with + the Define `csproj`. + **/ + var D_NoCsproj = "no-csproj"; } /** diff --git a/test/tests/Define_Csproj/.gitignore b/test/tests/Define_Csproj/.gitignore new file mode 100644 index 0000000..c7b2fe3 --- /dev/null +++ b/test/tests/Define_Csproj/.gitignore @@ -0,0 +1,5 @@ +build +out +out-legacy-cs +intended/bin +intended/obj \ No newline at end of file diff --git a/test/tests/Define_Csproj/Main.hx b/test/tests/Define_Csproj/Main.hx new file mode 100644 index 0000000..ca7bfd1 --- /dev/null +++ b/test/tests/Define_Csproj/Main.hx @@ -0,0 +1,3 @@ +package; + +function main() { } diff --git a/test/tests/Define_Csproj/Test.csproj b/test/tests/Define_Csproj/Test.csproj new file mode 100644 index 0000000..cd91238 --- /dev/null +++ b/test/tests/Define_Csproj/Test.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + Haxe.HaxeBoot + + diff --git a/test/tests/Define_Csproj/Test_Specified.hxml b/test/tests/Define_Csproj/Test_Specified.hxml new file mode 100644 index 0000000..d08f598 --- /dev/null +++ b/test/tests/Define_Csproj/Test_Specified.hxml @@ -0,0 +1,6 @@ +# The following are added automatically: +# -lib csharp +# --custom-target rcs=out + +-main Main +-D csproj=Test.csproj diff --git a/test/tests/Define_Csproj/Test_Unspecified.hxml b/test/tests/Define_Csproj/Test_Unspecified.hxml new file mode 100644 index 0000000..72c04fb --- /dev/null +++ b/test/tests/Define_Csproj/Test_Unspecified.hxml @@ -0,0 +1,5 @@ +# The following are added automatically: +# -lib csharp +# --custom-target rcs=out + +-main Main diff --git a/test/tests/Define_Csproj/intended/Test_Specified/HaxeBoot.cs b/test/tests/Define_Csproj/intended/Test_Specified/HaxeBoot.cs new file mode 100644 index 0000000..cb57d9e --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Specified/HaxeBoot.cs @@ -0,0 +1,7 @@ +namespace Haxe { + class HaxeBoot { + static void Main(string[] args) { + haxe.root.Main_Fields_.main(); + } + } +} \ No newline at end of file diff --git a/test/tests/Define_Csproj/intended/Test_Specified/Main.cs b/test/tests/Define_Csproj/intended/Test_Specified/Main.cs new file mode 100644 index 0000000..498b39a --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Specified/Main.cs @@ -0,0 +1,7 @@ +namespace haxe.root { + class Main_Fields_ { + public static void main() { + + } + } +} diff --git a/test/tests/Define_Csproj/intended/Test_Specified/Test.csproj b/test/tests/Define_Csproj/intended/Test_Specified/Test.csproj new file mode 100644 index 0000000..cd91238 --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Specified/Test.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + Haxe.HaxeBoot + + diff --git a/test/tests/Define_Csproj/intended/Test_Specified/_GeneratedFiles.txt b/test/tests/Define_Csproj/intended/Test_Specified/_GeneratedFiles.txt new file mode 100644 index 0000000..d0a9a3f --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Specified/_GeneratedFiles.txt @@ -0,0 +1,3 @@ +Main.cs +Test.csproj +HaxeBoot.cs \ No newline at end of file diff --git a/test/tests/Define_Csproj/intended/Test_Unspecified/HaxeBoot.cs b/test/tests/Define_Csproj/intended/Test_Unspecified/HaxeBoot.cs new file mode 100644 index 0000000..cb57d9e --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Unspecified/HaxeBoot.cs @@ -0,0 +1,7 @@ +namespace Haxe { + class HaxeBoot { + static void Main(string[] args) { + haxe.root.Main_Fields_.main(); + } + } +} \ No newline at end of file diff --git a/test/tests/Define_Csproj/intended/Test_Unspecified/Main.cs b/test/tests/Define_Csproj/intended/Test_Unspecified/Main.cs new file mode 100644 index 0000000..498b39a --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Unspecified/Main.cs @@ -0,0 +1,7 @@ +namespace haxe.root { + class Main_Fields_ { + public static void main() { + + } + } +} diff --git a/test/tests/Define_Csproj/intended/Test_Unspecified/_GeneratedFiles.txt b/test/tests/Define_Csproj/intended/Test_Unspecified/_GeneratedFiles.txt new file mode 100644 index 0000000..45e3506 --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Unspecified/_GeneratedFiles.txt @@ -0,0 +1,3 @@ +Main.cs +build.csproj +HaxeBoot.cs \ No newline at end of file diff --git a/test/tests/Define_Csproj/intended/Test_Unspecified/build.csproj b/test/tests/Define_Csproj/intended/Test_Unspecified/build.csproj new file mode 100644 index 0000000..88c3bc5 --- /dev/null +++ b/test/tests/Define_Csproj/intended/Test_Unspecified/build.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + enable + enable + Haxe.HaxeBoot + + + \ No newline at end of file