[m-rev.] for review: Mmake support for Java shell script
Fergus Henderson
fjh at cs.mu.OZ.AU
Sat Feb 7 18:21:00 AEDT 2004
Estimated hours taken: 1
Branches: main
More improves to the Mmake support for Java: handle "linking",
i.e. generate the shell script which invokes the Java interpreter.
compiler/modules.m:
After generating the dependencies,
if Target = java then call create_java_shell_script.
compiler/make.program_target.m:
compiler/modules.m:
Move the definition of create_java_shell_script from
make.program_target.m to modules.m, so that it can be
used from generate_dependencies in modules.m.
(It needs to go in modules.m rather than make.program_target.m
because modules.m should not depend on make.*.m. Also
it can't go in ml_backend.java_util since modules.m
should not depend on ml_backend.*.)
Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.288
diff -u -d -r1.288 modules.m
--- compiler/modules.m 7 Feb 2004 05:59:57 -0000 1.288
+++ compiler/modules.m 7 Feb 2004 07:16:49 -0000
@@ -788,6 +788,14 @@
:- pred check_for_no_exports(item_list, module_name, io__state, io__state).
:- mode check_for_no_exports(in, in, di, uo) is det.
+ % create_java_shell_script:
+ % Create a shell script with the same name as the given module
+ % to invoke Java with the appropriate options on the class of the
+ % same name.
+
+:- pred create_java_shell_script(module_name::in, bool::out,
+ io__state::di, io__state::uo) is det.
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -3666,6 +3674,19 @@
generate_dependencies_write_d_files(DepsList,
IntDepsRel, ImplDepsRel, IndirectDepsRel,
IndirectOptDepsRel, TransOptDepsOrdering, DepsMap)
+ ),
+ %
+ % For Java, the main target is actually a shell script which will
+ % set CLASSPATH appropriately and invoke java on the appropriate
+ % .class file. Rather than generating an Mmake rule to build this
+ % file when it is needed, we just generate this file "mmake depend"
+ % time, since that is simpler and probably more efficient anyway.
+ %
+ globals__io_get_target(Target),
+ ( { Target = java } ->
+ create_java_shell_script(ModuleName, _Succeeded)
+ ;
+ []
).
/*
@@ -7157,6 +7178,63 @@
)
;
[]
+ ).
+
+%-----------------------------------------------------------------------------%
+
+create_java_shell_script(MainModuleName, Succeeded) -->
+ % XXX Extension should be ".bat" on Windows
+ { Extension = "" },
+ module_name_to_file_name(MainModuleName, Extension, no, FileName),
+
+ globals__io_lookup_bool_option(verbose, Verbose),
+ maybe_write_string(Verbose, "% Generating shell script `" ++
+ FileName ++ "':\n"),
+
+ module_name_to_file_name(MainModuleName, ".class", no, ClassFileName),
+ { DirName = dir.dirname(ClassFileName) },
+
+ % XXX PathSeparator should be ";" on Windows
+ { PathSeparator = ":" },
+ % XXX The correct classpath needs to be set somewhere.
+ % It should take the form:
+ % DirName:<path>/mer_std.jar:<path>/mer_std.runtime.jar:.
+ % Currently this variable is empty, which causes problems, so
+ % we prepend the .class files' directory and the current CLASSPATH.
+ globals__io_lookup_accumulating_option(java_classpath, Java_Incl_Dirs0),
+ { Java_Incl_Dirs = [DirName, "$CLASSPATH" | Java_Incl_Dirs0] },
+ { ClassPath = string.join_list(PathSeparator, Java_Incl_Dirs) },
+
+ globals__io_lookup_string_option(java_interpreter, Java),
+ module_name_to_file_name(MainModuleName, "", no, Name_No_Extn),
+
+ io__open_output(FileName, OpenResult),
+ (
+ { OpenResult = ok(ShellScript) },
+ % XXX On Windows we should output a .bat file instead
+ io__write_string(ShellScript, "#!/bin/sh\n"),
+ io__write_string(ShellScript, "CLASSPATH=" ++ ClassPath ++ " "),
+ io__write_string(ShellScript, Java ++ " "),
+ io__write_string(ShellScript, Name_No_Extn ++ "\n"),
+ io__close_output(ShellScript),
+ io__call_system("chmod a+x " ++ FileName, ChmodResult),
+ (
+ { ChmodResult = ok(Status) },
+ { Status = 0 ->
+ Succeeded = yes
+ ;
+ error("chmod exit status != 0"),
+ Succeeded = no
+ }
+ ;
+ { ChmodResult = error(Message) },
+ { error(io__error_message(Message)) },
+ { Succeeded = no }
+ )
+ ;
+ { OpenResult = error(Message) },
+ { error(io__error_message(Message)) },
+ { Succeeded = no }
).
%-----------------------------------------------------------------------------%
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.23
diff -u -d -r1.23 make.program_target.m
--- compiler/make.program_target.m 2 Feb 2004 02:45:51 -0000 1.23
+++ compiler/make.program_target.m 7 Feb 2004 06:28:35 -0000
@@ -405,69 +405,6 @@
),
globals__io_set_option(link_objects, accumulating(LinkObjects)).
- % create_java_shell_script:
- % Create a shell script with the same name as the given module
- % to invoke Java with the appropriate options on the class of the
- % same name.
-
-:- pred create_java_shell_script(module_name::in, bool::out,
- io__state::di, io__state::uo) is det.
-
-create_java_shell_script(MainModuleName, Succeeded) -->
- % XXX Extension should be ".bat" on Windows
- { Extension = "" },
- module_name_to_file_name(MainModuleName, Extension, no, FileName),
-
- globals__io_lookup_bool_option(verbose, Verbose),
- maybe_write_string(Verbose, "% Generating shell script `" ++
- FileName ++ "':\n"),
-
- module_name_to_file_name(MainModuleName, ".class", no, ClassFileName),
- { DirName = dir.dirname(ClassFileName) },
-
- % XXX PathSeparator should be ";" on Windows
- { PathSeparator = ":" },
- % XXX The correct classpath needs to be set somewhere.
- % It should take the form:
- % DirName:<path>/mer_std.jar:<path>/mer_std.runtime.jar:.
- % Currently this variable is empty, which causes problems, so
- % we prepend the .class files' directory and the current CLASSPATH.
- globals__io_lookup_accumulating_option(java_classpath, Java_Incl_Dirs0),
- { Java_Incl_Dirs = [DirName, "$CLASSPATH" | Java_Incl_Dirs0] },
- { join_string_list(Java_Incl_Dirs, "", "", PathSeparator, ClassPath) },
-
- globals__io_lookup_string_option(java_interpreter, Java),
- module_name_to_file_name(MainModuleName, "", no, Name_No_Extn),
-
- io__open_output(FileName, OpenResult),
- (
- { OpenResult = ok(ShellScript) },
- % XXX On Windows we should output a .bat file instead
- io__write_string(ShellScript, "#!/bin/sh\n"),
- io__write_string(ShellScript, "CLASSPATH=" ++ ClassPath ++ " "),
- io__write_string(ShellScript, Java ++ " "),
- io__write_string(ShellScript, Name_No_Extn ++ "\n"),
- io__close_output(ShellScript),
- io__call_system("chmod a+x " ++ FileName, ChmodResult),
- (
- { ChmodResult = ok(Status) },
- { Status = 0 ->
- Succeeded = yes
- ;
- error("chmod exit status != 0"),
- Succeeded = no
- }
- ;
- { ChmodResult = error(Message) },
- { error(io__error_message(Message)) },
- { Succeeded = no }
- )
- ;
- { OpenResult = error(Message) },
- { error(io__error_message(Message)) },
- { Succeeded = no }
- ).
-
% join_string_list(Strings, Prefix, Suffix, Serarator, Result)
%
% Appends the strings in the list `Strings' together into the
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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