[m-rev.] diff: mmc --make java

Peter Wang novalazy at gmail.com
Thu Apr 30 14:37:46 AEST 2009


Branches: main

Make `mmc --make' work for Java grade.

compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
        Make `mmc --make' know to generate `.class' files.

compiler/compile_target_code.m:
        Pass "-sourcepath Mercury/javas" to javac when using subdirectories.

compiler/module_cmds.m:
        Make the shell script we generate to invoke `java' pass command line
        arguments through to the user program.  `exec' the java process.

library/Mmakefile:
        Use $(ALL_JAVACFLAGS) when compiling standard library modules so
        $(EXTRA_JAVACFLAGS) has its effect.

diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 5205b34..c07670a 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -908,24 +908,29 @@ compile_java_file(ErrorStream, JavaFile,
Succeeded, !IO) :-
         (
             UseGradeSubdirs = yes,
             grade_directory_component(Globals, Grade),
-            DirName = "Mercury"/Grade/FullArch/"Mercury"/"classs"
+            SourceDirName = "Mercury"/Grade/FullArch/"Mercury"/"javas",
+            DestDirName = "Mercury"/Grade/FullArch/"Mercury"/"classs"
         ;
             UseGradeSubdirs = no,
-            DirName = "Mercury"/"classs"
+            SourceDirName = "Mercury"/"javas",
+            DestDirName = "Mercury"/"classs"
         ),
         % Javac won't create the destination directory for class files,
         % so we need to do it.
-        dir.make_directory(DirName, _, !IO),
-        % Set destination directory for class files.
-        DestDir = "-d " ++ DirName ++ " "
+        dir.make_directory(DestDirName, _, !IO),
+        % Set directories for source and class files.
+        DirOpts = string.append_list([
+            "-sourcepath ", SourceDirName, " ",
+            "-d ", DestDirName, " "
+        ])
     ;
         UseSubdirs = no,
-        DestDir = ""
+        DirOpts = ""
     ),

     % Be careful with the order here!  Some options may override others.
     % Also be careful that each option is separated by spaces.
-    string.append_list([JavaCompiler, " ", InclOpt, DestDir,
+    string.append_list([JavaCompiler, " ", InclOpt, DirOpts,
         Target_DebugOpt, JAVAFLAGS, " ", JavaFile], Command),
     invoke_system_command(ErrorStream, cmd_verbose_commands, Command,
         Succeeded, !IO).
diff --git a/compiler/make.dependencies.m b/compiler/make.dependencies.m
index a8e5817..8e37b9f 100644
--- a/compiler/make.dependencies.m
+++ b/compiler/make.dependencies.m
@@ -391,6 +391,8 @@ target_dependencies(_, module_target_il_asm) =
     ]).
 target_dependencies(Globals, module_target_java_code) =
         compiled_code_dependencies(Globals).
+target_dependencies(Globals, module_target_java_class_code) =
+        compiled_code_dependencies(Globals).
 target_dependencies(Globals, module_target_erlang_header) =
         target_dependencies(Globals, module_target_erlang_code).
 target_dependencies(Globals, module_target_erlang_code) =
diff --git a/compiler/make.m b/compiler/make.m
index 41ad48a..ed93ee2 100644
--- a/compiler/make.m
+++ b/compiler/make.m
@@ -222,6 +222,7 @@
     ;       module_target_il_code
     ;       module_target_il_asm
     ;       module_target_java_code
+    ;       module_target_java_class_code
     ;       module_target_erlang_header
     ;       module_target_erlang_code
     ;       module_target_erlang_beam_code
diff --git a/compiler/make.module_target.m b/compiler/make.module_target.m
index f8d05f7..042d20f 100644
--- a/compiler/make.module_target.m
+++ b/compiler/make.module_target.m
@@ -811,6 +811,8 @@ compilation_task(_, module_target_il_asm) =
         target_code_to_object_code(non_pic) - [].
 compilation_task(_, module_target_java_code) =
     process_module(task_compile_to_target_code) - ["--java-only"].
+compilation_task(_, module_target_java_class_code) =
+        target_code_to_object_code(non_pic) - [].
 compilation_task(Globals, module_target_erlang_header) =
         compilation_task(Globals, module_target_erlang_code).
 compilation_task(_, module_target_erlang_code) =
@@ -1120,6 +1122,7 @@ target_type_to_pic(TargetType) = Result :-
         ; TargetType = module_target_il_code
         ; TargetType = module_target_il_asm
         ; TargetType = module_target_java_code
+        ; TargetType = module_target_java_class_code
         ; TargetType = module_target_erlang_header
         ; TargetType = module_target_erlang_code
         ; TargetType = module_target_erlang_beam_code
diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index 57d70b6..13842e3 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -170,8 +170,7 @@ make_linked_target_2(LinkedTargetFile, _,
Succeeded, !Info, !IO) :-
         ;
             CompilationTarget = target_java,
             IntermediateTargetType = module_target_java_code,
-            % XXX Whoever finishes the Java backend can fill this in.
-            ObjectTargetType = module_target_object_code(non_pic)
+            ObjectTargetType = module_target_java_class_code
         ;
             CompilationTarget = target_x86_64,
             sorry(this_file, "mmc --make and target x86_64")
diff --git a/compiler/make.util.m b/compiler/make.util.m
index b79f935..0345470 100644
--- a/compiler/make.util.m
+++ b/compiler/make.util.m
@@ -1227,6 +1227,7 @@ target_extension(_, module_target_il_code) = yes(".il").
     % XXX ".exe" if the module contains main.
 target_extension(_, module_target_il_asm) = yes(".dll").
 target_extension(_, module_target_java_code) = yes(".java").
+target_extension(_, module_target_java_class_code) = yes(".class").
 target_extension(_, module_target_erlang_header) = yes(".hrl").
 target_extension(_, module_target_erlang_code) = yes(".erl").
 target_extension(_, module_target_erlang_beam_code) = yes(".beam").
@@ -1335,6 +1336,7 @@
module_target_to_file_name_maybe_search(ModuleName, TargetType, MkDir,
Search,
             ; TargetType = module_target_il_code
             ; TargetType = module_target_intermodule_interface
             ; TargetType = module_target_java_code
+            ; TargetType = module_target_java_class_code
             ; TargetType = module_target_long_interface
             ; TargetType = module_target_object_code(_)
             ; TargetType = module_target_private_interface
@@ -1413,6 +1415,7 @@ search_for_file_type(module_target_c_code) = no.
 search_for_file_type(module_target_il_code) = no.
 search_for_file_type(module_target_il_asm) = no.
 search_for_file_type(module_target_java_code) = no.
+search_for_file_type(module_target_java_class_code) = no.
 search_for_file_type(module_target_erlang_header) =
         yes(erlang_include_directory).
 search_for_file_type(module_target_erlang_code) = no.
@@ -1450,6 +1453,7 @@ is_target_grade_or_arch_dependent(Target) = IsDependent :-
         ; Target = module_target_il_code
         ; Target = module_target_il_asm
         ; Target = module_target_java_code
+        ; Target = module_target_java_class_code
         ; Target = module_target_erlang_code
         ; Target = module_target_erlang_beam_code
         ; Target = module_target_erlang_header
@@ -1711,6 +1715,9 @@ module_target_type_to_nonce(Type) = X :-
     ;
         Type = module_target_track_flags,
         X = 24
+    ;
+        Type = module_target_java_class_code,
+        X = 25
     ).

 :- func pic_to_nonce(pic) = int.
diff --git a/compiler/module_cmds.m b/compiler/module_cmds.m
index 7df9df1..60d0c0e 100644
--- a/compiler/module_cmds.m
+++ b/compiler/module_cmds.m
@@ -679,9 +679,10 @@ create_java_shell_script(MainModuleName, Succeeded, !IO) :-
         OpenResult = ok(ShellScript),
         % XXX On Windows we should output a .bat file instead
         io.write_string(ShellScript, "#!/bin/sh\n", !IO),
-        io.write_string(ShellScript, "CLASSPATH=" ++ ClassPath ++ " ", !IO),
-        io.write_string(ShellScript, Java ++ " ", !IO),
-        io.write_string(ShellScript, Name_No_Extn ++ "\n", !IO),
+        io.write_string(ShellScript, "CLASSPATH=" ++ ClassPath ++ "\n", !IO),
+        io.write_string(ShellScript, "export CLASSPATH\n", !IO),
+        io.write_string(ShellScript, "exec " ++ Java ++ " ", !IO),
+        io.write_string(ShellScript, Name_No_Extn ++ " \"$@\"\n", !IO),
         io.close_output(ShellScript, !IO),
         io.call_system("chmod a+x " ++ FileName, ChmodResult, !IO),
         (
diff --git a/library/Mmakefile b/library/Mmakefile
index 4ea2323..07f0b94 100644
--- a/library/Mmakefile
+++ b/library/Mmakefile
@@ -259,7 +259,7 @@ JAVAS = ` echo $($(STD_LIB_NAME).javas) | sed \
 # otherwise javac doesn't handle cyclic dependencies between different
 # modules.
 classes: javas java_symlinks
-	$(JAVAC) $(JAVACFLAGS) $(JAVAS)
+	$(JAVAC) $(ALL_JAVACFLAGS) $(JAVAS)

 # javac expects to find the sources for symbols named mercury.* in
 # files mercury/*, and likewise for symbols named mercury.runtime.*
--------------------------------------------------------------------------
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