[m-rev.] for review: windows compatibility
Ian MacLarty
maclarty at cs.mu.OZ.AU
Tue Sep 6 16:59:11 AEST 2005
For review by anyone.
These changes make it possible to compile Mercury programs without cygwin
(using mingw gcc). Cygwin is still required to build the compiler of course.
mmc also obviously doesn't work since it's a bash script (you have to
set all the appropriate environment variables manually and call
mercury_compile.exe directly).
I was thinking of changing mmc to a C program to make it more portable. Would
there be any objections to this?
Fact tables will not work on windows since the code relies on some unix
commands (like sort).
Estimated hours taken: 10
Branches: main and 0.12
Various changes to make Mercury more compatible with Windows.
configure.in:
Turn off symbolic links when compiling in cygwin.
Previously the configure script checked for certain compiler
names or whether the --mno-cygwin option was passed to gcc,
however this check is not good enough since the user may specify
the mingw version of gcc using the --with-cc option.
compiler/mercury_compile.m:
mdbcomp/trace_counts.m:
Use rstrip to remove trailing newlines, since on Windows there
may be more than one character at the end of each line
(a newline and a carriage return or line feed
- I can't remember which).
compiler/passes_aux.m:
Remove invoke_shell_command since it is not used anywhere and
according to the comment won't work on Windows.
If on windows do not use `2>&1' to redirect standard error since this
doesn't work on windows 98 and 95 (and possibly other versions too).
runtime/mercury_conf_param.h:
Use #ifdef instead of just #if when checking for _WIN32.
Previously this caused Mercury to use `/' as the directory
separator on Windows when it should have used `\'.
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.428
diff -u -r1.428 configure.in
--- configure.in 31 Aug 2005 13:11:29 -0000 1.428
+++ configure.in 5 Sep 2005 08:59:21 -0000
@@ -769,7 +769,7 @@
AC_CHECK_LIB(m, sin, [MATH_LIB=-lm], [MATH_LIB=])
#-----------------------------------------------------------------------------#
-# If we're compiling the compiler with MS Visual C++ or `gcc -mno-cygwin',
+# If we're compiling the compiler on Windows,
# don't use symlinks when installing -- the generated compiler executable
# will not be able to follow them.
#
@@ -780,14 +780,10 @@
LN_S="ln -s"
case "$host" in
*cygwin*)
- case "$CC" in
- # cl is the Microsoft C compiler
- *gcc*-mno-cygwin* | *cl* | *CL*)
- MMC_USE_SYMLINKS_OPT=--no-use-symlinks
- MATH_LIB=
- LN_S=false
- ;;
- esac ;;
+ MMC_USE_SYMLINKS_OPT=--no-use-symlinks
+ MATH_LIB=
+ LN_S=false
+ ;;
esac
AC_SUBST(LN_S)
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.343
diff -u -r1.343 mercury_compile.m
--- compiler/mercury_compile.m 1 Sep 2005 09:06:32 -0000 1.343
+++ compiler/mercury_compile.m 3 Sep 2005 11:54:40 -0000
@@ -722,11 +722,7 @@
io__read_line_as_string(FileResult, !IO),
(
FileResult = ok(Line),
- ( string__remove_suffix(Line, "\n", Arg0) ->
- Arg = Arg0
- ;
- Arg = Line
- ),
+ Arg = string.rstrip(Line),
process_arg(OptionVariables, OptionArgs, Arg, Module,
FactTableObjFileList, !IO),
list__append(Module, !Modules),
Index: compiler/passes_aux.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/passes_aux.m,v
retrieving revision 1.70
diff -u -r1.70 passes_aux.m
--- compiler/passes_aux.m 1 Sep 2005 02:23:13 -0000 1.70
+++ compiler/passes_aux.m 3 Sep 2005 11:58:18 -0000
@@ -172,28 +172,6 @@
% Output the command line with `--verbose-commands'. This should be
% used for commands that may be of interest to the user.
- % invoke_shell_command(ErrorStream, Verbosity, Command, Succeeded)
- %
- % Invoke a shell script. Both standard and error output will go to the
- % specified output stream.
- % XXX Use of this predicate should be avoided -- it requires a Unix shell
- % to be present, so it won't work properly with native Windows.
- %
-:- pred invoke_shell_command(io__output_stream::in,
- command_verbosity::in, string::in, bool::out, io::di, io::uo) is det.
-
- % invoke_shell_command(ErrorStream, Verbosity, Command,
- % ProcessOutput, Succeeded)
- %
- % Invoke a shell script. Both standard and error output will go to the
- % specified output stream after being piped through `ProcessOutput'.
- % XXX Use of this predicate should be avoided -- it requires a Unix shell
- % to be present, so it won't work properly with native Windows.
- %
-:- pred invoke_shell_command(io__output_stream::in,
- command_verbosity::in, string::in, maybe(string)::in, bool::out,
- io::di, io::uo) is det.
-
% invoke_system_command(ErrorStream, Verbosity, Command, Succeeded)
%
% Invoke an executable. Both standard and error output will go to the
@@ -419,15 +397,6 @@
maybe_set_exit_status(yes, !IO).
maybe_set_exit_status(no, !IO) :- io__set_exit_status(1, !IO).
-invoke_shell_command(ErrorStream, Verbosity, Command0, Succeeded, !IO) :-
- invoke_shell_command(ErrorStream, Verbosity, Command0, no, Succeeded, !IO).
-
-invoke_shell_command(ErrorStream, Verbosity, Command0,
- ProcessOutput, Succeeded, !IO) :-
- make_command_string(Command0, forward, Command),
- invoke_system_command(ErrorStream, Verbosity, Command,
- ProcessOutput, Succeeded, !IO).
-
invoke_system_command(ErrorStream, Verbosity, Command, Succeeded, !IO) :-
invoke_system_command(ErrorStream, Verbosity, Command, no, Succeeded, !IO).
@@ -464,6 +433,10 @@
% XXX can't use Bourne shell syntax to redirect on .NET
% XXX the output will go to the wrong place!
CommandRedirected = Command
+ ; use_win32 ->
+ % On windows we can't in general redirect standard error in the
+ % shell.
+ CommandRedirected = Command ++ " > " ++ TmpFile
;
CommandRedirected =
string__append_list([Command, " > ", TmpFile, " 2>&1"])
@@ -493,11 +466,24 @@
),
(
- MaybeProcessOutput = yes(ProcessOutput),
+ % We can't do bash style redirection on .NET.
+ not use_dotnet,
+ MaybeProcessOutput = yes(ProcessOutput)
+ ->
io__make_temp(ProcessedTmpFile, !IO),
- io__call_system_return_signal(
- string__append_list([ProcessOutput, " < ", TmpFile,
- " > ", ProcessedTmpFile, " 2>&1"]),
+
+ ( use_win32 ->
+ % On windows we can't in general redirect standard
+ % error in the shell.
+ ProcessOutputRedirected = string__append_list(
+ [ProcessOutput, " < ", TmpFile, " > ",
+ ProcessedTmpFile])
+ ;
+ ProcessOutputRedirected = string__append_list(
+ [ProcessOutput, " < ", TmpFile, " > ",
+ ProcessedTmpFile, " 2>&1"])
+ ),
+ io__call_system_return_signal(ProcessOutputRedirected,
ProcessOutputResult, !IO),
io__remove_file(TmpFile, _, !IO),
(
@@ -526,7 +512,6 @@
ProcessOutputSucceeded = no
)
;
- MaybeProcessOutput = no,
ProcessOutputSucceeded = yes,
ProcessedTmpFile = TmpFile
),
Index: mdbcomp/trace_counts.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/trace_counts.m,v
retrieving revision 1.8
diff -u -r1.8 trace_counts.m
--- mdbcomp/trace_counts.m 27 Aug 2005 09:42:04 -0000 1.8
+++ mdbcomp/trace_counts.m 3 Sep 2005 11:54:40 -0000
@@ -281,8 +281,8 @@
io.read_line_as_string(Stream, ReadResult, !IO),
(
ReadResult = ok(Line),
- % Remove the trailing newline:
- FileName = string.left(Line, string.length(Line) - 1),
+ % Remove trailing whitespace:
+ FileName = string.rstrip(Line),
(
% Ignore blank lines.
FileName = ""
@@ -355,7 +355,7 @@
io__read_line_as_string(IdReadResult, !IO),
(
IdReadResult = ok(FirstLine),
- FirstLine = trace_count_file_id
+ string.rstrip(FirstLine) = trace_count_file_id
->
promise_only_solution_io(read_trace_counts_from_cur_stream,
ReadResult, !IO)
@@ -376,7 +376,7 @@
:- func trace_count_file_id = string.
-trace_count_file_id = "Mercury trace counts file\n".
+trace_count_file_id = "Mercury trace counts file".
:- pred read_trace_counts_from_cur_stream(read_trace_counts_result::out,
io::di, io::uo) is cc_multi.
@@ -385,7 +385,7 @@
io__read_line_as_string(IdResult, !IO),
(
IdResult = ok(IdStr),
- string.append(IdStrNoNL, "\n", IdStr),
+ IdStrNoNL = string.rstrip(IdStr),
string_to_file_type(IdStrNoNL, FileType)
->
try_io(read_trace_counts_setup(map__init), Result, !IO),
@@ -625,6 +625,7 @@
Res = ok,
io.set_output_stream(FileStream, OldOutputStream, !IO),
io.write_string(trace_count_file_id, !IO),
+ io.nl(!IO),
write_trace_counts(FileType, TraceCounts, !IO),
io.set_output_stream(OldOutputStream, _, !IO),
io.close_output(FileStream, !IO)
Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.83
diff -u -r1.83 mercury_conf_param.h
--- runtime/mercury_conf_param.h 29 Aug 2005 15:44:27 -0000 1.83
+++ runtime/mercury_conf_param.h 3 Sep 2005 11:54:40 -0000
@@ -820,7 +820,7 @@
** MR_BROKEN_ST_INO - Is the st_ino field of `struct stat' junk.
** Windows doesn't fill in this field correctly.
*/
-#if _WIN32
+#ifdef _WIN32
#define MR_WIN32
#define MR_WIN32_GETSYSTEMINFO
#define MR_WIN32_VIRTUAL_ALLOC
--------------------------------------------------------------------------
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