[m-rev.] for review: document `--use-grade-subdirs'

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



Estimated hours taken: 1.5
Branches: main

Improve the handling of `--use-grade-subdirs' so that it can
be documented.

compiler/compile_target_code.m:
	With `--use-grade-subdirs', link or copy executables
	into the user's directory.

compiler/make.program_target.m:
compiler/modules.m:
	Move code to create a symlink into modules.m, next to
	the code to create directories (all of this should really
	go in the library).

	Add a predicate to copy a file (which should also go
	in the library).

NEWS:
compiler/options.m:
doc/user_guide.texi:
	Document `--use-grade-subdirs'.


Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.274
diff -u -u -r1.274 NEWS
--- NEWS	22 Oct 2002 13:10:33 -0000	1.274
+++ NEWS	30 Oct 2002 04:03:00 -0000
@@ -318,6 +318,11 @@
   is a list of the names of all of the source files.  If the names of the
   source files all match the contained module names, `mmc -f' need not be run.
 
+* There is a new `--use-grade-subdirs' option which is similar to
+  `--use-subdirs', but allows multiple grades to be built in a
+  directory at the same time.  `--use-grade-subdirs' does not
+  work with Mmake.
+
 * We've added a new compiler option `--warn-non-tail-recursion', which
   causes the compiler to issue a warning about any directly recursive
   call that is not a tail call.
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.23
diff -u -u -r1.23 compile_target_code.m
--- compiler/compile_target_code.m	1 Sep 2002 06:04:58 -0000	1.23
+++ compiler/compile_target_code.m	29 Oct 2002 13:59:32 -0000
@@ -150,7 +150,7 @@
 :- import_module ll_backend__llds_out.	% for llds_out__make_init_name and
 					% llds_out__make_rl_data_name
 
-:- import_module char, dir, int, require, string.
+:- import_module char, dir, getopt, int, require, string.
 
 il_assemble(ErrorStream, ModuleName,
 			HasMain, Succeeded) -->
@@ -905,8 +905,7 @@
 	    { Result = no }
 	).
 
-link(ErrorStream, LinkTargetType, ModuleName,
-		ObjectsList, Succeeded) -->
+link(ErrorStream, LinkTargetType, ModuleName, ObjectsList, Succeeded) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	globals__io_lookup_bool_option(statistics, Stats),
 
@@ -981,8 +980,53 @@
 			LDFlags, " ", LinkLibraries],
 			LinkCmd) },
 		invoke_shell_command(ErrorStream, verbose_commands,
-			LinkCmd, Succeeded),
-		maybe_report_stats(Stats)
+			LinkCmd, LinkSucceeded),
+		maybe_report_stats(Stats),
+		globals__io_lookup_bool_option(use_grade_subdirs,
+			UseGradeSubdirs),
+		(
+			{ LinkSucceeded = yes },
+			{ LinkTargetType = executable },
+			{ UseGradeSubdirs = yes }
+		->
+			% Link/copy the executable into the user's
+			% directory. We don't do this for libraries
+			% because in general they shouldn't be used
+			% without being installed.
+			globals__io_set_option(use_grade_subdirs, bool(no)),
+			module_name_to_file_name(ModuleName, "", no,
+				UserDirExeName),
+			globals__io_set_option(use_grade_subdirs,
+				bool(UseGradeSubdirs)),
+
+			make_symlink(OutputFileName, UserDirExeName,
+				SymlinkSucceeded),
+			( { SymlinkSucceeded = yes } ->
+				{ Succeeded = yes }
+			;
+				copy_file(OutputFileName, UserDirExeName,
+					CopyRes),
+				( 
+					{ CopyRes = ok },
+					{ Succeeded = yes }
+				;
+					{ CopyRes = error(CopyError) },
+					{ Succeeded = no },
+					io__progname_base("mercury_compile",
+						ProgName),
+					io__write_string(ErrorStream,
+						ProgName),
+					io__write_string(": can't copy "),
+					io__write_string(OutputFileName),
+					io__write_string(
+					" into the current directory:"),
+					io__write_string(
+						io__error_message(CopyError))
+				)
+			)
+		;
+			{ Succeeded = LinkSucceeded }
+		)
 	).
 
 :- pred create_archive(io__output_stream, file_name, list(file_name),
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 13:59:32 -0000
@@ -835,15 +835,6 @@
 	{ LinkName = Subdir/(Ext ++ "s") },
 	make_symlink("..", LinkName, Result).
 
-:- pred make_symlink(string::in, string::in, bool::out,
-		io__state::di, io__state::uo) is det.
-
-make_symlink(LinkTarget, LinkName, Result) -->
-	io__output_stream(ErrorStream),
-	{ string__format("rm -f %s && ln -s %s %s",
-		[s(LinkName), s(LinkTarget), s(LinkName)], Command) },
-	invoke_shell_command(ErrorStream, verbose, Command, Result).
-
 %-----------------------------------------------------------------------------%
 
 	% Clean up grade-dependent files.
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.249
diff -u -u -r1.249 modules.m
--- compiler/modules.m	24 Oct 2002 10:06:14 -0000	1.249
+++ compiler/modules.m	29 Oct 2002 13:59:32 -0000
@@ -672,21 +672,35 @@
 	% Call the shell script mercury_update_interface to update the
 	% interface file FileName if it has changed.
 
-:- pred update_interface(string, bool, io__state, io__state).
+:- pred update_interface(file_name, bool, io__state, io__state).
 :- mode update_interface(in, out, di, uo) is det.
 
-:- pred update_interface(string, io__state, io__state).
+:- pred update_interface(file_name, io__state, io__state).
 :- mode update_interface(in, di, uo) is det.
 
 	% make_directory(Dir, Succeeded)
 	%
 	% Make the directory Dir and all its parents.
-:- pred make_directory(string, bool, io__state, io__state).
+	% XXX This belongs in the library.
+:- pred make_directory(dir_name, bool, io__state, io__state).
 :- mode make_directory(in, out, di, uo) is det.
 
-:- pred make_directory(string, io__state, io__state).
+:- pred make_directory(dir_name, io__state, io__state).
 :- mode make_directory(in, di, uo) is det.
 
+	% make_symlink(LinkTarget, LinkName, Succeeded)
+	%
+	% Make a LinkName a symlink pointing to LinkTarget.
+	% XXX This belongs in the library.
+:- pred make_symlink(file_name, file_name, bool, io__state, io__state).
+:- mode make_symlink(in, in, out, di, uo) is det.
+
+	% copy_file(Source, Destination, Succeeded).
+	%
+	% XXX This belongs in the library.
+:- pred copy_file(file_name, file_name, io__res, io__state, io__state).
+:- mode copy_file(in, in, out, di, uo) is det.
+
 %-----------------------------------------------------------------------------%
 
 	% Check whether a particular `pragma' declaration is allowed
@@ -1054,6 +1068,37 @@
 			[s(DirName), s(DirName)], Command) },
 		io__output_stream(ErrorStream),
 		invoke_shell_command(ErrorStream, verbose, Command, Result)
+	).
+
+make_symlink(LinkTarget, LinkName, Result) -->
+	io__output_stream(ErrorStream),
+	{ string__format("rm -f %s && ln -s %s %s",
+		[s(LinkName), s(LinkTarget), s(LinkName)], Command) },
+	invoke_shell_command(ErrorStream, verbose, Command, Result).
+
+copy_file(Source, Destination, Res) -->
+	io__open_input(Source, SourceRes),
+	(
+		{ SourceRes = ok(InputStream) },
+		io__open_output(Destination, DestRes),
+		(
+			{ DestRes = ok(OutputStream) },
+			% XXX Depending on file size it may be
+			% faster to call the system's cp command.
+			io__input_stream_foldl_io(
+				(pred(Char::in, di, uo) is det -->
+					io__write_char(Char)
+				),
+				Res),
+			io__close_input(InputStream),
+			io__close_output(OutputStream)
+		;
+			{ DestRes = error(Error) },
+			{ Res = error(Error) }
+		)
+	;
+		{ SourceRes = error(Error) },
+		{ Res = error(Error) }
 	).
 
 :- pred make_file_name(dir_name, bool, bool, file_name, string,
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 13:59:32 -0000
@@ -3643,14 +3643,13 @@
 		"\tdirectories given by `--intermod-directory'.",
 		"--use-subdirs",
 		"\tGenerate intermediate files in a `Mercury' subdirectory,",
-		"\trather than generating them in the current directory."
-
-		% `--use-grade-subdirs' is not documented because it
-		% is only intended for use in library installation
-		% with `mmc --make' (it doesn't work at all with Mmake).
-		% Documenting it would require documenting (and setting
-		% in stone) the layout of the `Mercury' directory, which
-		% is probably a bad idea.
+		"\trather than generating them in the current directory.",
+		"--use-grade-subdirs",
+		"\tGenerate intermediate files in a `Mercury' subdirectory,",
+		"\tlaid out so that multiple grades can be built simultaneously.",
+		"\tExecutables will be symlinked or copied into the current",
+		"\tdirectory.",
+		"\t`--use-grade-subdirs' does not work with Mmake."
 	]).
 
 :- pred options_help_misc(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 13:59:32 -0000
@@ -6188,6 +6188,17 @@
 Create intermediate files in a @file{Mercury} subdirectory,
 rather than in the current directory.
 
+ at item --use-grade-subdirs
+ at findex --use-grade-subdirs
+ at cindex File names
+ at cindex Directories
+ at cindex Subdirectories
+ at cindex @file{Mercury} subdirectory
+Generate intermediate files in a @file{Mercury} subdirectory,
+laid out so that multiple grades can be built simultaneously.
+Executables will be symlinked or copied into the current
+directory.
+ at samp{--use-grade-subdirs} does not work with Mmake.
 @end table
 
 @node Miscellaneous 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