Ver código fonte

add the ability to specify the dump location (#7684)

* add the ability to specify the dump file location when dump_dependencies is specified

* change to -D dump-path=path

* formatting [skip ci]
rwthompsonii 6 anos atrás
pai
commit
d39377a752

+ 5 - 0
src-json/define.json

@@ -111,6 +111,11 @@
 		"doc": "Dump typed AST in dump subdirectory using specified mode or non-prettified default.",
 		"params": ["mode: pretty | record | position | legacy"]
 	},
+	{
+		"name": "DumpPath",
+		"define": "dump_path",
+		"doc": "Path to generate dumps to (default: \"dump\")."
+	},
 	{
 		"name": "DumpDependencies",
 		"define": "dump_dependencies",

+ 6 - 4
src/codegen/codegen.ml

@@ -275,7 +275,7 @@ module Dump = struct
 			close_out ch)
 
 	let create_dumpfile_from_path com path =
-		let buf,close = create_dumpfile [] ("dump" :: (platform_name_macro com) :: fst path @ [snd path]) in
+		let buf,close = create_dumpfile [] ((dump_path com) :: (platform_name_macro com) :: fst path @ [snd path]) in
 		buf,close
 
 	let dump_types com s_expr =
@@ -422,7 +422,8 @@ module Dump = struct
 			| None -> platform_name_macro com
 			| Some s -> s
 		in
-		let buf,close = create_dumpfile [] ["dump";target_name;".dependencies"] in
+		let dump_dependencies_path = [dump_path com;target_name;".dependencies"] in
+		let buf,close = create_dumpfile [] dump_dependencies_path in
 		let print fmt = Printf.kprintf (fun s -> Buffer.add_string buf s) fmt in
 		let dep = Hashtbl.create 0 in
 		List.iter (fun m ->
@@ -434,7 +435,8 @@ module Dump = struct
 			) m.m_extra.m_deps;
 		) com.Common.modules;
 		close();
-		let buf,close = create_dumpfile [] ["dump";target_name;".dependants"] in
+		let dump_dependants_path = [dump_path com;target_name;".dependants"] in
+		let buf,close = create_dumpfile [] dump_dependants_path in
 		let print fmt = Printf.kprintf (fun s -> Buffer.add_string buf s) fmt in
 		Hashtbl.iter (fun n ml ->
 			print "%s:\n" n;
@@ -617,4 +619,4 @@ module ExtClass = struct
 		let ef1 = mk (TField(ethis,FStatic(c,cf))) cf.cf_type p in
 		let e_assign = mk (TBinop(OpAssign,ef1,e)) e.etype p in
 		add_cl_init c e_assign
-end
+end

+ 4 - 1
src/context/common.ml

@@ -821,4 +821,7 @@ let dump_context com = s_record_fields "" [
 	"class_path",s_list ", " (fun s -> s) com.class_path;
 	"defines",s_pmap (fun s -> s) (fun s -> s) com.defines.values;
 	"defines_signature",s_opt (fun s -> Digest.to_hex s) com.defines.defines_signature;
-]
+]
+
+let dump_path com =
+	Define.defined_value_safe ~default:"dump" com.defines Define.DumpPath

+ 1 - 1
src/optimization/analyzer.ml

@@ -809,7 +809,7 @@ module Debug = struct
 		) g.g_var_infos
 
 	let get_dump_path ctx c cf =
-		"dump" :: [platform_name_macro ctx.com] @ (fst c.cl_path) @ [Printf.sprintf "%s.%s" (snd c.cl_path) cf.cf_name]
+		(dump_path ctx.com) :: [platform_name_macro ctx.com] @ (fst c.cl_path) @ [Printf.sprintf "%s.%s" (snd c.cl_path) cf.cf_name]
 
 	let dot_debug ctx c cf =
 		let g = ctx.graph in

+ 4 - 4
src/typing/macroContext.ml

@@ -44,11 +44,11 @@ end
 let macro_enable_cache = ref false
 let macro_interp_cache = ref None
 
-let safe_decode v expected t p f =
+let safe_decode ctx v expected t p f =
 	try
 		f ()
 	with MacroApi.Invalid_expr | EvalContext.RunTimeException _ ->
-		let path = ["dump";"decoding_error"] in
+		let path = [dump_path ctx.com;"decoding_error"] in
 		let ch = Path.create_file false ".txt" [] path  in
 		let errors = Interp.handle_decoding_error (output_string ch) v t in
 		List.iter (fun (s,i) -> Printf.fprintf ch "\nline %i: %s" i s) (List.rev errors);
@@ -306,7 +306,7 @@ let make_macro_api ctx p =
 			let mctx = (match ctx.g.macros with None -> assert false | Some (_,mctx) -> mctx) in
 			let ttype = Typeload.load_instance mctx (cttype,p) false in
 			let f () = Interp.decode_type_def v in
-			let m, tdef, pos = safe_decode v "TypeDefinition" ttype p f in
+			let m, tdef, pos = safe_decode ctx v "TypeDefinition" ttype p f in
 			let add is_macro ctx =
 				let mdep = Option.map_default (fun s -> TypeloadModule.load_module ctx (parse_path s) pos) ctx.m.curmod mdep in
 				let mnew = TypeloadModule.type_module ctx m mdep.m_extra.m_file [tdef,pos] pos in
@@ -720,7 +720,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 						Some (EBlock [],p)
 					)
 			in
-			safe_decode v expected mret p process
+			safe_decode ctx v expected mret p process
 	in
 	let e = if ctx.in_macro then
 		Some (EThrow((EConst(String("macro-in-macro",SDoubleQuotes))),p),p)