[m-rev.] for review: change behaviour of mmc --make --use-grade-subdirs
Peter Wang
wangp at students.cs.mu.OZ.AU
Thu Feb 2 14:30:28 AEDT 2006
Estimated hours taken: 2
Branches: main
`mmc --make --use-grade-subdirs <linked-target>' makes symlinks/copies of the
linked target into the current directory, but doesn't do so if the linked
target is already up to date. This patch makes it always make the
symlink/copy, so that it is easy to switch between two or more grades even if
no source files were modified.
compiler/compile_target_code.m:
Separate out the code to make symlinks/copies of linked targets from
the `link' predicate into a predicate `post_link_make_symlink_or_copy'.
Move `shared_libraries_supported' from make.program_target.m into
compile_target_code.m.
compiler/make.program_target.m:
Call `post_link_make_symlink_or_copy' if `--use-grade-subdirs' is
enabled, and the linked target is otherwise up-to-date.
Write out a message in `--verbose-make' mode.
Conform to the move of `shared_libraries_supported'.
compiler/make.util.m:
Add a predicate `maybe_symlink_or_copy_linked_target_message'.
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.78
diff -u -r1.78 compile_target_code.m
--- compiler/compile_target_code.m 5 Dec 2005 02:17:20 -0000 1.78
+++ compiler/compile_target_code.m 2 Feb 2006 03:11:23 -0000
@@ -101,6 +101,14 @@
:- 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)
+ %
+ % If `--use-grade-subdirs' is enabled, link or copy the executable or
+ % library into the user's directory after having successfully built it.
+ %
+:- 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.
+
% link_module_list(ModulesToLink, FactTableObjFiles, Succeeded):
%
% The elements of ModulesToLink are the output of
@@ -110,6 +118,13 @@
:- pred link_module_list(list(string)::in, list(string)::in, bool::out,
io::di, io::uo) is det.
+ % shared_libraries_supported(SharedLibsSupported, !IO)
+ %
+ % Return whether or not shared libraries are supported on the current
+ % platform.
+ %
+:- pred shared_libraries_supported(bool::out, io::di, io::uo) is det.
+
% get_object_code_type(TargetType, PIC):
%
% Work out whether we should be generating position-independent
@@ -1132,19 +1147,11 @@
globals__io_lookup_bool_option(statistics, Stats, !IO),
maybe_write_string(Verbose, "% Linking...\n", !IO),
- globals__io_lookup_string_option(library_extension, LibExt, !IO),
- globals__io_lookup_string_option(shared_library_extension, SharedLibExt,
- !IO),
- globals__io_lookup_string_option(executable_file_extension, ExeExt, !IO),
+ link_output_filename(LinkTargetType, ModuleName, _Ext, OutputFileName, !IO),
( LinkTargetType = static_library ->
- Ext = LibExt,
- module_name_to_lib_file_name("lib", ModuleName, LibExt, yes,
- OutputFileName, !IO),
create_archive(ErrorStream, OutputFileName, yes, ObjectsList,
LinkSucceeded, !IO)
; LinkTargetType = java_archive ->
- Ext = ".jar",
- module_name_to_file_name(ModuleName, Ext, yes, OutputFileName, !IO),
create_java_archive(ErrorStream, ModuleName, OutputFileName,
ObjectsList, LinkSucceeded, !IO)
;
@@ -1166,16 +1173,7 @@
AllowUndef = no,
globals__io_lookup_string_option(
linker_error_undefined_flag, UndefOpt, !IO)
- ),
- Ext = SharedLibExt,
- module_name_to_lib_file_name("lib", ModuleName, Ext, yes,
- OutputFileName, !IO)
- ;
- LinkTargetType = static_library,
- unexpected(this_file, "compile_target_code__link")
- ;
- LinkTargetType = java_archive,
- unexpected(this_file, "compile_target_code__link")
+ )
;
LinkTargetType = executable,
CommandOpt = link_executable_command,
@@ -1185,9 +1183,13 @@
ThreadFlagsOpt = linker_thread_flags,
DebugFlagsOpt = linker_debug_flags,
TraceFlagsOpt = linker_trace_flags,
- UndefOpt = "",
- Ext = ExeExt,
- module_name_to_file_name(ModuleName, Ext, yes, OutputFileName, !IO)
+ UndefOpt = ""
+ ;
+ LinkTargetType = static_library,
+ unexpected(this_file, "compile_target_code__link")
+ ;
+ LinkTargetType = java_archive,
+ unexpected(this_file, "compile_target_code__link")
),
% Should the executable be stripped?
@@ -1260,9 +1262,10 @@
% Set up the runtime library path.
globals__io_lookup_bool_option(shlib_linker_use_install_name,
UseInstallName, !IO),
+ shared_libraries_supported(SharedLibsSupported, !IO),
(
UseInstallName = no,
- SharedLibExt \= LibExt,
+ SharedLibsSupported = yes,
( Linkage = "shared"
; LinkTargetType = shared_library
)
@@ -1355,31 +1358,39 @@
)
),
maybe_report_stats(Stats, !IO),
- globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs, !IO),
(
LinkSucceeded = yes,
- UseGradeSubdirs = yes
- ->
- % Link/copy the executable into the user's directory.
- globals__io_set_option(use_subdirs, bool(no), !IO),
- globals__io_set_option(use_grade_subdirs, bool(no), !IO),
- ( LinkTargetType = executable ->
- module_name_to_file_name(ModuleName, Ext, no, UserDirFileName, !IO)
- ;
- module_name_to_lib_file_name("lib", ModuleName, Ext, no,
- UserDirFileName, !IO)
- ),
- globals__io_set_option(use_subdirs, bool(yes), !IO),
- globals__io_set_option(use_grade_subdirs, bool(yes), !IO),
+ post_link_make_symlink_or_copy(ErrorStream, LinkTargetType,
+ ModuleName, Succeeded, !IO)
+ ;
+ LinkSucceeded = no,
+ Succeeded = 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)
+ % XXX this is very similar to `make.util.linked_target_file_name/5'.
+ %
+:- pred link_output_filename(linked_target_type::in, module_name::in,
+ string::out, string::out, io::di, io::uo) is det.
+
+link_output_filename(LinkTargetType, ModuleName, Ext, OutputFileName, !IO) :-
+ (
+ LinkTargetType = static_library,
+ globals__io_lookup_string_option(library_extension, Ext, !IO),
+ module_name_to_lib_file_name("lib", ModuleName, Ext, yes,
+ OutputFileName, !IO)
+ ;
+ LinkTargetType = shared_library,
+ globals__io_lookup_string_option(shared_library_extension, Ext, !IO),
+ module_name_to_lib_file_name("lib", ModuleName, Ext, yes,
+ OutputFileName, !IO)
+ ;
+ LinkTargetType = java_archive,
+ Ext = ".jar",
+ module_name_to_file_name(ModuleName, Ext, yes, OutputFileName, !IO)
;
- Succeeded = LinkSucceeded
+ LinkTargetType = executable,
+ globals__io_lookup_string_option(executable_file_extension, Ext, !IO),
+ module_name_to_file_name(ModuleName, Ext, yes, OutputFileName, !IO)
).
% Find the standard Mercury libraries, and the system
@@ -1555,6 +1566,44 @@
globals__io_get_gc_method(GCMethod, !IO),
UseThreadLibs = ( ( Parallel = yes ; GCMethod = mps ) -> yes ; no ).
+post_link_make_symlink_or_copy(ErrorStream, LinkTargetType, ModuleName,
+ Succeeded, !IO) :-
+ globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs, !IO),
+ (
+ UseGradeSubdirs = yes,
+ link_output_filename(LinkTargetType, ModuleName,
+ Ext, OutputFileName, !IO),
+ % Link/copy the executable into the user's directory.
+ globals__io_set_option(use_subdirs, bool(no), !IO),
+ globals__io_set_option(use_grade_subdirs, bool(no), !IO),
+ ( LinkTargetType = executable ->
+ module_name_to_file_name(ModuleName, Ext, no, UserDirFileName, !IO)
+ ;
+ module_name_to_lib_file_name("lib", ModuleName, Ext, no,
+ UserDirFileName, !IO)
+ ),
+ 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)
+ ;
+ UseGradeSubdirs = no,
+ Succeeded = yes
+ ).
+
+shared_libraries_supported(Supported, !IO) :-
+ % XXX This seems to be the standard way to check whether shared libraries
+ % are supported but it's not very nice.
+ globals__io_lookup_string_option(library_extension, LibExt, !IO),
+ globals__io_lookup_string_option(shared_library_extension, SharedLibExt,
+ !IO),
+ Supported = (if LibExt \= SharedLibExt then yes else no).
+
%-----------------------------------------------------------------------------%
:- pred process_link_library(list(dir_name)::in, string::in, string::out,
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.37
diff -u -r1.37 make.program_target.m
--- compiler/make.program_target.m 25 Jan 2006 03:27:35 -0000 1.37
+++ compiler/make.program_target.m 2 Feb 2006 03:12:35 -0000
@@ -334,9 +334,20 @@
Succeeded = no
;
DepsResult = up_to_date,
- maybe_warn_up_to_date_target(MainModuleName - linked_target(FileType),
- !Info, !IO),
- Succeeded = yes
+ 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)
+ ;
+ UseGradeSubdirs = no,
+ maybe_warn_up_to_date_target(
+ MainModuleName - linked_target(FileType), !Info, !IO),
+ Succeeded = yes
+ )
;
DepsResult = out_of_date,
maybe_make_linked_target_message(OutputFileName, !IO),
@@ -529,7 +540,8 @@
InitSucceeded = yes,
make_linked_target(MainModuleName - static_library,
StaticSucceeded, !Info, !IO),
- shared_libraries_supported(SharedLibsSupported, !IO),
+ compile_target_code__shared_libraries_supported(
+ SharedLibsSupported, !IO),
(
StaticSucceeded = yes,
(
@@ -565,16 +577,6 @@
)
).
-:- pred shared_libraries_supported(bool::out, io::di, io::uo) is det.
-
-shared_libraries_supported(Supported, !IO) :-
- % XXX This seems to be the standard way to check whether shared libraries
- % are supported but it's not very nice.
- globals__io_lookup_string_option(library_extension, LibExt, !IO),
- globals__io_lookup_string_option(shared_library_extension, SharedLibExt,
- !IO),
- Supported = (if LibExt \= SharedLibExt then yes else no).
-
%-----------------------------------------------------------------------------%
:- pred install_library(module_name::in, bool::out,
Index: compiler/make.util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.29
diff -u -r1.29 make.util.m
--- compiler/make.util.m 25 Jan 2006 03:27:35 -0000 1.29
+++ compiler/make.util.m 2 Feb 2006 03:17:50 -0000
@@ -254,6 +254,12 @@
:- 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
+ % `--verbose-message' is set.
+ %
+:- pred maybe_symlink_or_copy_linked_target_message(
+ pair(module_name, target_type)::in, io::di, io::uo) is det.
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -964,25 +970,13 @@
io__write_string(TargetFile, !IO),
io__write_string("'.\n", !IO).
-maybe_warn_up_to_date_target(Target @ (ModuleName - FileType), !Info, !IO) :-
+maybe_warn_up_to_date_target(Target, !Info, !IO) :-
globals__io_lookup_bool_option(warn_up_to_date, Warn, !IO),
(
Warn = yes,
( set__member(Target, !.Info ^ command_line_targets) ->
io__write_string("** Nothing to be done for `", !IO),
- (
- FileType = module_target(ModuleTargetType),
- write_target_file(ModuleName - ModuleTargetType, !IO)
- ;
- FileType = linked_target(LinkedTargetType),
- linked_target_file_name(ModuleName, LinkedTargetType, FileName,
- !IO),
- io__write_string(FileName, !IO)
- ;
- FileType = misc_target(_),
- unexpected(this_file,
- "maybe_warn_up_to_date_target: misc_target")
- ),
+ write_module_or_linked_target(Target, !IO),
io__write_string("'.\n", !IO)
;
true
@@ -993,6 +987,32 @@
!:Info = !.Info ^ command_line_targets :=
set__delete(!.Info ^ command_line_targets, Target).
+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),
+ write_module_or_linked_target(Target, !IO),
+ io__write_string("\n", !IO)
+ ), !IO).
+
+:- pred write_module_or_linked_target(pair(module_name, target_type)::in,
+ io::di, io::uo) is det.
+
+write_module_or_linked_target(ModuleName - FileType, !IO) :-
+ (
+ FileType = module_target(ModuleTargetType),
+ write_target_file(ModuleName - ModuleTargetType, !IO)
+ ;
+ FileType = linked_target(LinkedTargetType),
+ linked_target_file_name(ModuleName, LinkedTargetType, FileName,
+ !IO),
+ io__write_string(FileName, !IO)
+ ;
+ FileType = misc_target(_),
+ unexpected(this_file,
+ "maybe_warn_up_to_date_target: misc_target")
+ ).
+
%-----------------------------------------------------------------------------%
:- func this_file = string.
--------------------------------------------------------------------------
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