Browse Source

deal with import.hx dependencies (see #1138)

Simon Krajewski 9 years ago
parent
commit
41aac19758
2 changed files with 17 additions and 8 deletions
  1. 1 1
      common.ml
  2. 16 7
      typeload.ml

+ 1 - 1
common.ml

@@ -131,7 +131,7 @@ type context = {
 	mutable get_macros : unit -> context option;
 	mutable get_macros : unit -> context option;
 	mutable run_command : string -> int;
 	mutable run_command : string -> int;
 	file_lookup_cache : (string,string option) Hashtbl.t;
 	file_lookup_cache : (string,string option) Hashtbl.t;
-	parser_cache : (string,string list * (type_def * pos) list) Hashtbl.t;
+	parser_cache : (string,(type_def * pos) list) Hashtbl.t;
 	mutable stored_typed_exprs : (int, texpr) PMap.t;
 	mutable stored_typed_exprs : (int, texpr) PMap.t;
 	(* output *)
 	(* output *)
 	mutable file : string;
 	mutable file : string;

+ 16 - 7
typeload.ml

@@ -3283,19 +3283,28 @@ let handle_import_hx ctx m decls p =
 		| _ -> []
 		| _ -> []
 	in
 	in
 	let candidates = loop path_split (fst m.m_path) in
 	let candidates = loop path_split (fst m.m_path) in
+	let make_import_module path r =
+		Hashtbl.replace ctx.com.parser_cache path r;
+		(* We use the file path as module name to make it unique. This may or may not be a good idea... *)
+		let m_import = make_module ctx ([],path) path p in
+		add_module ctx m_import p;
+		add_dependency m m_import;
+	in
 	List.fold_left (fun acc path ->
 	List.fold_left (fun acc path ->
-		let _,decls = try
-			Hashtbl.find ctx.com.parser_cache path
+		let decls = try
+			let r = Hashtbl.find ctx.com.parser_cache path in
+			add_dependency m (Hashtbl.find ctx.g.modules ([],path));
+			r
 		with Not_found ->
 		with Not_found ->
 			if Sys.file_exists path then begin
 			if Sys.file_exists path then begin
-				let r = parse_file ctx.com path p in
-				List.iter (fun (d,p) -> match d with EImport _ | EUsing _ -> () | _ -> error "Only import and using is allowed in import.hx files" p) (snd r);
-				Hashtbl.replace ctx.com.parser_cache path r;
+				let _,r = parse_file ctx.com path p in
+				List.iter (fun (d,p) -> match d with EImport _ | EUsing _ -> () | _ -> error "Only import and using is allowed in import.hx files" p) r;
+				make_import_module path r;
 				r
 				r
 			end else begin
 			end else begin
-				let r = ([],[]) in
+				let r = [] in
 				(* Add empty decls so we don't check the file system all the time. *)
 				(* Add empty decls so we don't check the file system all the time. *)
-				Hashtbl.replace ctx.com.parser_cache path r;
+				make_import_module path r;
 				r
 				r
 			end
 			end
 		in
 		in