[m-rev.] for review: stengthen libgrade detection for C# and Java grades

Peter Wang novalazy at gmail.com
Sun Jul 22 12:11:52 AEST 2018


On Thu, 19 Jul 2018 22:34:29 -0400 (EDT), Julien Fischer <jfischer at opturion.com> wrote:
> 
> For review by anyone.
> 
> ---------------------------------
> 
> Strengthen libgrade detection for C# and Java grades.
> 
> Runtime detection of installed library grades works by checking for the
> presence of a grade specific file in the location where the standard libraries
> are installed.  For C and Erlang grades we check for the presence of the
> standard library's init file. (This is a good choice since its name and
> relative location are consistent across all platforms.)
> 
> The C# and Java backends do not generate init files.  Previously, we used the
> presence of lib/mercury/modules/csharp directory etc to determine whether those
> grades were installed.  As discussed recently on the developers list, this can
> lead to bad interactions with package managers if other libraries are also
> installed alongside the standard libraries.  This diff changes runtime library
> grade detection to check for C# and Java grades by checking for the presence of
> the standard library assembly or JAR respectively.  (Unlike in C grades, these
> will have consistent names across platforms.)
> 
> compiler/mercury_compile_main.m:
>       Detect installed C# and Java grades by looking for the standard library
>       assembly or JAR respectively.
> 
> Julien.
> 
> diff --git a/compiler/mercury_compile_main.m b/compiler/mercury_compile_main.m
> index fe68f53..995f4c9 100644
> --- a/compiler/mercury_compile_main.m
> +++ b/compiler/mercury_compile_main.m
...
> +    % Test for the presence of installed Java and C# grades by looking for
> +    % the standard library JAR or assembly respectively.
> +    %
> +:- pred do_detect_libgrade_using_lib_file(bool::in, string::in, string::in,
> +    io.file_type::in, bool::out, list(string)::in, list(string)::out,
> +    io::di, io::uo) is det.
> +
> +do_detect_libgrade_using_lib_file(VeryVerbose, DirName, GradeFileName,
> +        GradeFileType, Continue, !GradeOpts, !IO) :-
> +    (
> +        GradeFileType = directory,
>           ( if
> -            % We do not generate .init files for the Java and C# grades so just
> -            % check for directories in StdLibDir / "modules" containing
> -            % the name of their base grade.
> -            % XXX we should check for the presence of mer_std.{dll,jar}
> -            % instead.
> -            %
> -            ( string.prefix(FileName, "csharp")
> -            ; string.prefix(FileName, "java")
> -            )
> +            csharp_or_java_libgrade_target(GradeFileName, LibFile),
> +            TargetFile = DirName / GradeFileName / LibFile

Could move this line into the then branch.

>           then
> -            maybe_report_detected_libgrade(VeryVerbose, FileName, !IO),
> -            !:GradeOpts = ["--libgrade", FileName | !.GradeOpts]
> -        else
> -            % For the C and Erlang grades, we check for the presence of the
> -            % .init file for mer_std to test whether the grade is present or
> -            % not.
> -            %
> -            InitFile = DirName / FileName / "mer_std.init",
> -            io.check_file_accessibility(InitFile, [read], Result, !IO),
> +            io.check_file_accessibility(TargetFile, [read], Result, !IO),
>               (
>                   Result = ok,
> -                maybe_report_detected_libgrade(VeryVerbose, FileName, !IO),
> -                !:GradeOpts = ["--libgrade", FileName | !.GradeOpts]
> +                maybe_report_detected_libgrade(VeryVerbose, GradeFileName,
> +                    !IO),
> +                !:GradeOpts = ["--libgrade", GradeFileName | !.GradeOpts]
>               ;
>                   Result = error(_)
>               )
> +        else
> +            true
>           ),
>           Continue = yes

Looks fine.

Peter


More information about the reviews mailing list