2
0
Эх сурвалжийг харах

Unify help messages handling (#11584)

* Don't go through message reporting for help messages

* [tests] Avoid (ab)using --version
Rudy Ges 1 жил өмнө
parent
commit
d92f08b8eb

+ 5 - 10
src/compiler/args.ml

@@ -154,8 +154,7 @@ let parse_args com =
 			com.debug <- true;
 			com.debug <- true;
 		),"","add debug information to the compiled code");
 		),"","add debug information to the compiled code");
 		("Miscellaneous",["--version"],["-version"],Arg.Unit (fun() ->
 		("Miscellaneous",["--version"],["-version"],Arg.Unit (fun() ->
-			com.info s_version_full null_pos;
-			actx.did_something <- true;
+			raise (Helper.HelpMessage s_version_full);
 		),"","print version and exit");
 		),"","print version and exit");
 		("Miscellaneous", ["-h";"--help"], ["-help"], Arg.Unit (fun () ->
 		("Miscellaneous", ["-h";"--help"], ["-help"], Arg.Unit (fun () ->
 			raise (Arg.Help "")
 			raise (Arg.Help "")
@@ -163,31 +162,27 @@ let parse_args com =
 		("Miscellaneous",["--help-defines"],[], Arg.Unit (fun() ->
 		("Miscellaneous",["--help-defines"],[], Arg.Unit (fun() ->
 			let all,max_length = Define.get_documentation_list com.user_defines in
 			let all,max_length = Define.get_documentation_list com.user_defines in
 			let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
 			let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
-			List.iter (fun msg -> com.print (msg ^ "\n")) all;
-			actx.did_something <- true
+			raise (Helper.HelpMessage (ExtLib.String.join "\n" all));
 		),"","print help for all compiler specific defines");
 		),"","print help for all compiler specific defines");
 		("Miscellaneous",["--help-user-defines"],[], Arg.Unit (fun() ->
 		("Miscellaneous",["--help-user-defines"],[], Arg.Unit (fun() ->
 			actx.did_something <- true;
 			actx.did_something <- true;
 			com.callbacks#add_after_init_macros (fun() ->
 			com.callbacks#add_after_init_macros (fun() ->
 				let all,max_length = Define.get_user_documentation_list com.user_defines in
 				let all,max_length = Define.get_user_documentation_list com.user_defines in
 				let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
 				let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
-				List.iter (fun msg -> com.print (msg ^ "\n")) all;
-				raise Abort
+				raise (Helper.HelpMessage (ExtLib.String.join "\n" all));
 			)
 			)
 		),"","print help for all user defines");
 		),"","print help for all user defines");
 		("Miscellaneous",["--help-metas"],[], Arg.Unit (fun() ->
 		("Miscellaneous",["--help-metas"],[], Arg.Unit (fun() ->
 			let all,max_length = Meta.get_documentation_list com.user_metas in
 			let all,max_length = Meta.get_documentation_list com.user_metas in
 			let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
 			let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
-			List.iter (fun msg -> com.print (msg ^ "\n")) all;
-			actx.did_something <- true
+			raise (Helper.HelpMessage (ExtLib.String.join "\n" all));
 		),"","print help for all compiler metadatas");
 		),"","print help for all compiler metadatas");
 		("Miscellaneous",["--help-user-metas"],[], Arg.Unit (fun() ->
 		("Miscellaneous",["--help-user-metas"],[], Arg.Unit (fun() ->
 			actx.did_something <- true;
 			actx.did_something <- true;
 			com.callbacks#add_after_init_macros (fun() ->
 			com.callbacks#add_after_init_macros (fun() ->
 				let all,max_length = Meta.get_user_documentation_list com.user_metas in
 				let all,max_length = Meta.get_user_documentation_list com.user_metas in
 				let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
 				let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
-				List.iter (fun msg -> com.print (msg ^ "\n")) all;
-				raise Abort
+				raise (Helper.HelpMessage (ExtLib.String.join "\n" all));
 			)
 			)
 		),"","print help for all user metadatas");
 		),"","print help for all user metadatas");
 	] in
 	] in

+ 1 - 1
src/compiler/compiler.ml

@@ -440,7 +440,7 @@ with
 	| Failure msg when not Helper.is_debug_run ->
 	| Failure msg when not Helper.is_debug_run ->
 		error ctx ("Error: " ^ msg) null_pos
 		error ctx ("Error: " ^ msg) null_pos
 	| Helper.HelpMessage msg ->
 	| Helper.HelpMessage msg ->
-		com.info msg null_pos
+		print_endline msg
 	| Parser.TypePath (p,c,is_import,pos) ->
 	| Parser.TypePath (p,c,is_import,pos) ->
 		DisplayOutput.handle_type_path_exception ctx p c is_import pos
 		DisplayOutput.handle_type_path_exception ctx p c is_import pos
 	| Parser.SyntaxCompletion(kind,subj) ->
 	| Parser.SyntaxCompletion(kind,subj) ->

+ 1 - 0
tests/misc/projects/Issue8471/Macro.hx

@@ -2,6 +2,7 @@ import haxe.macro.Context;
 
 
 class Macro {
 class Macro {
 	public static function init() {
 	public static function init() {
+		Context.info("Info", Context.currentPos());
 		Context.warning("This warning will disappear", Context.currentPos());
 		Context.warning("This warning will disappear", Context.currentPos());
 
 
 		Context.onAfterTyping(afterTyping);
 		Context.onAfterTyping(afterTyping);

+ 1 - 0
tests/misc/projects/Issue8471/Macro2.hx

@@ -9,6 +9,7 @@ class Macro2 {
 	}
 	}
 
 
 	static function afterTyping(_) {
 	static function afterTyping(_) {
+		Context.info("Info", Context.currentPos());
 		Context.warning(("1" :DeprecatedType), Context.currentPos());
 		Context.warning(("1" :DeprecatedType), Context.currentPos());
 		Context.warning("2", Context.currentPos());
 		Context.warning("2", Context.currentPos());
 		Context.warning("3", Context.currentPos());
 		Context.warning("3", Context.currentPos());

+ 0 - 1
tests/misc/projects/Issue8471/compile.hxml

@@ -1,2 +1 @@
---version
 --macro Macro.init()
 --macro Macro.init()

+ 2 - 2
tests/misc/projects/Issue8471/compile2-pretty.hxml.stderr

@@ -1,6 +1,6 @@
-[WARNING] (macro) Macro2.hx:12: characters 25-39
+[WARNING] (macro) Macro2.hx:13: characters 25-39
 
 
- 12 |   Context.warning(("1" :DeprecatedType), Context.currentPos());
+ 13 |   Context.warning(("1" :DeprecatedType), Context.currentPos());
     |                         ^^^^^^^^^^^^^^
     |                         ^^^^^^^^^^^^^^
     | (WDeprecated) This typedef is deprecated in favor of String
     | (WDeprecated) This typedef is deprecated in favor of String
 
 

+ 0 - 1
tests/misc/projects/Issue8471/compile2.hxml

@@ -1,2 +1 @@
---version
 --macro Macro2.init()
 --macro Macro2.init()

+ 1 - 1
tests/misc/projects/Issue8471/compile2.hxml.stderr

@@ -1,4 +1,4 @@
-Macro2.hx:12: characters 25-39 : Warning : (WDeprecated) This typedef is deprecated in favor of String
+Macro2.hx:13: characters 25-39 : Warning : (WDeprecated) This typedef is deprecated in favor of String
 Warning : 1
 Warning : 1
 Warning : 2
 Warning : 2
 Warning : 3
 Warning : 3