[m-rev.] diff: fixes for using java grade on windows

Peter Wang novalazy at gmail.com
Tue Sep 29 17:46:46 AEST 2009


Branches: main

Fix a couple of problem with using the java grade on Windows.

compiler/compile_target_code.m:
        Use ";" as the separator when constructing the classpath argument to
        the Java compiler on Windows.

compiler/module_cmds.m:
        In the shell script we generate for Java programs, never generate
        paths with backslashes as directory separators.

        Make the script detect if it is running on Windows (by checking for a
        WINDIR environment variable).  In that case use ";" as classpath
        separators.

diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 43dfda3..83a5429 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -895,13 +895,20 @@ compile_java_files(ErrorStream, JavaFiles, Succeeded, !IO) :-
 
     globals.io_lookup_accumulating_option(java_classpath, Java_Incl_Dirs,
         !IO),
-    % XXX PathSeparator should be ";" on Windows
-    PathSeparator = ":",
-    % We prepend the current CLASSPATH to preserve the accumulating
+    ( dir.use_windows_paths ->
+        PathSeparator = ";"
+    ;
+        PathSeparator = ":"
+    ),
+    % We prepend the current CLASSPATH (if any) to preserve the accumulating
     % nature of this variable.
     get_env_classpath(EnvClasspath, !IO),
-    join_string_list([EnvClasspath|Java_Incl_Dirs], "", "",
-        PathSeparator, ClassPath),
+    ( EnvClasspath = "" ->
+        ClassPathList = Java_Incl_Dirs
+    ;
+        ClassPathList = [EnvClasspath | Java_Incl_Dirs]
+    ),
+    ClassPath = string.join_list(PathSeparator, ClassPathList),
     ( ClassPath = "" ->
         InclOpt = ""
     ;
diff --git a/compiler/module_cmds.m b/compiler/module_cmds.m
index e841f83..d2f7770 100644
--- a/compiler/module_cmds.m
+++ b/compiler/module_cmds.m
@@ -662,8 +662,9 @@ use_win32 :-
 % Java command-line utilities.
 %
 
+    % XXX We should also create a ".bat" on Windows.
+    %
 create_java_shell_script(MainModuleName, Succeeded, !IO) :-
-    % XXX Extension should be ".bat" on Windows
     Extension = "",
     module_name_to_file_name(MainModuleName, Extension, do_not_create_dirs,
         FileName, !IO),
@@ -672,15 +673,16 @@ create_java_shell_script(MainModuleName, Succeeded, !IO) :-
     maybe_write_string(Verbose, "% Generating shell script `" ++
         FileName ++ "'...\n", !IO),
 
+    % In shell scripts always use / separators, even on Windows.
     get_class_dir_name(ClassDirName, !IO),
+    string.replace_all(ClassDirName, "\\", "/", ClassDirNameUnix),
 
-    % XXX PathSeparator should be ";" on Windows
-    PathSeparator = ":",
     globals.io_lookup_accumulating_option(java_classpath, Java_Incl_Dirs0,
         !IO),
     % We prepend the .class files' directory and the current CLASSPATH.
-    Java_Incl_Dirs = ["$DIR/" ++ ClassDirName, "$CLASSPATH" | Java_Incl_Dirs0],
-    ClassPath = string.join_list(PathSeparator, Java_Incl_Dirs),
+    Java_Incl_Dirs = ["$DIR/" ++ ClassDirNameUnix,
+        "$CLASSPATH" | Java_Incl_Dirs0],
+    ClassPath = string.join_list("${SEP}", Java_Incl_Dirs),
 
     globals.io_lookup_string_option(java_interpreter, Java, !IO),
     mangle_sym_name_for_java(MainModuleName, module_qual, ".", ClassName),
@@ -690,10 +692,13 @@ create_java_shell_script(MainModuleName, Succeeded, !IO) :-
     io.open_output(FileName, OpenResult, !IO),
     (
         OpenResult = ok(ShellScript),
-        % XXX On Windows we should output a .bat file instead
         list.foldl(io.write_string(ShellScript), [
             "#!/bin/sh\n",
             "DIR=${0%/*}\n",
+            "case $WINDIR in\n",
+            "   '') SEP=':' ;;\n",
+            "   *)  SEP=';' ;;\n",
+            "esac\n",
             "CLASSPATH=", ClassPath, "\n",
             "export CLASSPATH\n",
             "JAVA=${JAVA:-", Java, "}\n",
--------------------------------------------------------------------------
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