[m-rev.] for review: warn for up-to-date `mmc --make' targets

Simon Taylor stayl at cs.mu.OZ.AU
Wed Oct 30 15:00:12 AEDT 2002


Estimated hours taken: 1
Branches: main

With `--make', warn if a target specified on the command line
is already up to date.

compiler/make.util.m:
	Check whether a target that was found to be up to date
	was specified on the command line.

compiler/make.m:
	Add the targets specified on the command line to the make_info.

compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.dependencies.m:
	Call make__util__maybe_warn_up_to_date_target when a target
	is found to be up to date.

	Remove targets from the list of targets specified on the command
	line as they are processed to avoid generating multiple warnings.

compiler/options.m:
doc/user_guide.texi:
	Add an option `--no-warn-up-to-date'.

Index: compiler/make.dependencies.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.9
diff -u -u -r1.9 make.dependencies.m
--- compiler/make.dependencies.m	26 Aug 2002 04:56:58 -0000	1.9
+++ compiler/make.dependencies.m	29 Oct 2002 06:14:16 -0000
@@ -890,7 +890,8 @@
     { Target = ModuleName - FileType },
     ( { FileType = source } ->
 	% Source files are always up-to-date.
-	{ Info = Info0 },
+	maybe_warn_up_to_date_target(ModuleName - module_target(source),
+		Info0, Info),
 	{ Status = up_to_date }
     ; { Status0 = Info0 ^ dependency_status ^ elem(Dep) } ->
 		{ Info = Info0 },
Index: compiler/make.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.12
diff -u -u -r1.12 make.m
--- compiler/make.m	28 Oct 2002 02:43:26 -0000	1.12
+++ compiler/make.m	28 Oct 2002 15:38:27 -0000
@@ -105,7 +105,11 @@
 
 			% Used for reporting which module imported
 			% a nonexistent module.
-		importing_module :: maybe(module_name)
+		importing_module :: maybe(module_name),
+
+			% Targets specified on the command line.
+		command_line_targets :: set(pair(module_name, target_type))
+
 	).
 
 :- type make_error
@@ -241,59 +245,74 @@
     ( { Continue = no } ->	
 	io__set_exit_status(1)
     ;
-	{ ShouldRebuildDeps = yes },
 	globals__io_lookup_bool_option(keep_going, KeepGoing),
+	globals__io_get_globals(Globals),
+
+	%
+	% Accept and ignore `.depend' targets.
+	% `mmc --make' does not need a separate
+	% make depend step. The dependencies for
+	% each module are regenerated on demand.
+	%
+	{ NonDependTargets = list__filter(
+		(pred(Target::in) is semidet :-
+			\+ string__remove_suffix(Target, ".depend", _)
+		), Targets) },
+
+	%
+	% Classify the remaining targets.
+	%
+	{ list__filter_map(classify_target(Globals), NonDependTargets,
+		ClassifiedTargets, InvalidTargets) },
+
+	%
+	% Report errors for unknown targets.
+	%
+	list__foldl(
+		(pred(InvalidTarget::in, di, uo) is det -->
+			io__write_string("** Unknown target: "),
+			io__write_string(InvalidTarget),
+			io__write_string(".\n")
+		), InvalidTargets),
+
+	{ ShouldRebuildDeps = yes },
 	{ MakeInfo0 = make_info(map__init, map__init,
 		OptionArgs, Variables, map__init,
 		init_cached_direct_imports,
 		init_cached_transitive_dependencies,
-		ShouldRebuildDeps, KeepGoing, set__init, no) },
+		ShouldRebuildDeps, KeepGoing,
+		set__init, no, set__list_to_set(ClassifiedTargets)) },
 
-	globals__io_get_globals(Globals),
-	foldl2_maybe_stop_at_error(KeepGoing,
-	    (pred(TargetStr::in, Success0::out,
-	    		Info0::in, Info::out, di, uo) is det -->	
-		(
-			% Accept and ignore `.depend' targets.
-			% `mmc --make' does not need a separate
-			% make depend step. The dependencies for
-			% each module are regenerated on demand.
-			{ string__length(TargetStr, NameLength) },
-			{ search_backwards_for_dot(TargetStr,
-				NameLength - 1, DotLocn) },
-			{ string__split(TargetStr, DotLocn, _, ".depend") }
-		->
-			{ Success0 = yes },
-			{ Info = Info0 }
-		;
-			{ target_file(Globals, TargetStr,
-				ModuleName, TargetType) }
-		->
-			(
-			    { TargetType = module_target(ModuleTargetType) },
-			    make_module_target(
+	%
+	% Build the targets, stopping on any errors if
+	% `--keep-going' was not set.
+	%
+	( { InvalidTargets = [] ; KeepGoing = yes } ->
+	    foldl2_maybe_stop_at_error(KeepGoing,
+		(pred(Target::in, Success0::out, Info0::in, Info::out,
+		    		di, uo) is det -->
+		    { Target = ModuleName - TargetType },
+		    (
+			{ TargetType = module_target(ModuleTargetType) },
+			make_module_target(
 			    	target(ModuleName - ModuleTargetType),
 			    	Success0, Info0, Info)
-			;
-			    { TargetType = linked_target(ProgramTargetType) },
-			    make_linked_target(
+		    ;
+			{ TargetType = linked_target(ProgramTargetType) },
+			make_linked_target(
 			    	ModuleName - ProgramTargetType, Success0,
 			    	Info0, Info)
-			;
-			    { TargetType = misc_target(MiscTargetType) },
-			    make_misc_target(ModuleName - MiscTargetType,
+		    ;
+			{ TargetType = misc_target(MiscTargetType) },
+			make_misc_target(ModuleName - MiscTargetType,
 			    	Success0, Info0, Info)
-			)
-		;
-			{ Info = Info0 },
-			{ Success0 = no },
-			io__write_string("** Unknown target: "),
-			io__write_string(TargetStr),
-			io__write_string(".\n")
-		)
-	    ), Targets, Success, MakeInfo0, _MakeInfo),
+		    )
+		), ClassifiedTargets, Success, MakeInfo0, _MakeInfo)
+	;
+		{ Success = no }
+	),
 
-	( { Success = no } ->
+	( { InvalidTargets \= [] ; Success = no } ->
 		io__set_exit_status(1)
 	;
 		[]
@@ -308,10 +327,10 @@
 	;	misc_target(misc_target_type)
 	.
 
-:- pred target_file(globals::in, string::in,
-		module_name::out, target_type::out) is semidet.
+:- pred classify_target(globals::in, string::in,
+		pair(module_name, target_type)::out) is semidet.
 
-target_file(Globals, FileName, ModuleName, TargetType) :-
+classify_target(Globals, FileName, ModuleName - TargetType) :-
     (
 	string__length(FileName, NameLength),
 	search_backwards_for_dot(FileName, NameLength - 1, DotLocn),
Index: compiler/make.module_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.module_target.m,v
retrieving revision 1.16
diff -u -u -r1.16 make.module_target.m
--- compiler/make.module_target.m	14 Oct 2002 06:46:34 -0000	1.16
+++ compiler/make.module_target.m	28 Oct 2002 17:09:13 -0000
@@ -144,16 +144,23 @@
 	    			TouchedTargetFiles, Info6, Info) }
 		;
 			{ DepsResult = out_of_date },
+			{ Info7 = Info6 ^ command_line_targets :=
+				set__delete(Info6 ^ command_line_targets,
+				    ModuleName - module_target(FileType)) },
 			build_target(CompilationTask, TargetFile, Imports,
 				TouchedTargetFiles, TouchedFiles, Succeeded,
-				Info6, Info)
+				Info7, Info)
 		;
 			{ DepsResult = up_to_date },
+			maybe_warn_up_to_date_target(
+				ModuleName - module_target(FileType),
+				Info6, Info7),
+
 			debug_file_msg(TargetFile, "up to date"),
 			{ Succeeded = yes },
 			{ list__foldl(update_target_status(up_to_date),
 	    			[TargetFile | TouchedTargetFiles],
-				Info6, Info) }
+				Info7, Info) }
 		)
 	    )
     	)
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.13
diff -u -u -r1.13 make.program_target.m
--- compiler/make.program_target.m	15 Oct 2002 16:23:54 -0000	1.13
+++ compiler/make.program_target.m	29 Oct 2002 14:00:59 -0000
@@ -262,8 +262,10 @@
 		{ Info = Info3 }
 	;
 		{ DepsResult = up_to_date },
-		{ Succeeded = yes },
-		{ Info = Info3 }
+		maybe_warn_up_to_date_target(
+			MainModuleName - linked_target(FileType),
+			Info3, Info),
+		{ Succeeded = yes }
 	;
 		{ DepsResult = out_of_date },
 		maybe_make_linked_target_message(OutputFileName),
@@ -322,9 +324,6 @@
 					FileType, MainModuleName, AllObjects),
 				Succeeded)
 		;
-			%
-			% IL doesn't need any linking. XXX Is this right?
-			%
 			{ CompilationTarget = il },
 			{ Succeeded = yes }
 		;
@@ -334,13 +333,16 @@
 			"Sorry, not implemented, linking for `--target java'")
 		),
 
+		{ Info5 = Info4 ^ command_line_targets :=
+			set__delete(Info4 ^ command_line_targets, 
+				MainModuleName - linked_target(FileType)) },
 		( { Succeeded = yes } ->
-			{ Info = Info4 ^ file_timestamps :=
-				map__delete(Info4 ^ file_timestamps,
+			{ Info = Info5 ^ file_timestamps :=
+				map__delete(Info5 ^ file_timestamps,
 					OutputFileName) }
 		;
 			file_error(OutputFileName),
-			{ Info = Info4 }
+			{ Info = Info5 }
 		)
 	),
 	globals__io_set_option(link_objects, accumulating(LinkObjects)).
Index: compiler/make.util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.9
diff -u -u -r1.9 make.util.m
--- compiler/make.util.m	7 Aug 2002 13:11:52 -0000	1.9
+++ compiler/make.util.m	29 Oct 2002 06:16:04 -0000
@@ -198,6 +198,11 @@
 	% Write a message "** Error making <filename>".
 :- pred file_error(file_name::in, io__state::di, io__state::uo) is det.
 
+	% If the given target was specified on the command
+	% line, warn that it was already up to date.
+:- pred maybe_warn_up_to_date_target(pair(module_name, target_type)::in,
+	make_info::in, make_info::out, io__state::di, io__state::uo) is det.
+
 %-----------------------------------------------------------------------------%
 :- implementation.
 
@@ -760,5 +765,33 @@
 	io__write_string("** Error making `"),
 	io__write_string(TargetFile),
 	io__write_string("'.\n").
+
+maybe_warn_up_to_date_target(Target @ (ModuleName - FileType), Info0, Info) -->
+	globals__io_lookup_bool_option(warn_up_to_date, Warn),
+	( { Warn = yes } ->
+		( { set__member(Target, Info0 ^ command_line_targets) } ->
+			io__write_string("** Nothing to be done for `"),
+			(
+				{ FileType = module_target(ModuleTargetType) },
+				write_target_file(ModuleName - ModuleTargetType)
+			;
+				{ FileType = linked_target(LinkedTargetType) },
+				linked_target_file_name(ModuleName,
+					LinkedTargetType, FileName),
+				io__write_string(FileName)
+			;
+				{ FileType = misc_target(_) },
+				{ error(
+			"maybe_warn_up_to_date_target: misc_target") }
+			),
+			io__write_string("'.\n")
+		;
+			[]
+		)
+	;
+		[]
+	),
+	{ Info = Info0 ^ command_line_targets :=
+		set__delete(Info0 ^ command_line_targets, Target) }.
 
 %-----------------------------------------------------------------------------%
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.390
diff -u -u -r1.390 options.m
--- compiler/options.m	22 Oct 2002 04:35:54 -0000	1.390
+++ compiler/options.m	29 Oct 2002 14:00:59 -0000
@@ -90,6 +90,7 @@
 		;	warn_smart_recompilation
 		;	warn_undefined_options_variables
 		;	warn_non_tail_recursion
+		;	warn_up_to_date
 	% Verbosity options
 		;	verbose
 		;	very_verbose
@@ -663,7 +664,8 @@
 	warn_wrong_module_name -	bool(yes),
 	warn_smart_recompilation -	bool(yes),
 	warn_undefined_options_variables - bool(yes),
-	warn_non_tail_recursion -	bool(no)
+	warn_non_tail_recursion -	bool(no),
+	warn_up_to_date -		bool(yes)
 ]).
 option_defaults_2(verbosity_option, [
 		% Verbosity Options
@@ -1212,6 +1214,7 @@
 long_option("warn-undefined-options-variables",
 					warn_undefined_options_variables).
 long_option("warn-non-tail-recursion",	warn_non_tail_recursion).
+long_option("warn-up-to-date",		warn_up_to_date).
 
 % verbosity options
 long_option("verbose",			verbose).
@@ -1836,7 +1839,8 @@
 			warn_missing_module_name -	bool(Enable),
 			warn_wrong_module_name	-	bool(Enable),
 			warn_smart_recompilation -	bool(Enable),
-			warn_undefined_options_variables - bool(Enable)
+			warn_undefined_options_variables - bool(Enable),
+			warn_up_to_date -		bool(Enable)
 		], OptionTable0, OptionTable).
 special_handler(infer_all, bool(Infer), OptionTable0, ok(OptionTable)) :-
 	override_options([
@@ -2273,7 +2277,10 @@
 		"\toptions files with `--make'.",
 		"--warn-non-tail-recursion",
 		"\tWarn about any directly recursive calls that are not tail calls.",
-		"\tThis requires --high-level-code."
+		"\tThis requires --high-level-code.",
+		"--no-warn-up-to-date",
+		"\tDon't warn if targets specified on the command line",
+		"\twith `--make' are already up to date."
 	]).
 
 :- pred options_help_verbosity(io__state::di, io__state::uo) is det.
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.333
diff -u -u -r1.333 user_guide.texi
--- doc/user_guide.texi	26 Oct 2002 14:15:33 -0000	1.333
+++ doc/user_guide.texi	29 Oct 2002 14:00:59 -0000
@@ -4122,6 +4122,13 @@
 @findex --warn-non-tail-recursion
 Warn about any directly recursive calls that are not tail recursive.
 This option also requires @samp{--high-level-code}.
+
+ at sp 1
+ at item --no-warn-up-to-date
+ at findex --no-warn-up-to-date
+ at findex --warn-up-to-date
+Don't warn if targets specified on the command line
+with @samp{--make} are already up to date.
 @end table
 
 @node Verbosity options
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list