[m-rev.] for review: fix `mmc --make' header file handling

Simon Taylor stayl at cs.mu.OZ.AU
Mon Jun 17 18:25:20 AEST 2002


Estimated hours taken: 3
Branches: main

Fix the handling of header files with `mmc --make'.

compiler/make.module_target.m:
	Check that all files made by the command are present
	(for example, previously only the `.c_date' files were
	checked, not the `.c' files).

compiler/make.util.m:
	In high-level C grades, don't rebuild the `.o' file if an
	irrelevant part of a `.mih' file has changed. If a relevant
	part of a `.mih' file changed, the interface files of the
	imported module must have changed in a way that would force
	the `.c' and `.o' files of the current module to be rebuilt.
	
	When finding the timestamps for header files, make sure
	the current directory is searched.

	Header files are created using mercury_update_interface,
	so to check whether a header file is up to date we need
	to check the timestamp on the `.c_date' or `.s_date' file,
	not the header file itself.

compiler/make.dependencies.m:
	Add some more debugging messages.

	Fix the format of some error messages.


Index: make.dependencies.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.5
diff -u -u -r1.5 make.dependencies.m
--- make.dependencies.m	30 May 2002 12:55:01 -0000	1.5
+++ make.dependencies.m	16 Jun 2002 08:10:34 -0000
@@ -774,7 +774,21 @@
 	    { list__member(MaybeDepTimestamp1, DepTimestamps) },
 	    { MaybeDepTimestamp1 = error(_) }
 	->
-	    { DepsResult = error }
+	    { DepsResult = error },
+	    debug_msg(
+	        (pred(di, uo) is det -->
+		    { assoc_list__from_corresponding_lists(DepFiles,
+				DepTimestamps, DepTimestampAL) },
+		    { solutions(
+			    (pred(DepFile::out) is nondet :-
+				list__member(DepFile - error(_),
+					DepTimestampAL)
+			    ), ErrorDeps) },
+		    io__write_string(TargetFileName),
+		    io__write_string(": failed dependencies: "),
+		    io__write_list(ErrorDeps, ",\n\t", WriteDepFile),
+		    io__nl
+		))
 	;
 	    { Rebuild = yes }
 	->
@@ -839,7 +853,8 @@
 			io__write_string("** Error: file `"),
 			io__write_string(FileName),
 			io__write_string("' not found: "),
-			io__write_string(Error)
+			io__write_string(Error),
+			io__nl
 		),
 		{ Info = Info1 ^ dependency_status ^ elem(Dep) := Status }
 	).
@@ -876,7 +891,8 @@
 		    io__write_string("** Error: file `"),
 		    write_target_file(Target),
 		    io__write_string("' not found: "),
-		    io__write_string(Error)
+		    io__write_string(Error),
+		    io__nl
 	        )
 	    ;
 		{ Info2 = Info1 },
Index: make.module_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.module_target.m,v
retrieving revision 1.7
diff -u -u -r1.7 make.module_target.m
--- make.module_target.m	30 May 2002 12:55:01 -0000	1.7
+++ make.module_target.m	17 Jun 2002 07:35:12 -0000
@@ -106,34 +106,14 @@
 			io__nl
 		    )),
 
-		%
-		% For comparison, find the oldest of the touched
-		% timestamp files.
-		%
-		list__map_foldl2(
-			get_timestamp_file_timestamp, TouchedTargetFiles,
-			TouchedTargetFileTimestamps, Info5, Info6),
-		list__map_foldl2(get_file_timestamp([dir__this_directory]),
-			TouchedFiles, TouchedFileTimestamps, Info6, Info8),
-		{ MaybeOldestTimestamp0 = list__foldl(find_oldest_timestamp, 
-			TouchedTargetFileTimestamps, ok(newest_timestamp)) },
-		{ MaybeOldestTimestamp = list__foldl(find_oldest_timestamp, 
-			TouchedFileTimestamps, MaybeOldestTimestamp0) },
-		module_name_to_file_name(ModuleName,
-			target_extension(Globals, FileType),
-			no, TargetFileName),
-
 		globals__io_lookup_bool_option(keep_going, KeepGoing),
 		( { DepsSuccess = no, KeepGoing = no } ->
-			{ Info10 = Info8 },
+			{ Info6 = Info5 },
 			{ DepsResult = error }
 		;
-			foldl2_maybe_stop_at_error(KeepGoing,
-				make_module_target, DepFilesToMake,
-				_, Info8, Info9),
-			check_dependencies(TargetFileName,
-				MaybeOldestTimestamp, DepFilesToMake,
-				DepsResult0, Info9, Info10),
+			make_dependency_files(TargetFile, DepFilesToMake,
+				TouchedTargetFiles, TouchedFiles, DepsResult0,
+				Info5, Info6),
 			{ DepsResult =
 				( DepsSuccess = yes -> DepsResult0 ; error ) }
 		),
@@ -141,19 +121,19 @@
 			{ DepsResult = error },
 			{ Succeeded = no },
 			{ list__foldl(update_target_status(error),
-	    			TouchedTargetFiles, Info10, Info) }
+	    			TouchedTargetFiles, Info6, Info) }
 		;
 			{ DepsResult = out_of_date },
 			build_target(CompilationTask, TargetFile, Imports,
 				TouchedTargetFiles, TouchedFiles, Succeeded,
-				Info10, Info)
+				Info6, Info)
 		;
 			{ DepsResult = up_to_date },
 			debug_file_msg(TargetFile, "up to date"),
 			{ Succeeded = yes },
 			{ list__foldl(update_target_status(up_to_date),
 	    			[TargetFile | TouchedTargetFiles],
-				Info10, Info) }
+				Info6, Info) }
 		)
 	    )
     	)
@@ -173,6 +153,49 @@
 	{ Info = Info1 }
     ).
 
+:- pred make_dependency_files(target_file::in, list(dependency_file)::in,
+	list(target_file)::in, list(file_name)::in, dependencies_result::out,
+	make_info::in, make_info::out, io__state::di, io__state::uo) is det.
+
+make_dependency_files(TargetFile, DepFilesToMake, TouchedTargetFiles,
+		TouchedFiles, DepsResult, Info0, Info) -->
+	%
+	% Build the dependencies.
+	%
+	globals__io_lookup_bool_option(keep_going, KeepGoing),
+	foldl2_maybe_stop_at_error(KeepGoing, make_module_target,
+		DepFilesToMake, _, Info0, Info1),
+
+	%
+	% Check that the target files exist.
+	%
+	list__map_foldl2(get_target_timestamp, TouchedTargetFiles,
+			TargetTimestamps, Info1, Info2),
+	( { list__member(error(_), TargetTimestamps) } ->
+		debug_file_msg(TargetFile, "target file does not exist"),
+		{ DepsResult = out_of_date },
+		{ Info = Info2 }
+	;
+		%
+		% Compare the oldest of the timestamps of the touched
+		% files with the timestamps of the dependencies.
+		%
+		list__map_foldl2(get_timestamp_file_timestamp,
+			TouchedTargetFiles, TouchedTargetFileTimestamps,
+			Info2, Info3),
+		list__map_foldl2(get_file_timestamp([dir__this_directory]),
+			TouchedFiles, TouchedFileTimestamps, Info3, Info4),
+		{ MaybeOldestTimestamp0 = list__foldl(find_oldest_timestamp, 
+			TouchedTargetFileTimestamps, ok(newest_timestamp)) },
+		{ MaybeOldestTimestamp = list__foldl(find_oldest_timestamp, 
+			TouchedFileTimestamps, MaybeOldestTimestamp0) },
+
+		get_file_name(TargetFile, TargetFileName, Info4, Info5),
+		check_dependencies(TargetFileName,
+			MaybeOldestTimestamp, DepFilesToMake,
+			DepsResult, Info5, Info)
+	).
+
 %-----------------------------------------------------------------------------%
 
 :- pred build_target(compilation_task_result::in, target_file::in,
@@ -561,11 +584,14 @@
 			make_target_list(TargetModuleNames, FileType) }
 	),
 
-
+	globals__io_get_globals(Globals),
 	list__foldl2(
 	    (pred((TargetModuleName - TargetFileType)::in, TimestampFiles0::in,
 			TimestampFiles1::out, di, uo) is det -->
-		( { TimestampExt = timestamp_extension(TargetFileType) } ->
+		(
+			{ TimestampExt =
+				timestamp_extension(Globals, TargetFileType) }
+		->
 			module_name_to_file_name(TargetModuleName,
 				TimestampExt, no, TimestampFile),
 			{ TimestampFiles1 =
Index: make.util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.7
diff -u -u -r1.7 make.util.m
--- make.util.m	30 May 2002 12:55:01 -0000	1.7
+++ make.util.m	17 Jun 2002 07:34:16 -0000
@@ -146,7 +146,7 @@
 
 	% Find the extension for the timestamp file for the
 	% given target type, if one exists.
-:- func timestamp_extension(module_target_type) = string is semidet.
+:- func timestamp_extension(globals, module_target_type) = string is semidet.
 
 %-----------------------------------------------------------------------------%
 	% Debugging, verbose and error messages.
@@ -395,7 +395,7 @@
 get_timestamp_file_timestamp(ModuleName - FileType,
 		MaybeTimestamp, Info0, Info) -->
 	globals__io_get_globals(Globals),
-	{ TimestampExt = timestamp_extension(FileType) ->
+	{ TimestampExt = timestamp_extension(Globals, FileType) ->
 		Ext = TimestampExt	
 	;
 		Ext = target_extension(Globals, FileType)
@@ -420,7 +420,17 @@
 	),
 	get_file_timestamp(SearchDirs, FileName, MaybeTimestamp, Info0, Info).
 get_dependency_timestamp(target(Target), MaybeTimestamp, Info0, Info) -->
-	get_target_timestamp(Target, MaybeTimestamp, Info0, Info).
+	get_target_timestamp(Target, MaybeTimestamp0, Info0, Info),
+	{ Target = _ - c_header(mih), MaybeTimestamp0 = ok(_) ->
+		% Don't rebuild the `.o' file if an irrelevant part of a
+		% `.mih' file has changed. If a relevant part of a `.mih'
+		% file changed, the interface files of the imported module
+		% must have changed in a way that would force the `.c' and
+		% `.o' files of the current module to be rebuilt.
+		MaybeTimestamp = ok(oldest_timestamp)	
+	;
+		MaybeTimestamp = MaybeTimestamp0
+	}.
 
 get_target_timestamp(ModuleName - FileType, MaybeTimestamp, Info0, Info) -->
 	get_file_name(ModuleName - FileType, FileName, Info0, Info1),
@@ -516,7 +526,15 @@
 get_search_directories(FileType, SearchDirs) -->
 	( { yes(SearchDirOpt) = search_for_file_type(FileType) } ->
 		globals__io_lookup_accumulating_option(SearchDirOpt,
-			SearchDirs)
+			SearchDirs0),
+		% Make sure the current directory is searched
+		% for C headers and libraries.
+		{ SearchDirs =
+			( list__member(dir__this_directory, SearchDirs0) -> 
+				SearchDirs0
+			;
+				[dir__this_directory | SearchDirs0]
+			) }
 	;
 		{ SearchDirs = [dir__this_directory] }
 	).
@@ -535,7 +553,7 @@
 	globals__io_get_globals(Globals),
 	remove_file(ModuleName, target_extension(Globals, FileType),
 		Info0, Info1),
-	( { TimestampExt = timestamp_extension(FileType) } ->
+	( { TimestampExt = timestamp_extension(Globals, FileType) } ->
 		remove_file(ModuleName, TimestampExt, Info1, Info)
 	;
 		{ Info = Info1 }
@@ -591,17 +609,21 @@
 	% Note that we need a timestamp file for `.err' files because
 	% errors are written to the `.err' file even when writing interfaces.
 	% The timestamp is only updated when compiling to target code.
-timestamp_extension(errors) = ".err_date".
-timestamp_extension(private_interface) = ".date0".
-timestamp_extension(long_interface) = ".date".
-timestamp_extension(short_interface) = ".date".
-timestamp_extension(unqualified_short_interface) = ".date3".
-timestamp_extension(intermodule_interface) = ".optdate".
-timestamp_extension(c_code) = ".c_date".
-timestamp_extension(il_code) = ".il_date".
-timestamp_extension(java_code) = ".java_date".
-timestamp_extension(asm_code(non_pic)) = ".s_date".
-timestamp_extension(asm_code(pic)) = ".pic_s_date".
+timestamp_extension(_, errors) = ".err_date".
+timestamp_extension(_, private_interface) = ".date0".
+timestamp_extension(_, long_interface) = ".date".
+timestamp_extension(_, short_interface) = ".date".
+timestamp_extension(_, unqualified_short_interface) = ".date3".
+timestamp_extension(_, intermodule_interface) = ".optdate".
+timestamp_extension(_, c_code) = ".c_date".
+timestamp_extension(Globals, c_header(_)) = Ext :-
+	globals__get_target(Globals, Target),
+	Ext = timestamp_extension(Globals,
+			(Target = asm -> asm_code(non_pic) ; c_code)).
+timestamp_extension(_, il_code) = ".il_date".
+timestamp_extension(_, java_code) = ".java_date".
+timestamp_extension(_, asm_code(non_pic)) = ".s_date".
+timestamp_extension(_, asm_code(pic)) = ".pic_s_date".
 
 :- func search_for_file_type(module_target_type) = maybe(option).
 
--------------------------------------------------------------------------
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