[m-rev.] diff: fix bug #339: --restricted-command-line broken with recent Java compilers

Sebastian Godelet sebastian.godelet at outlook.com
Wed Jul 15 14:05:40 AEST 2015


Hi Julien,

I've compiled Mercury on Windows 8.1 with Java 1.8 and mmc now is able to invoke the
Java compiler. However, there seems to be a bug in the batch file creation,
When I use --use-grade-subdirs, the <name>.bat file cannot be found, since
It is not looking in the grade specific directory, i.e.:
Mercury\java\i686-pc-mingw32\Mercury\bats
Invoking without --use-grade-subdirs works however

mmc --use-grade-subdirs -s java -m fmt_bug
cp: cannot stat `Mercury\\java\\i686-pc-mingw32\\Mercury\\bin\\fmt_bug.bat': No such file or directory
Made symlink/copy of Mercury\java\i686-pc-mingw32\Mercury\jars\fmt_bug.jar
mercury_compile.exe: error copying `Mercury\java\i686-pc-mingw32\Mercury\bin\fmt_bug.bat' to `fmt_bug.bat', can't open input file: No such file or directory

Cheers,

Sebastian.

> -----Original Message-----
> From: reviews [mailto:reviews-bounces at lists.mercurylang.org] On Behalf Of
> Julien Fischer
> Sent: Tuesday, July 14, 2015 11:04 AM
> To: reviews at lists.mercurylang.org
> Subject: [m-rev.] diff: fix bug #339: --restricted-command-line broken with
> recent Java compilers
> 
> 
> Fix bug #339: --restricted-command-line broken with recent Java compilers.
> 
> Recent Java compilers have started aborting if any -J options occur inside
> @files.  Since --restricted-command-line implies the use of @files, we need to
> filter out any -J options to javac and ensure that they do not end up inside an
> @file when --restricted-command-line is enabled.
> 
> compiler/compile_target_code.m:
>  	When gathering the flags for the Java compiler, separate out any
>  	-J flags and ensure that they do not get placed in an @file.
> 
> Julien.
> 
> diff --git a/compiler/compile_target_code.m
> b/compiler/compile_target_code.m
> index c710fcf..82f4a91 100644
> --- a/compiler/compile_target_code.m
> +++ b/compiler/compile_target_code.m
> @@ -1058,7 +1058,23 @@ compile_java_files(ErrorStream, JavaFiles, Globals,
> Succeeded, !IO) :-
> 
>       globals.lookup_string_option(Globals, java_compiler, JavaCompiler),
>       globals.lookup_accumulating_option(Globals, java_flags, JavaFlagsList),
> -    join_string_list(JavaFlagsList, "", "", " ", JAVAFLAGS),
> +    globals.lookup_bool_option(Globals, restricted_command_line,
> +        RestrictedCommandLine),
> +    (
> +        RestrictedCommandLine = yes,
> +        % NOTE: the '-J' flag must not occur inside @files, so we need
> +        % to ensure that it is always passed on the command line.
> +        list.filter(is_minus_j_flag, JavaFlagsList,
> +            JRT_JavaFlagsList, NonJRT_JavaFlagsList),
> +        join_string_list(JRT_JavaFlagsList, "", "", " ",
> +            NonAtFileJAVAFLAGS),
> +        join_string_list(NonJRT_JavaFlagsList, "", "", " ",
> +            JAVAFLAGS)
> +    ;
> +        RestrictedCommandLine = no,
> +        join_string_list(JavaFlagsList, "", "", " ", JAVAFLAGS),
> +        NonAtFileJAVAFLAGS = ""
> +    ),
> 
>       get_mercury_std_libs_for_java(Globals, MercuryStdLibs),
>       globals.lookup_accumulating_option(Globals, java_classpath,
> UserClasspath),
> @@ -1123,13 +1139,15 @@ compile_java_files(ErrorStream, JavaFiles, Globals,
> Succeeded, !IO) :-
>           MaybeMFilterJavac = yes(MFilterJavac)
>       ),
> 
> +    NonAtFileCommandArgs = NonAtFileJAVAFLAGS,
>       % Be careful with the order here!  Some options may override others.
>       % Also be careful that each option is separated by spaces.
>       JoinedJavaFiles = string.join_list(" ", JavaFiles),
>       string.append_list([InclOpt, DirOpts,
>           Target_DebugOpt, JAVAFLAGS, " ", JoinedJavaFiles], CommandArgs),
>       invoke_long_system_command_maybe_filter_output(Globals, ErrorStream,
> -        cmd_verbose_commands, JavaCompiler, CommandArgs,
> MaybeMFilterJavac,
> +        cmd_verbose_commands, JavaCompiler, NonAtFileCommandArgs,
> +        CommandArgs, MaybeMFilterJavac,
>           Succeeded, !IO).
> 
>   :- func java_classpath_separator = string.
> @@ -1145,6 +1163,11 @@ java_classpath_separator = PathSeparator :-
>           PathSeparator = ":"
>       ).
> 
> +:- pred is_minus_j_flag(string::in) is semidet.
> +
> +is_minus_j_flag(FlagStr) :-
> +    string.prefix(FlagStr, "-J").
> +
>   %-----------------------------------------------------------------------------%
> 
>   compile_erlang_file(ErrorStream, ErlangFile, Globals, Succeeded, !IO) :-
> @@ -3550,14 +3573,14 @@ make_standalone_int_body(Globals,
> Basename, !IO) :-
>   invoke_long_system_command(Globals, ErrorStream, Verbosity, Cmd, Args,
>           Succeeded, !IO) :-
>       invoke_long_system_command_maybe_filter_output(Globals, ErrorStream,
> -        Verbosity, Cmd, Args, no, Succeeded, !IO).
> +        Verbosity, Cmd, "", Args, no, Succeeded, !IO).
> 
>   :- pred invoke_long_system_command_maybe_filter_output(globals::in,
>       io.output_stream::in, command_verbosity::in, string::in, string::in,
> -    maybe(string)::in, bool::out, io::di, io::uo) is det.
> +    string::in, maybe(string)::in, bool::out, io::di, io::uo) is det.
> 
>   invoke_long_system_command_maybe_filter_output(Globals, ErrorStream,
> Verbosity,
> -        Cmd, Args, MaybeProcessOutput, Succeeded, !IO) :-
> +        Cmd, NonAtArgs, Args, MaybeProcessOutput, Succeeded, !IO) :-
>       globals.lookup_bool_option(Globals, restricted_command_line,
>           RestrictedCommandLine),
>       (
> @@ -3577,18 +3600,22 @@
> invoke_long_system_command_maybe_filter_output(Globals, ErrorStream,
> Verbosity,
>               io.close_output(TmpStream, !IO),
> 
>               globals.lookup_bool_option(Globals, very_verbose, VeryVerbose),
> +            AtFileName = at_file_name(Globals, TmpFile),
>               (
>                   VeryVerbose = yes,
> -                io.write_string("% Args placed in ", !IO),
> -                io.write_string(at_file_name(Globals, TmpFile) ++ ": `", !IO),
> -                io.write_string(TmpFileArgs, !IO),
> -                io.write_string("'\n", !IO),
> +                io.format("%% Args placed in %s: `%s'\n",
> +                    [s(AtFileName), s(TmpFileArgs)], !IO),
>                   io.flush_output(!IO)
>               ;
>                   VeryVerbose = no
>               ),
> 
> -            FullCmd = Cmd ++ " " ++ at_file_name(Globals, TmpFile),
> +            ( NonAtArgs = "" ->
> +                FullCmd = Cmd ++ " " ++ AtFileName
> +            ;
> +                string.append_list([Cmd, " ", NonAtArgs, " ", AtFileName],
> +                    FullCmd)
> +            ),
>               invoke_system_command_maybe_filter_output(Globals, ErrorStream,
>                   Verbosity, FullCmd, MaybeProcessOutput, Succeeded0, !IO),
> 
> @@ -3604,10 +3631,13 @@
> invoke_long_system_command_maybe_filter_output(Globals, ErrorStream,
> Verbosity,
>               OpenResult = error(_),
>               Succeeded = no
>           )
> -
>       ;
>           RestrictedCommandLine = no,
> -        FullCmd = Cmd ++ " " ++ Args,
> +        ( NonAtArgs = "" ->
> +            FullCmd = Cmd ++ " " ++ Args
> +        ;
> +            string.append_list([Cmd, " ", NonAtArgs, " ", Args], FullCmd)
> +        ),
>           invoke_system_command_maybe_filter_output(Globals, ErrorStream,
>               Verbosity, FullCmd, MaybeProcessOutput, Succeeded, !IO)
>       ).
> _______________________________________________
> reviews mailing list
> reviews at lists.mercurylang.org
> https://www.mercurylang.org/lists/listinfo/reviews




More information about the reviews mailing list