Main.hx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #if macro
  2. import haxe.macro.Compiler;
  3. import haxe.macro.Context;
  4. #end
  5. function main() {
  6. trace("Hello world!");
  7. }
  8. #if macro
  9. function setupHxTestTarget() {
  10. printTargetName("--macro");
  11. // Check that output is available by --macro phase.
  12. // Good place for "custom target" to ensure output path is valid early on (file vs folder).
  13. switch(Compiler.getOutput()) {
  14. case "": Sys.println("no output");
  15. case o: Sys.println("output: " + o);
  16. }
  17. Context.onGenerate(onGenerate);
  18. }
  19. // Ensure custom target can be detected.
  20. function printTargetName(phase) {
  21. Sys.println('[$phase] Target name: ' + (switch(Compiler.getConfiguration().platform) {
  22. case CustomTarget(name): name;
  23. case _: "Not custom target";
  24. }));
  25. }
  26. // Where "custom target" files would be generated.
  27. function onGenerate(types: Array<haxe.macro.Type>) {
  28. printTargetName("Generate");
  29. // Make sure the config has not been overwritten since Init.init().
  30. final intended = Std.string(hxtest.Init.intendedConfig);
  31. final currentConfig = Std.string(Compiler.getConfiguration().platformConfig);
  32. Sys.println("[Generate] Config correct: " + (intended == currentConfig));
  33. }
  34. #end