[m-rev.] for review: ssdebug grade changes

Peter Wang novalazy at gmail.com
Fri May 14 15:31:34 AEST 2010


Branches: main, 10.04

Lift some assumptions that the only Java and Erlang grades are `java' and
`erlang'.

Finally use `--force-disable-ssdebug' instead of `--no-ssdb' to disable the
source-to-source debugging tranformation where required.  The latter is
incorrect as it changes the grade, which disrupts the install path with `mmc
--make'.

library/Mmakefile:
scripts/Mercury.config.in:
scripts/Mmake.vars.in:
        Remove the variable `INSTALL_JAVA_LIBRARY_DIR' as it assumes only one
        Java grade is possible.

        Don't use default `--java-classpath' options to add Mercury standard
        libraries to the Java class path, for the same reason.

compiler/module_cmds.m:
        Add a predicate to return the Mercury standard libraries needed for a
        Java program as they are no longer listed in Mercury.config.

        Add the Mercury standard libraries when creating the shell script to
        launch Java programs.

compiler/compile_target_code.m:
        Add the Mercury standard libraries when calling the Java compiler.

compiler/make.program_target.m:
        Don't hard code `java' and `erlang' grades when installing library
        grade files.

browser/MDB_FLAGS.in:
library/LIB_FLAGS.in:
mdbcomp/MDBCOMP_FLAGS.in:
ssdb/SSDB_FLAGS.in:
        Use `--force-disable-ssdebug' to disable the transform.

compiler/module_imports.m:
        Don't implicitly import the `ssdb' module if `--force-disable-ssdebug'
        is enabled.

compiler/handle_options.m:
        Reset the `source_to_source_debug' option on encountering a `--grade'
        option.

diff --git a/browser/MDB_FLAGS.in b/browser/MDB_FLAGS.in
index f7eb5b8..3d67dbd 100644
--- a/browser/MDB_FLAGS.in
+++ b/browser/MDB_FLAGS.in
@@ -5,7 +5,7 @@
 --no-mercury-stdlib-dir
 --no-shlib-linker-use-install-name
 --force-disable-tracing
---no-ssdb
+--force-disable-ssdebug
 --no-libgrade
 --generate-mmc-deps
 -I../library
diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index fbc23d9..9724aa3 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -925,17 +925,9 @@ compile_java_files(ErrorStream, JavaFiles, Globals, Succeeded, !IO) :-
     globals.lookup_accumulating_option(Globals, java_flags, JavaFlagsList),
     join_string_list(JavaFlagsList, "", "", " ", JAVAFLAGS),
 
-    globals.lookup_accumulating_option(Globals, java_classpath,
-        Java_Incl_Dirs),
-    (
-        ( dir.use_windows_paths
-        ; io.have_cygwin
-        )
-    ->
-        PathSeparator = ";"
-    ;
-        PathSeparator = ":"
-    ),
+    get_mercury_std_libs_for_java(Globals, MercuryStdLibs),
+    globals.lookup_accumulating_option(Globals, java_classpath, UserClasspath),
+    Java_Incl_Dirs = MercuryStdLibs ++ UserClasspath,
     % We prepend the current CLASSPATH (if any) to preserve the accumulating
     % nature of this variable.
     get_env_classpath(EnvClasspath, !IO),
@@ -944,7 +936,7 @@ compile_java_files(ErrorStream, JavaFiles, Globals, Succeeded, !IO) :-
     ;
         ClassPathList = [EnvClasspath | Java_Incl_Dirs]
     ),
-    ClassPath = string.join_list(PathSeparator, ClassPathList),
+    ClassPath = string.join_list(java_classpath_separator, ClassPathList),
     ( ClassPath = "" ->
         InclOpt = ""
     ;
@@ -997,6 +989,19 @@ compile_java_files(ErrorStream, JavaFiles, Globals, Succeeded, !IO) :-
     invoke_system_command(Globals, ErrorStream, cmd_verbose_commands, Command,
         Succeeded, !IO).
 
+:- func java_classpath_separator = string.
+
+java_classpath_separator = PathSeparator :-
+    (
+        ( dir.use_windows_paths
+        ; io.have_cygwin
+        )
+    ->
+        PathSeparator = ";"
+    ;
+        PathSeparator = ":"
+    ).
+
 %-----------------------------------------------------------------------------%
 
 assemble(ErrorStream, PIC, ModuleName, Globals, Succeeded, !IO) :-
@@ -1951,6 +1956,7 @@ link_exe_or_shared_lib(Globals, ErrorStream, LinkTargetType, ModuleName,
     % libraries needed by them.
     % Return the empty string if --mercury-standard-library-directory
     % is not set.
+    % NOTE: changes here may require changes to get_mercury_std_libs_for_java.
     %
 :- pred get_mercury_std_libs(globals::in, linked_target_type::in, string::out)
     is det.
@@ -2101,7 +2107,7 @@ get_mercury_std_libs(Globals, TargetType, StdLibs) :-
         MaybeStdlibDir = no,
         StdLibs = ""
     ).
-    
+
     % Pass either `-llib' or `PREFIX/lib/GRADE/liblib.a', depending on
     % whether we are linking with static or shared Mercury libraries.
     %
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index dfab9b2..2817952 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -2919,6 +2919,7 @@ grade_start_values(minimal_model_debug - bool(no)).
 grade_start_values(pic_reg - bool(no)).
 grade_start_values(exec_trace - bool(no)).
 grade_start_values(decl_debug - bool(no)).
+grade_start_values(source_to_source_debug - bool(no)).
 grade_start_values(extend_stacks_when_needed - bool(no)).
 
 :- pred split_grade_string(string::in, list(string)::out) is semidet.
diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index 4ee8281..adaa07d 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -1571,13 +1571,13 @@ install_library_grade_files(Globals, LinkSucceeded0, GradeDir, ModuleName,
 
         globals.lookup_string_option(Globals, install_prefix, Prefix),
 
-        ( GradeDir = "java" ->
-            GradeLibDir = Prefix/"lib"/"mercury"/"lib"/"java",
+        ( string.prefix(GradeDir, "java") ->
+            GradeLibDir = Prefix/"lib"/"mercury"/"lib"/GradeDir,
             install_file(Globals, JarFileName, GradeLibDir, LibsSucceeded,
                 !IO),
             InitSucceeded = yes
-        ; GradeDir = "erlang" ->
-            GradeLibDir = Prefix/"lib"/"mercury"/"lib"/"erlang",
+        ; string.prefix(GradeDir, "erlang") ->
+            GradeLibDir = Prefix/"lib"/"mercury"/"lib"/GradeDir,
             % Our "Erlang archives" are actually directories.
             install_directory(Globals, ErlangArchiveFileName, GradeLibDir,
                 LibsSucceeded, !IO),
diff --git a/compiler/module_cmds.m b/compiler/module_cmds.m
index e7b45cb..e135699 100644
--- a/compiler/module_cmds.m
+++ b/compiler/module_cmds.m
@@ -140,6 +140,12 @@
 :- pred create_java_shell_script(globals::in, module_name::in, bool::out,
     io::di, io::uo) is det.
 
+    % Return the standard Mercury libraries needed for a Java program.
+    % Return the empty list if --mercury-standard-library-directory
+    % is not set.
+    %
+:- pred get_mercury_std_libs_for_java(globals::in, list(string)::out) is det.
+
     % Given a list .class files, return the list of .class files that should be
     % passed to `jar'.  This is required because nested classes are in separate
     % files which we don't know about, so we have to scan the directory to
@@ -679,11 +685,12 @@ create_java_shell_script(Globals, MainModuleName, Succeeded, !IO) :-
     get_class_dir_name(Globals, ClassDirName),
     string.replace_all(ClassDirName, "\\", "/", ClassDirNameUnix),
 
+    get_mercury_std_libs_for_java(Globals, MercuryStdLibs),
     globals.lookup_accumulating_option(Globals, java_classpath,
-        Java_Incl_Dirs0),
+        UserClasspath),
     % We prepend the .class files' directory and the current CLASSPATH.
-    Java_Incl_Dirs = ["$DIR/" ++ ClassDirNameUnix,
-        "$CLASSPATH" | Java_Incl_Dirs0],
+    Java_Incl_Dirs = ["$DIR/" ++ ClassDirNameUnix] ++ MercuryStdLibs ++
+        ["$CLASSPATH" | UserClasspath],
     ClassPath = string.join_list("${SEP}", Java_Incl_Dirs),
 
     globals.lookup_string_option(Globals, java_interpreter, Java),
@@ -728,6 +735,30 @@ create_java_shell_script(Globals, MainModuleName, Succeeded, !IO) :-
         Succeeded = no
     ).
 
+    % NOTE: changes here may require changes to get_mercury_std_libs.
+get_mercury_std_libs_for_java(Globals, !:StdLibs) :-
+    !:StdLibs = [],
+    globals.lookup_maybe_string_option(Globals,
+        mercury_standard_library_directory, MaybeStdlibDir),
+    (
+        MaybeStdlibDir = yes(StdLibDir),
+        grade_directory_component(Globals, GradeDir),
+        % Source-to-source debugging libraries.
+        globals.lookup_bool_option(Globals, source_to_source_debug,
+            SourceDebug),
+        (
+            SourceDebug = yes,
+            list.cons(StdLibDir/"lib"/GradeDir/"mer_ssdb.jar", !StdLibs),
+            list.cons(StdLibDir/"lib"/GradeDir/"mer_mdbcomp.jar", !StdLibs)
+        ;
+            SourceDebug = no
+        ),
+        list.cons(StdLibDir/"lib"/GradeDir/"mer_std.jar", !StdLibs),
+        list.cons(StdLibDir/"lib"/GradeDir/"mer_rt.jar", !StdLibs)
+    ;
+        MaybeStdlibDir = no
+    ).
+
 list_class_files_for_jar(Globals, MainClassFiles, ClassSubDir,
         ListClassFiles, !IO) :-
     globals.lookup_bool_option(Globals, use_subdirs, UseSubdirs),
diff --git a/compiler/module_imports.m b/compiler/module_imports.m
index f21d3cd..e7ec8fa 100644
--- a/compiler/module_imports.m
+++ b/compiler/module_imports.m
@@ -563,11 +563,14 @@ add_implicit_imports(Items, Globals, !ImportDeps, !UseDeps) :-
         UseRegions = no
     ),
     globals.lookup_bool_option(Globals, source_to_source_debug, SSDB),
+    globals.lookup_bool_option(Globals, force_disable_ssdebug, DisableSSDB),
     (
         SSDB = yes,
+        DisableSSDB = no
+    ->
         !:UseDeps = [mercury_ssdb_builtin_module | !.UseDeps]
     ;
-        SSDB = no
+        true
     ).
 
 :- pred items_need_imports(list(item)::in,
diff --git a/library/LIB_FLAGS.in b/library/LIB_FLAGS.in
index 338cb2c..bd857cd 100644
--- a/library/LIB_FLAGS.in
+++ b/library/LIB_FLAGS.in
@@ -8,7 +8,7 @@
 --generate-mmc-deps
 --no-shlib-linker-use-install-name
 --trace minimum
---no-ssdb
+--force-disable-ssdebug
 --no-libgrade
 --c-include-directory ../boehm_gc
 --c-include-directory ../boehm_gc/include
diff --git a/library/Mmakefile b/library/Mmakefile
index f6a6af3..e1187d6 100644
--- a/library/Mmakefile
+++ b/library/Mmakefile
@@ -268,8 +268,8 @@ copy_java_runtime_files:
 	[ -d jmercury/runtime ] || cp -r ../java/runtime jmercury
 
 install_mer_rt: $(RT_LIB_NAME).jar
-	mkdir -p $(INSTALL_JAVA_LIBRARY_DIR)
-	cp $(RT_LIB_NAME).jar $(INSTALL_JAVA_LIBRARY_DIR)
+	mkdir -p $(INSTALL_PREFIX)/lib/mercury/lib/$(GRADE)
+	cp $(RT_LIB_NAME).jar $(INSTALL_PREFIX)/lib/mercury/lib/$(GRADE)
 
 else
 
diff --git a/mdbcomp/MDBCOMP_FLAGS.in b/mdbcomp/MDBCOMP_FLAGS.in
index 0177634..e04d3e0 100644
--- a/mdbcomp/MDBCOMP_FLAGS.in
+++ b/mdbcomp/MDBCOMP_FLAGS.in
@@ -4,7 +4,7 @@
 --no-warn-inferred-erroneous
 --no-mercury-stdlib-dir
 --generate-mmc-deps
---no-ssdb
+--force-disable-ssdebug
 --no-libgrade
 --no-shlib-linker-use-install-name
 -I../library
diff --git a/scripts/Mercury.config.in b/scripts/Mercury.config.in
index 12b8a8e..2c3b627 100644
--- a/scripts/Mercury.config.in
+++ b/scripts/Mercury.config.in
@@ -34,9 +34,6 @@ MERCURY_ERLANG_INTERPRETER=@ERL@
 # be used by the substitution for SHARED_LIBS.
 MATH_LIB=$(MERCURY_MATH_LIB)
 
-# This needed for Java classpath.
-INSTALL_JAVA_LIBRARY_DIR=$(MERCURY_STDLIB_DIR)/lib/java
-
 # If you change these, you will also need to change the files indicated in
 # scripts/c2init.in.
 RT_LIB_NAME=mer_rt
@@ -67,11 +64,6 @@ DEFAULT_MCFLAGS=\
 		--cflags-for-gotos "@CFLAGS_FOR_GOTOS@" \
 		--cflags-for-pic "@CFLAGS_FOR_PIC@" \
 		--c-flag-to-name-object-file "@OBJFILE_OPT@" \
-		--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(RT_LIB_NAME).jar" \
-		--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(STD_LIB_NAME).jar" \
-		--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/mer_mdbcomp.jar" \
-		--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/mer_browser.jar" \
-		--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/mer_ssdb.jar" \
 		--java-flags "@JAVAC_FLAGS_FOR_HEAP_SIZE@" \
 		--object-file-extension ". at OBJ_SUFFIX@" \
 		--pic-object-file-extension ". at EXT_FOR_PIC_OBJECTS@" \
diff --git a/scripts/Mmake.vars.in b/scripts/Mmake.vars.in
index 4922837..d9f5436 100644
--- a/scripts/Mmake.vars.in
+++ b/scripts/Mmake.vars.in
@@ -690,7 +690,6 @@ FINAL_INSTALL_PREFIX	= @prefix@
 INSTALL_BINDIR		= $(INSTALL_PREFIX)/bin
 INSTALL_LIBDIR		= $(INSTALL_PREFIX)/lib/mercury
 FINAL_INSTALL_LIBDIR	= $(FINAL_INSTALL_PREFIX)/lib/mercury
-INSTALL_JAVA_LIBRARY_DIR= $(INSTALL_PREFIX)/lib/mercury/lib/java
 INSTALL_INFO_DIR	= $(INSTALL_PREFIX)/info
 INSTALL_DVI_DIR		= $(INSTALL_PREFIX)/lib/mercury/doc
 INSTALL_TEXT_DIR	= $(INSTALL_PREFIX)/lib/mercury/doc
diff --git a/ssdb/SSDB_FLAGS.in b/ssdb/SSDB_FLAGS.in
index 72d8925..be3a571 100644
--- a/ssdb/SSDB_FLAGS.in
+++ b/ssdb/SSDB_FLAGS.in
@@ -5,7 +5,7 @@
 --no-mercury-stdlib-dir
 --no-shlib-linker-use-install-name
 --force-disable-tracing
---no-ssdb
+--force-disable-ssdebug
 --no-libgrade
 --generate-mmc-deps
 -I../library

--------------------------------------------------------------------------
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