[m-rev.] for review: make mmc --make not symlink target file unnecessarily
Peter Wang
wangp at students.csse.unimelb.edu.au
Wed Apr 11 12:56:27 AEST 2007
Branches: main
When using mmc --make --use-grade-subdirs, don't make a symlink or copy of
the target file to the user directory if the file in the user directory is
already up to date. This avoids bumping the timestamp unnecessarily.
compiler/compile_target_code.m:
Make post_link_make_symlink_or_copy check the timestamp of the file
in the user directory and do nothing if it is the same as the
timestamp of the file to be linked/copied.
Add an output argument to post_link_make_symlink_or_copy to indicate
if the symlink/copy was made.
compiler/make.program_target.m:
Make build_linked_target_2 only write a "Made symlink/copy of ..."
message if the symlink/copy is actually made by
post_link_make_symlink_or_copy.
Also make it warn in the case that there is nothing for mmc --make to
do. This was previously the case only for --no-use-grade-subdirs.
compiler/make.util.m:
Change maybe_symlink_or_copy_linked_target_message to write "Made
symlink/copy ..." rather than "Making symlink/copy ..." as the
message is now written after the fact.
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.105
diff -u -r1.105 compile_target_code.m
--- compiler/compile_target_code.m 2 Mar 2007 02:56:37 -0000 1.105
+++ compiler/compile_target_code.m 11 Apr 2007 02:54:22 -0000
@@ -104,13 +104,16 @@
:- pred link(io.output_stream::in, linked_target_type::in, module_name::in,
list(string)::in, bool::out, io::di, io::uo) is det.
- % post_link_make_symlink_or_copy(TargetType, MainModuleName, Succeeded)
+ % post_link_make_symlink_or_copy(TargetType, MainModuleName, Succeeded,
+ % DidSomething)
%
% If `--use-grade-subdirs' is enabled, link or copy the executable or
- % library into the user's directory after having successfully built it.
+ % library into the user's directory after having successfully built it,
+ % if the target does not exist or is not up-to-date.
%
:- pred post_link_make_symlink_or_copy(io.output_stream::in,
- linked_target_type::in, module_name::in, bool::out, io::di, io::uo) is det.
+ linked_target_type::in, module_name::in, bool::out, bool::out,
+ io::di, io::uo) is det.
% link_module_list(ModulesToLink, FactTableObjFiles, Succeeded):
%
@@ -186,6 +189,7 @@
:- import_module libs.globals.
:- import_module libs.handle_options.
:- import_module libs.options.
+:- import_module libs.timestamp.
:- import_module libs.trace_params.
:- import_module parse_tree.error_util.
:- import_module parse_tree.prog_foreign.
@@ -1460,7 +1464,7 @@
(
LinkSucceeded = yes,
post_link_make_symlink_or_copy(ErrorStream, LinkTargetType,
- ModuleName, Succeeded, !IO)
+ ModuleName, Succeeded, _DidSomething, !IO)
;
LinkSucceeded = no,
Succeeded = no
@@ -1677,7 +1681,7 @@
UseThreadLibs = ( ( Parallel = yes ; GCMethod = gc_mps ) -> yes ; no ).
post_link_make_symlink_or_copy(ErrorStream, LinkTargetType, ModuleName,
- Succeeded, !IO) :-
+ Succeeded, DidSomething, !IO) :-
globals.io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs, !IO),
(
UseGradeSubdirs = yes,
@@ -1700,15 +1704,41 @@
globals.io_set_option(use_subdirs, bool(yes), !IO),
globals.io_set_option(use_grade_subdirs, bool(yes), !IO),
- io.set_output_stream(ErrorStream, OutputStream, !IO),
- % Remove the target of the symlink/copy in case it already exists.
- io.remove_file(UserDirFileName, _, !IO),
- make_symlink_or_copy_file(OutputFileName, UserDirFileName, Succeeded,
- !IO),
- io.set_output_stream(OutputStream, _, !IO)
+ same_timestamp(OutputFileName, UserDirFileName, SameTimestamp, !IO),
+ (
+ SameTimestamp = yes,
+ Succeeded = yes,
+ DidSomething = no
+ ;
+ SameTimestamp = no,
+ io.set_output_stream(ErrorStream, OutputStream, !IO),
+ % Remove the target of the symlink/copy in case it already exists.
+ io.remove_file(UserDirFileName, _, !IO),
+ make_symlink_or_copy_file(OutputFileName, UserDirFileName,
+ Succeeded, !IO),
+ io.set_output_stream(OutputStream, _, !IO),
+ DidSomething = yes
+ )
;
UseGradeSubdirs = no,
- Succeeded = yes
+ Succeeded = yes,
+ DidSomething = no
+ ).
+
+:- pred same_timestamp(string::in, string::in, bool::out, io::di, io::uo)
+ is det.
+
+same_timestamp(FileNameA, FileNameB, SameTimestamp, !IO) :-
+ io.file_modification_time(FileNameA, TimestampResultA, !IO),
+ io.file_modification_time(FileNameB, TimestampResultB, !IO),
+ (
+ TimestampResultA = ok(TimestampA),
+ TimestampResultB = ok(TimestampB),
+ time_t_to_timestamp(TimestampA) = time_t_to_timestamp(TimestampB)
+ ->
+ SameTimestamp = yes
+ ;
+ SameTimestamp = no
).
shared_libraries_supported(Supported, !IO) :-
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.66
diff -u -r1.66 make.program_target.m
--- compiler/make.program_target.m 13 Feb 2007 00:16:55 -0000 1.66
+++ compiler/make.program_target.m 11 Apr 2007 02:54:22 -0000
@@ -398,18 +398,23 @@
Succeeded = no
;
DepsResult = deps_up_to_date,
+ MsgTarget = MainModuleName - linked_target(FileType),
globals.io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs,
!IO),
(
UseGradeSubdirs = yes,
- maybe_symlink_or_copy_linked_target_message(
- MainModuleName - linked_target(FileType), !IO),
- compile_target_code.post_link_make_symlink_or_copy(ErrorStream,
- FileType, MainModuleName, Succeeded, !IO)
+ post_link_make_symlink_or_copy(ErrorStream,
+ FileType, MainModuleName, Succeeded, DidSomething, !IO),
+ (
+ DidSomething = yes,
+ maybe_symlink_or_copy_linked_target_message(MsgTarget, !IO)
+ ;
+ DidSomething = no,
+ maybe_warn_up_to_date_target(MsgTarget, !Info, !IO)
+ )
;
UseGradeSubdirs = no,
- maybe_warn_up_to_date_target(
- MainModuleName - linked_target(FileType), !Info, !IO),
+ maybe_warn_up_to_date_target(MsgTarget, !Info, !IO),
Succeeded = yes
)
;
Index: compiler/make.util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.43
diff -u -r1.43 make.util.m
--- compiler/make.util.m 16 Feb 2007 03:44:55 -0000 1.43
+++ compiler/make.util.m 11 Apr 2007 02:54:22 -0000
@@ -276,7 +276,7 @@
:- pred maybe_warn_up_to_date_target(pair(module_name, target_type)::in,
make_info::in, make_info::out, io::di, io::uo) is det.
- % Write a message "Making symlink/copy of <filename>" if
+ % Write a message "Made symlink/copy of <filename>" if
% `--verbose-message' is set.
%
:- pred maybe_symlink_or_copy_linked_target_message(
@@ -1269,7 +1269,7 @@
maybe_symlink_or_copy_linked_target_message(Target, !IO) :-
verbose_msg(
(pred(!.IO::di, !:IO::uo) is det :-
- io.write_string("Making symlink/copy of ", !IO),
+ io.write_string("Made symlink/copy of ", !IO),
write_module_or_linked_target(Target, !IO),
io.write_string("\n", !IO)
), !IO).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list