Browse Source

Resolve non platform specific file before hitting cache (#11017)

* Resolve non platform specific file before hitting cache

* Add test

* Fix test output
Rudy Ges 2 years ago
parent
commit
58e0b880ed

+ 11 - 1
src/compiler/server.ml

@@ -156,6 +156,15 @@ module Communication = struct
 		loop 0 "";
 		List.rev !lines
 
+	let resolve_file ctx f =
+			let ext = Common.extension f in
+			let second_ext = Common.extension (Common.remove_extension f) in
+			let platform_ext = "." ^ (platform_name_macro ctx) in
+			if platform_ext = second_ext then
+				(Common.remove_extension (Common.remove_extension f)) ^ ext
+			else
+				f
+
 	let compiler_pretty_message_string ctx ectx cm =
 		match cm.cm_message with
 		(* Filter some messages that don't add much when using this message renderer *)
@@ -171,8 +180,9 @@ module Communication = struct
 					let epos = if is_unknown_file cm.cm_pos.pfile then "(unknown position)" else cm.cm_pos.pfile in
 					(-1, -1, -1, -1, epos, [])
 				end else begin
+					let f = resolve_file ctx.com cm.cm_pos.pfile in
 					let f =
-						try Common.find_file ctx.com cm.cm_pos.pfile
+						try Common.find_file ctx.com f
 						with Not_found -> failwith ("File not found '" ^ cm.cm_pos.pfile ^ "'")
 						in
 

+ 10 - 10
src/context/common.ml

@@ -1020,19 +1020,19 @@ let platform ctx p = ctx.platform = p
 let platform_name_macro com =
 	if defined com Define.Macro then "macro" else platform_name com.platform
 
+let remove_extension file =
+	try String.sub file 0 (String.rindex file '.')
+	with Not_found -> file
+
+let extension file =
+	try
+		let dot_pos = String.rindex file '.' in
+		String.sub file dot_pos (String.length file - dot_pos)
+	with Not_found -> file
+
 let cache_directory ctx class_path dir f_dir =
 	let platform_ext = "." ^ (platform_name_macro ctx)
 	and is_loading_core_api = defined ctx Define.CoreApi in
-	let remove_extension file =
-		try String.sub file 0 (String.rindex file '.')
-		with Not_found -> file
-	in
-	let extension file =
-		try
-			let dot_pos = String.rindex file '.' in
-			String.sub file dot_pos (String.length file - dot_pos)
-		with Not_found -> file
-	in
 	let dir_listing =
 		try Some (Sys.readdir dir);
 		with Sys_error _ -> None

+ 5 - 0
tests/misc/projects/Issue10863/Main.js.hx

@@ -0,0 +1,5 @@
+function main() {
+	foo();
+}
+
+macro function foo():Expr;

+ 8 - 0
tests/misc/projects/Issue10863/Main.macro.hx

@@ -0,0 +1,8 @@
+import haxe.macro.Context;
+import haxe.macro.Expr;
+
+macro function foo():Expr {
+	Context.warning("from macro", (macro 0).pos);
+	Context.warning("from non macro", Context.currentPos());
+	return macro null;
+}

+ 5 - 0
tests/misc/projects/Issue10863/compile.hxml

@@ -0,0 +1,5 @@
+-main Main
+-js js.js
+-D message-reporting=pretty
+-D no-color
+--no-output

+ 12 - 0
tests/misc/projects/Issue10863/compile.hxml.stderr

@@ -0,0 +1,12 @@
+[WARNING] Main.macro.hx:5: characters 39-40
+
+ 5 |  Context.warning("from macro", (macro 0).pos);
+   |                                       ^
+   | from macro
+
+[WARNING] Main.js.hx:2: characters 2-7
+
+ 2 |  foo();
+   |  ^^^^^
+   | from non macro
+