Explorar o código

warn about compilation configuration outside of init macros (#8722)

#7871
Aleksandr Kuzmenko %!s(int64=6) %!d(string=hai) anos
pai
achega
750becb7fe
Modificáronse 2 ficheiros con 20 adicións e 1 borrados
  1. 11 1
      src/macro/macroApi.ml
  2. 9 0
      std/haxe/macro/Compiler.hx

+ 11 - 1
src/macro/macroApi.ml

@@ -1563,8 +1563,14 @@ let macro_api ccom get_api =
 			encode_string (try Common.find_file (ccom()) file with Not_found -> failwith ("File not found '" ^ file ^ "'"))
 		);
 		"define", vfun2 (fun s v ->
+			let s = decode_string s in
+			let com = ccom() in
+			if com.stage <> CInitMacrosStart then begin
+				let v = if v = vnull then "" else ", " ^ (decode_string v) in
+				com.warning ("Should be used in initialization macros only: haxe.macro.Compiler.define(" ^ s ^ v ^ ")") Globals.null_pos;
+			end;
 			let v = if v = vnull then "" else "=" ^ (decode_string v) in
-			Common.raw_define (ccom()) ((decode_string s) ^ v);
+			Common.raw_define com (s ^ v);
 			vnull
 		);
 		"defined", vfun1 (fun s ->
@@ -1824,6 +1830,8 @@ let macro_api ccom get_api =
 		"add_class_path", vfun1 (fun cp ->
 			let com = ccom() in
 			let cp = decode_string cp in
+			if com.stage <> CInitMacrosStart then
+				com.warning ("Should be used in initialization macros only: haxe.macro.Compiler.addClassPath(" ^ cp ^ ")") Globals.null_pos;
 			let cp = Path.add_trailing_slash cp in
 			com.class_path <- cp :: com.class_path;
 			(match com.get_macros() with
@@ -1838,6 +1846,8 @@ let macro_api ccom get_api =
 		"add_native_lib", vfun1 (fun file ->
 			let file = decode_string file in
 			let com = ccom() in
+			if com.stage <> CInitMacrosStart then
+				com.warning ("Should be used in initialization macros only: haxe.macro.Compiler.addNativeLib(" ^ file ^ ")") Globals.null_pos;
 			NativeLibraryHandler.add_native_lib com file false ();
 			vnull
 		);

+ 9 - 0
std/haxe/macro/Compiler.hx

@@ -64,6 +64,8 @@ class Compiler {
 
 	/**
 		Set a conditional compiler flag.
+
+		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 	**/
 	public static function define(flag:String, ?value:String) {
 		#if (neko || eval)
@@ -127,6 +129,11 @@ class Compiler {
 		#end
 	}
 
+	/**
+		Add a class path where ".hx" source files or packages (sub-directories) can be found.
+
+		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
+	**/
 	public static function addClassPath(path:String) {
 		#if (neko || eval)
 		load("add_class_path", 1)(path);
@@ -157,6 +164,8 @@ class Compiler {
 
 	/**
 		Adds a native library depending on the platform (e.g. `-swf-lib` for Flash).
+
+		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 	**/
 	public static function addNativeLib(name:String) {
 		#if (neko || eval)