[m-rev.] for review: shell script for C# grade uses absolute path
Sebastian Godelet
sebastian.godelet+github at gmail.com
Fri Mar 28 02:28:11 AEDT 2014
Hi Peter,
I fixed both the C# and Java grade generated shell scripts,
they are now ".." and space safe. MONO_PATH or the existing CLASSPATH value
do not need quoting, as these should be quoted by the system already, I do
think that is a reasonable assumption.
The changes are tested on extras/xml/samples/ invoking ../tryit *.xml
compiler/compile_target_code.m:
Assigning script directory to DIR and use that to launch the CLI interpreter,
quoting the CLI_INTERPRETER and executable filename.
compiler/module_cmds.m:
Quoting Mercury generated CLASSPATH, in case the directory contains spaces,
also making DIR absolute, in case the script is invoked from a subdirectory.
Sebastian.
---
diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 1893393..09d8464 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -3014,10 +3014,11 @@ write_cli_shell_script(Globals, ExeFileName,
Stream, !IO) :-
":", LinkLibraryDirectories),
list.foldl(io.write_string(Stream), [
"#!/bin/sh\n",
+ "DIR=${0%/*}\n",
"MONO_PATH=$MONO_PATH:", LinkLibraryDirectories, "\n",
"export MONO_PATH\n",
"CLI_INTERPRETER=${CLI_INTERPRETER:-", CLI, "}\n",
- "exec $CLI_INTERPRETER ", ExeFileName, " \"$@\"\n"
+ "exec \"$CLI_INTERPRETER\" \"$DIR/", ExeFileName, "\" \"$@\"\n"
], !IO).
:- pred create_java_archive(globals::in, io.output_stream::in,
file_name::in,
diff --git a/compiler/module_cmds.m b/compiler/module_cmds.m
index 19dd78a..6767820 100644
--- a/compiler/module_cmds.m
+++ b/compiler/module_cmds.m
@@ -775,8 +775,8 @@ write_java_shell_script(Globals, MainModuleName,
Stream, !IO) :-
globals.lookup_accumulating_option(Globals, java_classpath,
UserClasspath),
% We prepend the .class files' directory and the current CLASSPATH.
- Java_Incl_Dirs = ["$DIR/" ++ ClassDirNameUnix] ++ MercuryStdLibs ++
- ["$CLASSPATH" | UserClasspath],
+ Java_Incl_Dirs = ["\"$DIR/" ++ ClassDirNameUnix ++ "\""] ++
+ MercuryStdLibs ++ ["$CLASSPATH" | UserClasspath],
ClassPath = string.join_list("${SEP}", Java_Incl_Dirs),
globals.lookup_string_option(Globals, java_interpreter, Java),
@@ -785,6 +785,7 @@ write_java_shell_script(Globals, MainModuleName,
Stream, !IO) :-
io.write_strings(Stream, [
"#!/bin/sh\n",
"DIR=${0%/*}\n",
+ "DIR=$( cd ${DIR} ; pwd -P )\n",
"case $WINDIR in\n",
" '') SEP=':' ;;\n",
" *) SEP=';' ;;\n",
@@ -792,7 +793,7 @@ write_java_shell_script(Globals, MainModuleName,
Stream, !IO) :-
"CLASSPATH=", ClassPath, "\n",
"export CLASSPATH\n",
"JAVA=${JAVA:-", Java, "}\n",
- "exec $JAVA jmercury.", ClassName, " \"$@\"\n"
+ "exec \"$JAVA\" jmercury.", ClassName, " \"$@\"\n"
], !IO).
:- pred write_java_batch_file(globals::in, module_name::in,
Am 20.03.2014 01:00, schrieb Peter Wang:
> On Sat, 15 Mar 2014 15:38:57 +0100, Sebastian Godelet <sebastian.godelet+github at gmail.com> wrote:
>> For review by anyone.
>>
>> The generated shell script to launch C# executables does not use
>> absolute pathes, this patch fixes that (now works the same as the Java
>> grade).
>>
>> compiler/compile_target_code.m:
>> Assigning script directory to DIR and use that to launch the CLI
>> interpreter.
>>
>> Sebastian.
>>
>> ---
>> compiler/compile_target_code.m | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>> diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
>> index 1893393..cdf510e 100644
>> --- a/compiler/compile_target_code.m
>> +++ b/compiler/compile_target_code.m
>> @@ -3014,10 +3014,11 @@ write_cli_shell_script(Globals, ExeFileName,
>> Stream, !IO) :-
>> ":", LinkLibraryDirectories),
>> list.foldl(io.write_string(Stream), [
>> "#!/bin/sh\n",
>> + "DIR=${0%/*}\n",
>> "MONO_PATH=$MONO_PATH:", LinkLibraryDirectories, "\n",
>> "export MONO_PATH\n",
>> "CLI_INTERPRETER=${CLI_INTERPRETER:-", CLI, "}\n",
>> - "exec $CLI_INTERPRETER ", ExeFileName, " \"$@\"\n"
>> + "exec $CLI_INTERPRETER $DIR/", ExeFileName, " \"$@\"\n"
>> ], !IO).
> Hi,
>
> $CLI_INTERPRETER and $DIR should be quoted for spaces.
> I think the reference to $MONO_PATH should be quoted as well.
> but I'm not sure.
>
> PEter
More information about the reviews
mailing list