[m-dev.] for review: add make_command_string

Peter Ross peter.ross at miscrit.be
Tue Feb 20 21:08:22 AEDT 2001


Hi,


===================================================================


Estimated hours taken: 8

Fix a bug where fact tables weren't working for MSVC version of the
compiler.

compiler/passes_aux.m:
    Add a new predicate make_command_string which will optionally wrap a
    shell string with a call to sh -c, if the shell string is being
    constructed in a win32 environment.

compiler/fact_table.m:
compiler/llds_out.m:
compiler/modules.m:
    Call the make_command_string predicate.


Index: fact_table.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/fact_table.m,v
retrieving revision 1.38
diff -u -r1.38 fact_table.m
--- fact_table.m	2000/12/07 12:59:06	1.38
+++ fact_table.m	2001/02/20 10:02:06
@@ -1134,9 +1134,9 @@
 	{ map__lookup(ProcTable0, ProcID, ProcInfo0) },
 	io__output_stream_name(Stream, FileName),
 	io__close_output(Stream),
-	{ string__format(
-	    "sort -o %s %s && cut -d'~' -f1 %s | sort -cu >/dev/null 2>&1",
-	    [s(FileName), s(FileName), s(FileName)], Command) },
+	{ make_command_string(string__format(
+		"sort -o %s %s && echo hi | sort -cu >/dev/null 2>&1",
+		[s(FileName), s(FileName)]), double, Command) },
 	globals__io_lookup_bool_option(verbose, Verbose),
 	maybe_write_string(Verbose, "% Invoking system command `"),
 	maybe_write_string(Verbose, Command),
@@ -1350,8 +1350,8 @@
 
 maybe_append_data_table(no, _, _) --> [].
 maybe_append_data_table(yes, OutputFileName, DataFileName) -->
-	{ string__format("cat %s >>%s", 
-		[s(DataFileName), s(OutputFileName)], Command) },
+	{ make_command_string(string__format("cat %s >>%s", 
+		[s(DataFileName), s(OutputFileName)]), forward, Command) },
 	globals__io_lookup_bool_option(verbose, Verbose),
 	maybe_write_string(Verbose, "% Invoking system command `"),
 	maybe_write_string(Verbose, Command),
Index: llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.172
diff -u -r1.172 llds_out.m
--- llds_out.m	2001/02/05 00:46:42	1.172
+++ llds_out.m	2001/02/20 10:02:07
@@ -258,7 +258,7 @@
 
 :- import_module rtti, rtti_out, layout, layout_out, options, trace_params.
 :- import_module exprn_aux, prog_util, prog_out, hlds_pred.
-:- import_module export, mercury_to_mercury, modules.
+:- import_module export, mercury_to_mercury, modules, passes_aux.
 :- import_module c_util.
 
 :- import_module int, char, string, std_util.
@@ -4418,8 +4418,9 @@
 :- pred make_directory(string::in, io__state::di, io__state::uo) is det.
 
 make_directory(DirName) -->
-	{ string__format("[ -d %s ] || mkdir -p %s", [s(DirName), s(DirName)],
-		Command) },
+	{ make_command_string(string__format(
+		"[ -d %s ] || mkdir -p %s", [s(DirName), s(DirName)]),
+		forward, Command) },
 	io__call_system(Command, _Result).
 
 %-----------------------------------------------------------------------------%
Index: modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.151
diff -u -r1.151 modules.m
--- modules.m	2001/02/12 11:39:58	1.151
+++ modules.m	2001/02/20 10:02:08
@@ -792,8 +792,9 @@
 	( { dir__this_directory(DirName) } ->
 		[]
 	;
-		{ string__format("[ -d %s ] || mkdir -p %s",
-			[s(DirName), s(DirName)], Command) },
+		{ make_command_string(string__format(
+			"[ -d %s ] || mkdir -p %s",
+			[s(DirName), s(DirName)]), forward, Command) },
 		io__call_system(Command, _Result)
 	).
 
Index: passes_aux.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/passes_aux.m,v
retrieving revision 1.37
diff -u -r1.37 passes_aux.m
--- passes_aux.m	2000/08/08 04:44:47	1.37
+++ passes_aux.m	2001/02/20 10:02:08
@@ -146,18 +146,9 @@
 
 :- pred report_error(string::in, io__state::di, io__state::uo) is det.
 
-	% Invoke a shell script.
-:- pred invoke_shell_command(string::in, bool::out,
-	io__state::di, io__state::uo) is det.
-
-	% Invoke an executable.
-:- pred invoke_system_command(string::in, bool::out,
-	io__state::di, io__state::uo) is det.
-
 :- pred maybe_report_sizes(module_info::in, io__state::di, io__state::uo)
 	is det.
 
-
 :- pred report_pred_proc_id(module_info, pred_id, proc_id, 
 		maybe(prog_context), prog_context, io__state, io__state).
 :- mode report_pred_proc_id(in, in, in, in, out, di, uo) is det.
@@ -168,6 +159,24 @@
 	
 %-----------------------------------------------------------------------------%
 
+:- type quote_char
+	--->	forward		% '
+	;	double.		% "
+
+	% Invoke a shell script.
+:- pred invoke_shell_command(string::in, bool::out,
+	io__state::di, io__state::uo) is det.
+
+	% Invoke an executable.
+:- pred invoke_system_command(string::in, bool::out,
+	io__state::di, io__state::uo) is det.
+
+	% Make a command string, which needs to be invoked in a shell
+	% environment.
+:- pred make_command_string(string::in, quote_char::in, string::out) is det.
+
+%-----------------------------------------------------------------------------%
+
 :- implementation.
 
 :- import_module options, globals, hlds_out, prog_out, mode_util.
@@ -404,13 +413,7 @@
 	).
 
 invoke_shell_command(Command0, Succeeded) -->
-	{
-		use_win32
-	->
-		string__append_list(["sh -c '", Command0, " '"], Command)
-	;
-		Command = Command0
-	},
+	{ make_command_string(Command0, forward, Command) },
 	invoke_system_command(Command, Succeeded).
 
 invoke_system_command(Command, Succeeded) -->
@@ -433,6 +436,20 @@
 	;	
 		report_error("unable to invoke system command."),
 		{ Succeeded = no }
+	).
+
+make_command_string(String0, QuoteType, String) :-
+	( use_win32 ->
+		(
+			QuoteType = forward,
+			Quote = " '"
+		;
+			QuoteType = double,
+			Quote = " \""
+		),
+		string__append_list(["sh -c ", Quote, String0, Quote], String)
+	;
+		String = String0
 	).
 
 	% Are we compiling in a win32 environment?

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list