[m-rev.] diff: fix bugs in `--rebuild'

Simon Taylor stayl at cs.mu.OZ.AU
Mon Aug 26 14:57:13 AEST 2002


Estimated hours taken: 2
Branches: main

Fix bugs in `--rebuild'.

compiler/compile_target_code.m:
	Always recompile the `module_init.c' file with `--rebuild'.

compiler/handle_options.m:
	The code to make `--rebuild' imply `--make' was after some
	uses of the value of `--make', in particular the code to
	make `--make' imply `--use-subdirs'.

compiler/make.dependencies.m:
compiler/make.program_target.m:
compiler/make.module_target.m:
	Add a sanity check to make sure that all files that should
	have been produced when building a target have been produced,
	and reporting a proper error message if they have not.

Index: compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.21
diff -u -u -r1.21 compile_target_code.m
--- compile_target_code.m	21 Aug 2002 11:27:12 -0000	1.21
+++ compile_target_code.m	24 Aug 2002 13:10:53 -0000
@@ -784,7 +784,7 @@
 
 make_init_obj_file(ErrorStream,
 		ModuleName, ModuleNames, Result) -->
-	{ MustCompile = no },
+	globals__io_lookup_bool_option(rebuild, MustCompile),
 	make_init_obj_file(ErrorStream,
 		MustCompile, ModuleName, ModuleNames, Result).
 
Index: handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.149
diff -u -u -r1.149 handle_options.m
--- handle_options.m	22 Aug 2002 02:34:10 -0000	1.149
+++ handle_options.m	26 Aug 2002 04:05:36 -0000
@@ -443,6 +443,10 @@
 	% --no-mlds-optimize implies --no-optimize-tailcalls
 	option_neg_implies(optimize, optimize_tailcalls, bool(no)),
 
+	% --rebuild is just like --make but always rebuilds the files
+	% without checking timestamps.
+	option_implies(rebuild, make, bool(yes)),
+
 	% make.m controls generating object code and linking itself,
 	% so mercury_compile.m should only generate target code when
 	% given a module to process.
@@ -540,10 +544,6 @@
 	% processes the target code file itself, so this isn't a problem.
 	maybe_disable_smart_recompilation(Smart, target_code_only, no,
 		"`--no-target-code-only'"),
-
-	% --rebuild is just like --make but always rebuilds the files
-	% without checking timestamps.
-	option_implies(rebuild, make, bool(yes)),
 
 	option_implies(use_grade_subdirs, use_subdirs, bool(yes)),
 
Index: make.dependencies.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.8
diff -u -u -r1.8 make.dependencies.m
--- make.dependencies.m	7 Aug 2002 13:11:51 -0000	1.8
+++ make.dependencies.m	25 Aug 2002 13:51:30 -0000
@@ -67,14 +67,20 @@
 	;	error
 	.
 
+	% check_dependencies(TargetFileName, TargetFileTimestamp,
+	%	BuildDepsSucceeded, Dependencies, Result)
+	%
 	% Check that all the dependency targets are up-to-date. 
-:- pred check_dependencies(string::in, maybe_error(timestamp)::in,
+:- pred check_dependencies(file_name::in, maybe_error(timestamp)::in, bool::in,
 	list(dependency_file)::in, dependencies_result::out,
 	make_info::in, make_info::out, io__state::di, io__state::uo) is det.
 
+	% check_dependencies(TargetFileName, TargetFileTimestamp,
+	%	BuildDepsSucceeded, Dependencies, Result)
+	%
 	% Check that all the dependency files are up-to-date. 
-:- pred check_dependency_timestamps(string::in,
-	maybe_error(timestamp)::in, list(File)::in,
+:- pred check_dependency_timestamps(file_name::in, maybe_error(timestamp)::in,
+	bool::in, list(File)::in,
 	pred(File, io__state, io__state)::(pred(in, di, uo) is det),
 	list(maybe_error(timestamp))::in, dependencies_result::out,
 	io__state::di, io__state::uo) is det.
@@ -716,7 +722,7 @@
 
 %-----------------------------------------------------------------------------%
 
-check_dependencies(TargetFileName, MaybeTimestamp,
+check_dependencies(TargetFileName, MaybeTimestamp, BuildDepsSucceeded,
 		DepFiles, DepsResult, Info0, Info) -->
 	list__map_foldl2(dependency_status, DepFiles,
 		DepStatusList, Info0, Info1),
@@ -755,12 +761,12 @@
 			DepTimestamps, Info1, Info),
 
 		check_dependency_timestamps(TargetFileName, MaybeTimestamp,
-			DepFiles, write_dependency_file, DepTimestamps,
-			DepsResult)
+			BuildDepsSucceeded, DepFiles, write_dependency_file,
+			DepTimestamps, DepsResult)
 	).
 
-check_dependency_timestamps(TargetFileName, MaybeTimestamp, DepFiles,
-		WriteDepFile, DepTimestamps, DepsResult) -->
+check_dependency_timestamps(TargetFileName, MaybeTimestamp, BuildDepsSucceeded,
+		DepFiles, WriteDepFile, DepTimestamps, DepsResult) -->
     ( 
 	{ MaybeTimestamp = error(_) },
 	{ DepsResult = out_of_date },
@@ -778,7 +784,7 @@
 	    { MaybeDepTimestamp1 = error(_) }
 	->
 	    { DepsResult = error },
-	    debug_msg(
+	    { WriteMissingDeps =
 	        (pred(di, uo) is det -->
 		    { assoc_list__from_corresponding_lists(DepFiles,
 				DepTimestamps, DepTimestampAL) },
@@ -787,11 +793,30 @@
 				list__member(DepFile - error(_),
 					DepTimestampAL)
 			    ), ErrorDeps) },
+		    io__write_string("** dependencies for `"),
 		    io__write_string(TargetFileName),
-		    io__write_string(": failed dependencies: "),
-		    io__write_list(ErrorDeps, ",\n\t", WriteDepFile),
-		    io__nl
-		))
+		    io__write_string("' do not exist: "),
+		    io__write_list(ErrorDeps, ", ", WriteDepFile),
+		    io__nl,
+		    ( { BuildDepsSucceeded = yes } ->
+		    	io__write_string(
+			"** This indicates a bug in `mmc --make'.\n")
+		    ;
+		    	[]
+		    )
+		) },
+	    (
+	    	{ BuildDepsSucceeded = yes },
+		%
+		% Something has gone wrong -- building the target has
+		% succeeded, but there are some files missing.
+		% Report an error.
+		%
+	    	WriteMissingDeps
+	    ;
+	    	{ BuildDepsSucceeded = no },
+	    	debug_msg(WriteMissingDeps)
+	    )
 	;
 	    { Rebuild = yes }
 	->
Index: make.module_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.module_target.m,v
retrieving revision 1.14
diff -u -u -r1.14 make.module_target.m
--- make.module_target.m	8 Aug 2002 06:25:44 -0000	1.14
+++ make.module_target.m	25 Aug 2002 13:56:59 -0000
@@ -199,8 +199,8 @@
 			TouchedFileTimestamps, MaybeOldestTimestamp0) },
 
 		get_file_name(no, TargetFile, TargetFileName, Info4, Info5),
-		check_dependencies(TargetFileName,
-			MaybeOldestTimestamp, DepFilesToMake,
+		check_dependencies(TargetFileName, MaybeOldestTimestamp,
+			MakeDepsSuccess, DepFilesToMake,
 			DepsResult, Info5, Info)
 	).
 
Index: make.program_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.10
diff -u -u -r1.10 make.program_target.m
--- make.program_target.m	9 Aug 2002 08:32:49 -0000	1.10
+++ make.program_target.m	26 Aug 2002 04:31:39 -0000
@@ -70,12 +70,13 @@
 
 	foldl2_maybe_stop_at_error(KeepGoing,
 		foldl2_maybe_stop_at_error(KeepGoing, make_module_target),
-		[IntermediateTargets, ObjTargets], _, Info4, Info5),
+		[IntermediateTargets, ObjTargets], BuildDepsSucceeded,
+		Info4, Info5),
 
 	linked_target_file_name(MainModuleName, FileType, OutputFileName),
 	get_file_timestamp([dir__this_directory], OutputFileName,
 		MaybeTimestamp, Info5, Info6),
-	check_dependencies(OutputFileName, MaybeTimestamp,
+	check_dependencies(OutputFileName, MaybeTimestamp, BuildDepsSucceeded,
 		ObjTargets, BuildDepsResult, Info6, Info7),
 
 	(
@@ -219,26 +220,37 @@
 	),
 
 	{ ObjectsToCheck = InitObjects ++ LinkObjects },
+
+	%
+	% Report errors if any of the extra objects aren't present.
+	%
+	list__map_foldl2(dependency_status,
+		list__map((func(F) = file(F, no)), ObjectsToCheck),
+		ExtraObjStatus, Info1, Info2),
+
+	{ DepsResult3 =
+	    ( list__member(error, ExtraObjStatus) -> error ; DepsResult2 ) },
+	{ BuildDepsSuccess = ( DepsResult3 \= error -> yes ; no ) },
 	list__map_foldl2(get_file_timestamp([dir__this_directory]),
-		ObjectsToCheck, ExtraObjectTimestamps, Info1, Info2),
+		ObjectsToCheck, ExtraObjectTimestamps, Info2, Info3),
 	check_dependency_timestamps(OutputFileName, MaybeTimestamp,
-		ObjectsToCheck, io__write, ExtraObjectTimestamps,
-		ExtraObjectDepsResult),
+		BuildDepsSuccess, ObjectsToCheck, io__write,
+		ExtraObjectTimestamps, ExtraObjectDepsResult),
 
-	{ DepsResult3 = ( DepsSuccess = yes -> DepsResult2 ; error ) },
-	{ DepsResult3 = error, DepsResult = DepsResult3
-	; DepsResult3 = out_of_date, DepsResult = DepsResult3
-	; DepsResult3 = up_to_date, DepsResult = ExtraObjectDepsResult
+	{ DepsResult4 = ( DepsSuccess = yes -> DepsResult3 ; error ) },
+	{ DepsResult4 = error, DepsResult = DepsResult4
+	; DepsResult4 = out_of_date, DepsResult = DepsResult4
+	; DepsResult4 = up_to_date, DepsResult = ExtraObjectDepsResult
 	},
 	(
 		{ DepsResult = error },
 		file_error(OutputFileName),
 		{ Succeeded = no },
-		{ Info = Info2 }
+		{ Info = Info3 }
 	;
 		{ DepsResult = up_to_date },
 		{ Succeeded = yes },
-		{ Info = Info2 }
+		{ Info = Info3 }
 	;
 		{ DepsResult = out_of_date },
 		maybe_make_linked_target_message(OutputFileName),
@@ -264,7 +276,7 @@
 			    { error(
 			    "build_linked_target: error in dependencies") }
 			)
-		    ), AllModulesList, ExtraForeignFiles, Info2, Info3),
+		    ), AllModulesList, ExtraForeignFiles, Info3, Info4),
 		{ ForeignObjects = list__map(
 			(func(foreign_code_file(_, _, ObjFile)) = ObjFile),
 			list__condense(ExtraForeignFiles)) },
@@ -310,12 +322,12 @@
 		),
 
 		( { Succeeded = yes } ->
-			{ Info = Info3 ^ file_timestamps :=
-				map__delete(Info3 ^ file_timestamps,
+			{ Info = Info4 ^ file_timestamps :=
+				map__delete(Info4 ^ file_timestamps,
 					OutputFileName) }
 		;
 			file_error(OutputFileName),
-			{ Info = Info3 }
+			{ Info = Info4 }
 		)
 	),
 	globals__io_set_option(link_objects, accumulating(LinkObjects)).
--------------------------------------------------------------------------
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