[m-rev.] diff: move the library grade install check out of the make package
Julien Fischer
jfischer at opturion.com
Thu Sep 12 15:38:01 AEST 2019
Move the library grade install check out of the make package.
Move the library grade install check out of the make package and into its own
module in the libs package. This is in preparation for performing the check
when building single source file programs.
compiler/check_libgrades.m:
New module containing the code that implements the library grade install
check.
compiler/libs.m:
Include the new module.
compiler/make.program_target.m:
Conform to the above change.
compiler/notes/compiler_design.html:
Mention the new module.
Julien.
diff --git a/compiler/check_libgrades.m b/compiler/check_libgrades.m
index e69de29..801f6c5 100644
--- a/compiler/check_libgrades.m
+++ b/compiler/check_libgrades.m
@@ -0,0 +1,153 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%---------------------------------------------------------------------------%
+% Copyright (C) 2008-2009 The University of Melbourne.
+% Copyright (C) 2015-2016, 2019 The Mercury team.
+% This file may only be copied under the terms of the GNU General
+% Public License - see the file COPYING in the Mercury distribution.
+%---------------------------------------------------------------------------%
+%
+% This module checks if all the Mercury libraries needed to build a target
+% are installed in the required grade.
+%
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- module libs.check_libgrades.
+:- interface.
+
+:- import_module libs.globals.
+
+:- import_module bool.
+:- import_module io.
+
+%---------------------------------------------------------------------------%
+
+ % Check that all Mercury libraries required by the target are installed
+ % in the selected grade.
+ %
+:- pred check_libraries_are_installed(globals::in, bool::out,
+ io::di, io::uo) is det.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module libs.compute_grade.
+:- import_module libs.file_util.
+:- import_module libs.options.
+
+:- import_module dir.
+:- import_module list.
+:- import_module maybe.
+:- import_module string.
+
+%---------------------------------------------------------------------------%
+
+check_libraries_are_installed(Globals, Succeeded, !IO) :-
+ globals.lookup_accumulating_option(Globals, mercury_libraries, Libs),
+ grade_directory_component(Globals, Grade),
+ check_stdlib_is_installed(Globals, Grade, Succeeded0, !IO),
+ list.foldl2(check_library_is_installed(Globals, Grade), Libs,
+ Succeeded0, Succeeded, !IO).
+
+:- pred check_stdlib_is_installed(globals::in, string::in, bool::out,
+ io::di, io::uo) is det.
+
+check_stdlib_is_installed(Globals, Grade, Succeeded, !IO) :-
+ globals.lookup_maybe_string_option(Globals,
+ mercury_standard_library_directory, MaybeStdLibDir),
+ (
+ MaybeStdLibDir = yes(StdLibDir),
+ globals.get_target(Globals, Target),
+ (
+ ( Target = target_c
+ ; Target = target_erlang
+ ),
+ % In C or Erlang grades, check for the presence of mer_std.init in
+ % the required grade. Unless the installation is broken this
+ % implies the presence of the other standard library files in that
+ % grade.
+ StdLibCheckFile = StdLibDir / "modules" / Grade / "mer_std.init"
+ ;
+ % Java grades do not use .init files, so check for the presence of
+ % the standard library JAR.
+ Target = target_java,
+ StdLibCheckFile = StdLibDir / "lib" / Grade / "mer_std.jar"
+ ;
+ % C# grades do not use .init files, so check for the presence of
+ % the standard library DLL.
+ Target = target_csharp,
+ StdLibCheckFile = StdLibDir / "lib" / Grade / "mer_std.dll"
+ ),
+ io.see(StdLibCheckFile, Result, !IO),
+ (
+ Result = ok,
+ io.seen(!IO),
+ Succeeded = yes
+ ;
+ Result = error(_),
+ io.stderr_stream(Stderr, !IO),
+ io.progname_base("mercury_compile", ProgName, !IO),
+ io.format(Stderr,
+ "%s: error: the Mercury standard library " ++
+ "cannot be found in grade %s.\n",
+ [s(ProgName), s(Grade)], !IO),
+ Succeeded = no
+ )
+ ;
+ MaybeStdLibDir = no,
+ Succeeded = yes
+ ).
+
+:- pred check_library_is_installed(globals::in, string::in,
+ string::in, bool::in, bool::out, io::di, io::uo) is det.
+
+check_library_is_installed(Globals, Grade, LibName, !Succeeded, !IO) :-
+ globals.get_target(Globals, Target),
+ (
+ % In C and Erlang grades, check for the presence of a library by seeing
+ % if its .init files exists.
+ ( Target = target_c
+ ; Target = target_erlang
+ ),
+ CheckFileName = LibName ++ ".init",
+ % NOTE: we don't look up the value of the option init_files here
+ % because that may include .init files other than those associated with
+ % any libraries.
+ globals.lookup_accumulating_option(Globals, init_file_directories,
+ SearchDirs)
+ ;
+ (
+ % In Java grades, check for the presence of the JAR for library.
+ Target = target_java,
+ CheckFileName = LibName ++ ".jar"
+ ;
+ % In C# grades, check for the presence of the DLL for the library.
+ Target = target_csharp,
+ CheckFileName = LibName ++ ".dll"
+ ),
+ globals.lookup_accumulating_option(Globals,
+ mercury_library_directories, MercuryLibDirs),
+ grade_directory_component(Globals, GradeDir),
+ SearchDirs = list.map((func(LibDir) = LibDir / "lib" / GradeDir),
+ MercuryLibDirs)
+ ),
+ search_for_file_returning_dir(SearchDirs, CheckFileName, MaybeDirName,
+ !IO),
+ (
+ MaybeDirName = ok(_)
+ ;
+ MaybeDirName = error(_),
+ io.stderr_stream(Stderr, !IO),
+ io.progname_base("mercury_compile", ProgName, !IO),
+ io.format(Stderr,
+ "%s: error: the library `%s' cannot be found in grade `%s'.\n",
+ [s(ProgName), s(LibName), s(Grade)], !IO),
+ !:Succeeded = no
+ ).
+
+%---------------------------------------------------------------------------%
+:- end_module libs.check_libgrades.
+%---------------------------------------------------------------------------%
diff --git a/compiler/libs.m b/compiler/libs.m
index 0b1b7dc..2254219 100644
--- a/compiler/libs.m
+++ b/compiler/libs.m
@@ -26,6 +26,9 @@
% Representation of mmakefile fragments.
:- include_module mmakefiles.
+% Existence checks for required libraries.
+:- include_module check_libgrades.
+
% Generic algorithms and data structures that are not quite useful enough
% or otherwise aren't in the standard library.
% :- include_module atsort. % currently unused
diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index 4a7973a..1ec8278 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -41,6 +41,7 @@
:- import_module analysis.
:- import_module libs.
+:- import_module libs.check_libgrades.
:- import_module libs.compute_grade.
:- import_module libs.process_util.
:- import_module parse_tree.
@@ -2066,130 +2067,5 @@ make_module_realclean(Globals, ModuleName, !Info, !IO) :-
".request", !Info, !IO).
%-----------------------------------------------------------------------------%
-%
-% Check that the Mercury libraries required to build a linked target
-% are installed in the selected grade.
-%
-
- % Check that all Mercury libraries required by the linked target are
- % installed in the selected grade.
- %
-:- pred check_libraries_are_installed(globals::in, bool::out, io::di, io::uo)
- is det.
-
-check_libraries_are_installed(Globals, Succeeded, !IO) :-
- globals.lookup_accumulating_option(Globals, mercury_libraries, Libs),
- grade_directory_component(Globals, Grade),
- check_stdlib_is_installed(Globals, Grade, Succeeded0, !IO),
- list.foldl2(check_library_is_installed(Globals, Grade), Libs,
- Succeeded0, Succeeded, !IO).
-
-:- pred check_stdlib_is_installed(globals::in, string::in, bool::out,
- io::di, io::uo) is det.
-
-check_stdlib_is_installed(Globals, Grade, Succeeded, !IO) :-
- verbose_make_msg_option(Globals, debug_make,
- ( pred(!.IO::di, !:IO::uo) is det :-
- io.format("Checking that the Mercury standard library is " ++
- "installed in grade `%s'.\n", [s(Grade)], !IO)
- ), !IO),
- globals.lookup_maybe_string_option(Globals,
- mercury_standard_library_directory, MaybeStdLibDir),
- (
- MaybeStdLibDir = yes(StdLibDir),
- globals.get_target(Globals, Target),
- (
- ( Target = target_c
- ; Target = target_erlang
- ),
- % In C or Erlang grades, check for the presence of mer_std.init in
- % the required grade. Unless the installation is broken this
- % implies the presence of the other standard library files in that
- % grade.
- StdLibCheckFile = StdLibDir / "modules" / Grade / "mer_std.init"
- ;
- % Java grades do not use .init files, so check for the presence of
- % the standard library JAR.
- Target = target_java,
- StdLibCheckFile = StdLibDir / "lib" / Grade / "mer_std.jar"
- ;
- % C# grades do not use .init files, so check for the presence of
- % the standard library DLL.
- Target = target_csharp,
- StdLibCheckFile = StdLibDir / "lib" / Grade / "mer_std.dll"
- ),
- io.see(StdLibCheckFile, Result, !IO),
- (
- Result = ok,
- io.seen(!IO),
- Succeeded = yes
- ;
- Result = error(_),
- io.stderr_stream(Stderr, !IO),
- io.progname_base("mercury_compile", ProgName, !IO),
- io.format(Stderr,
- "%s: error: the Mercury standard library " ++
- "cannot be found in grade %s.\n",
- [s(ProgName), s(Grade)], !IO),
- Succeeded = no
- )
- ;
- MaybeStdLibDir = no,
- Succeeded = yes
- ).
-
-:- pred check_library_is_installed(globals::in, string::in,
- string::in, bool::in, bool::out, io::di, io::uo) is det.
-
-check_library_is_installed(Globals, Grade, LibName, !Succeeded, !IO) :-
- verbose_make_msg_option(Globals, debug_make,
- ( pred(!.IO::di, !:IO::uo) is det :-
- io.format("Checking that %s is installed in grade `%s'.\n",
- [s(LibName), s(Grade)], !IO)
- ), !IO),
- globals.get_target(Globals, Target),
- (
- % In C and Erlang grades, check for the presence of a library by seeing
- % if its .init files exists.
- ( Target = target_c
- ; Target = target_erlang
- ),
- CheckFileName = LibName ++ ".init",
- % NOTE: we don't look up the value of the option init_files here
- % because that may include .init files other than those associated with
- % any libraries.
- globals.lookup_accumulating_option(Globals, init_file_directories,
- SearchDirs)
- ;
- (
- % In Java grades, check for the presence of the JAR for library.
- Target = target_java,
- CheckFileName = LibName ++ ".jar"
- ;
- % In C# grades, check for the presence of the DLL for the library.
- Target = target_csharp,
- CheckFileName = LibName ++ ".dll"
- ),
- globals.lookup_accumulating_option(Globals,
- mercury_library_directories, MercuryLibDirs),
- grade_directory_component(Globals, GradeDir),
- SearchDirs = list.map((func(LibDir) = LibDir / "lib" / GradeDir),
- MercuryLibDirs)
- ),
- search_for_file_returning_dir(SearchDirs, CheckFileName, MaybeDirName,
- !IO),
- (
- MaybeDirName = ok(_)
- ;
- MaybeDirName = error(_),
- io.stderr_stream(Stderr, !IO),
- io.progname_base("mercury_compile", ProgName, !IO),
- io.format(Stderr,
- "%s: error: the library `%s' cannot be found in grade `%s'.\n",
- [s(ProgName), s(LibName), s(Grade)], !IO),
- !:Succeeded = no
- ).
-
-%-----------------------------------------------------------------------------%
:- end_module make.program_target.
%-----------------------------------------------------------------------------%
diff --git a/compiler/notes/compiler_design.html b/compiler/notes/compiler_design.html
index 91449b7..c2274f6 100644
--- a/compiler/notes/compiler_design.html
+++ b/compiler/notes/compiler_design.html
@@ -2501,6 +2501,12 @@ The following modules are part of the libs.m package.
<dd>
A representation for mmakefiles and mmakefile fragments,
and predicates for printing them.
+
+ <dt> check_libgrades.m:
+ <dd>
+ Implements the check that dependent libraries are installed in
+ the required grade.
+
</dl>
<hr>
More information about the reviews
mailing list