[m-rev.] diff: batch file launchers for the erlang grade
Julien Fischer
juliensf at csse.unimelb.edu.au
Fri Jan 7 15:55:41 AEDT 2011
This is still work-in-progress - I am comitting it now to make it easier
for me to test it on different machines.
-----------------
Branches: main, 11.01
Generate batch file launchers for the Erlang grade on Windows.
compiler/module_cmds.m:
Generate a launcher batch file for programs compiled in the Erlang
grade on Windows.
Use io.write_strings instead of folding io.write_string in a couple
of spots.
Julien.
Index: module_cmds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/module_cmds.m,v
retrieving revision 1.17
diff -u -r1.17 module_cmds.m
--- module_cmds.m 4 Jan 2011 03:59:42 -0000 1.17
+++ module_cmds.m 7 Jan 2011 04:48:38 -0000
@@ -716,7 +716,7 @@
globals.lookup_string_option(Globals, java_interpreter, Java),
mangle_sym_name_for_java(MainModuleName, module_qual, ".", ClassName),
- list.foldl(io.write_string(Stream), [
+ io.write_strings(Stream, [
"#!/bin/sh\n",
"DIR=${0%/*}\n",
"case $WINDIR in\n",
@@ -746,7 +746,7 @@
globals.lookup_string_option(Globals, java_interpreter, Java),
mangle_sym_name_for_java(MainModuleName, module_qual, ".", ClassName),
- list.foldl(io.write_string(Stream), [
+ io.write_strings(Stream, [
"@echo off\n",
"rem Automatically generated by the Mercury compiler.\n",
"setlocal\n",
@@ -924,7 +924,7 @@
(
MaybeStdLibDir = yes(StdLibDir),
StdLibBeamsPath = StdLibDir/"lib"/GradeDir/"libmer_std.beams",
- SearchStdLib = pa_option(yes, StdLibBeamsPath),
+ SearchStdLib = pa_option(yes, yes, StdLibBeamsPath),
% Added by elds_to_erlang.m
MainFunc = "mercury__main_wrapper"
;
@@ -944,12 +944,12 @@
LinkLibrariesList0, LinkLibrariesList, !IO),
globals.lookup_string_option(Globals, erlang_interpreter, Erlang),
- SearchLibs = string.append_list(list.map(pa_option(yes),
+ SearchLibs = string.append_list(list.map(pa_option(yes, yes),
list.sort_and_remove_dups(LinkLibrariesList))),
% XXX main_2_p_0 is not necessarily in the main module itself and
% could be in a submodule. We don't handle that yet.
- SearchProg = pa_option(no, """$DIR""/" ++ quote_arg(BeamDirName)),
+ SearchProg = pa_option(yes, no, """$DIR""/" ++ quote_arg(BeamDirName)),
% Write the shell script.
% Note we need to use '-extra' instead of '--' for "-flag" and
@@ -967,8 +967,61 @@
:- pred write_erlang_batch_file(globals::in, module_name::in,
io.text_output_stream::in, io::di, io::uo) is det.
-write_erlang_batch_file(_Globals, _MainModuleName, _Stream, _, _) :-
- sorry($pred, "Batch file launchers NYI for Erlang graade.").
+write_erlang_batch_file(Globals, MainModuleName, Stream, !IO) :-
+ % XXX It should be possible to avoid some of the code duplication with
+ % the Unix version above.
+ globals.lookup_string_option(Globals, erlang_object_file_extension,
+ BeamExt),
+ module_name_to_file_name(Globals, MainModuleName, BeamExt,
+ do_not_create_dirs, BeamFileName, !IO),
+ BeamDirName = dir.dirname(BeamFileName),
+ module_name_to_file_name_stem(MainModuleName, BeamBaseNameNoExt),
+
+ % Add `-pa <dir>' option to find the standard library.
+ % (-pa adds the directory to the beginning of the list of paths to search
+ % for .beam files)
+ grade_directory_component(Globals, GradeDir),
+ globals.lookup_maybe_string_option(Globals,
+ mercury_standard_library_directory, MaybeStdLibDir),
+ (
+ MaybeStdLibDir = yes(StdLibDir),
+ StdLibBeamsPath = StdLibDir/"lib"/GradeDir/"libmer_std.beams",
+ SearchStdLib = pa_option(no, yes, StdLibBeamsPath),
+ % Added by elds_to_erlang.m
+ MainFunc = "mercury__main_wrapper"
+ ;
+ MaybeStdLibDir = no,
+ SearchStdLib = "",
+ MainFunc = "main_2_p_0"
+ ),
+
+ % Add `-pa <dir>' options to find any other libraries specified by the user.
+ globals.lookup_accumulating_option(Globals, mercury_library_directories,
+ MercuryLibDirs0),
+ MercuryLibDirs = list.map((func(LibDir) = LibDir/"lib"/GradeDir),
+ MercuryLibDirs0),
+ globals.lookup_accumulating_option(Globals, link_libraries,
+ LinkLibrariesList0),
+ list.map_foldl(find_erlang_library_path(Globals, MercuryLibDirs),
+ LinkLibrariesList0, LinkLibrariesList, !IO),
+
+ globals.lookup_string_option(Globals, erlang_interpreter, Erlang),
+ SearchLibs = string.append_list(list.map(pa_option(no, yes),
+ list.sort_and_remove_dups(LinkLibrariesList))),
+
+ % XXX main_2_p_0 is not necessarily in the main module itself and
+ % could be in a submodule. We don't handle that yet.
+ SearchProg = pa_option(no, no, "%DIR%\\" ++ quote_arg(BeamDirName)),
+ io.write_strings(Stream, [
+ "@echo off\n",
+ "rem Generated by the Mercury compiler.\n",
+ "setlocal\n",
+ "set DIR=%~dp0\n",
+ Erlang, " -noshell ",
+ SearchStdLib, SearchLibs, SearchProg,
+ " -s ", BeamBaseNameNoExt, " ", MainFunc,
+ " -s init stop -extra %*\n"
+ ], !IO).
:- pred find_erlang_library_path(globals::in, list(dir_name)::in, string::in,
string::out, io::di, io::uo) is det.
@@ -983,7 +1036,7 @@
LibFileName, SearchResult, !IO),
(
SearchResult = ok(DirName),
- LibPath = DirName/LibFileName
+ LibPath = DirName / LibFileName
;
SearchResult = error(Error),
LibPath = "",
@@ -991,16 +1044,24 @@
!IO)
).
-:- func pa_option(bool, dir_name) = string.
+:- func pa_option(bool, bool, dir_name) = string.
-pa_option(Quote, Dir0) = " -pa " ++ Dir ++ " \\\n" :-
+pa_option(BreakLines, Quote, Dir0) = Option :-
(
Quote = yes,
Dir = quote_arg(Dir0)
;
Quote = no,
Dir = Dir0
- ).
+ ),
+ (
+ BreakLines = yes,
+ LineContinuation = " \\\n"
+ ;
+ BreakLines = no,
+ LineContinuation = ""
+ ),
+ Option = " -pa " ++ Dir ++ LineContinuation.
%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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