[m-rev.] for review: add --install-method option
Julien Fischer
jfischer at opturion.com
Sun Nov 12 16:08:44 AEDT 2023
For review by anyone.
-----------------------
Add --install-method option.
Add new configuration option, --install-method, that will be used to control
how the compiler copies files and directories. This diff just adds the new
option and inserts its values into the globals; later changes will make use
of it.
compiler/globals.m
Add a type representing the value of the new option.
Add a slot to the globals structure to hold the value of the new
option and a predicate to look it up.
compiler/options.m:
Recognise the new option.
compiler/handle_options.m:
Check the value of the new option.
Fix spelling in a spot.
Julien.
diff --git a/compiler/globals.m b/compiler/globals.m
index 715d84f..74342c4 100644
--- a/compiler/globals.m
+++ b/compiler/globals.m
@@ -2,7 +2,7 @@
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 1994-2012 The University of Melbourne.
-% Copyright (C) 2013-2021 The Mercury Team.
+% Copyright (C) 2013-2023 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.
%---------------------------------------------------------------------------%
@@ -246,7 +246,25 @@
%---------------------%
- % This type specifies the command compiler uses to install files.
+ % This type specifies how the compiler should install files and
+ % directories. Values of this type only affect when the compiler does file
+ % installation (e.g. an install target with mmc --make); they do not affect
+ % file installation done by mmake.
+:- type install_method
+ ---> install_method_external
+ % Files and directories should be installed by invoking a command
+ % (e.g. cp or cp -R) via the shell of the underlying operation
+ % system. (See the file_install_cmd/0 type below.)
+
+ ; install_method_internal.
+ % Files and directories should be installed by invoking an OS or
+ % target language call, or by using predicates implemented using
+ % standard Mercury file operations.
+
+%---------------------%
+
+ % This type specifies the external command the compiler uses to install
+ % files.
%
:- type file_install_cmd
---> install_cmd_user(
@@ -329,9 +347,9 @@
trace_level::in, trace_suppress_items::in, ssdb_trace_level::in,
may_be_thread_safe::in, c_compiler_type::in, csharp_compiler_type::in,
subdir_setting::in, reuse_strategy::in, maybe(feedback_info)::in,
- env_type::in, env_type::in, env_type::in, file_install_cmd::in,
- limit_error_contexts_map::in, linked_target_ext_info_map::in,
- globals::out) is det.
+ env_type::in, env_type::in, env_type::in, install_method::in,
+ file_install_cmd::in, limit_error_contexts_map::in,
+ linked_target_ext_info_map::in, globals::out) is det.
:- pred get_default_options(globals::in, option_table::out) is det.
:- pred get_options(globals::in, option_table::out) is det.
@@ -355,6 +373,7 @@
:- pred get_host_env_type(globals::in, env_type::out) is det.
:- pred get_system_env_type(globals::in, env_type::out) is det.
:- pred get_target_env_type(globals::in, env_type::out) is det.
+:- pred get_install_method(globals::in, install_method::out) is det.
:- pred get_file_install_cmd(globals::in, file_install_cmd::out) is det.
:- pred get_limit_error_contexts_map(globals::in,
limit_error_contexts_map::out) is det.
@@ -824,7 +843,8 @@ convert_line_number_range(RangeStr, line_number_range(MaybeMin, MaybeMax)) :-
g_may_be_thread_safe :: bool,
g_host_env_type :: env_type,
g_system_env_type :: env_type,
- g_target_env_type :: env_type
+ g_target_env_type :: env_type,
+ g_install_method :: install_method
).
globals_init(DefaultOptions, Options, OptTuple, OpMode,
@@ -832,14 +852,14 @@ globals_init(DefaultOptions, Options, OptTuple, OpMode,
TraceLevel, TraceSuppress, SSTraceLevel, MaybeThreadSafe,
C_CompilerType, CSharp_CompilerType, SubdirSetting,
ReuseStrategy, MaybeFeedback, HostEnvType, SystemEnvType,
- TargetEnvType, FileInstallCmd, LimitErrorContextsMap,
+ TargetEnvType, InstallMethod, FileInstallCmd, LimitErrorContextsMap,
LinkedTargetExtInfoMap, Globals) :-
Globals = globals(DefaultOptions, Options, OptTuple, OpMode, TraceSuppress,
ReuseStrategy, MaybeFeedback, FileInstallCmd, LimitErrorContextsMap,
LinkedTargetExtInfoMap, C_CompilerType, CSharp_CompilerType,
Target, SubdirSetting, WordSize, GC_Method,
TerminationNorm, Termination2Norm, TraceLevel, SSTraceLevel,
- MaybeThreadSafe, HostEnvType, SystemEnvType, TargetEnvType).
+ MaybeThreadSafe, HostEnvType, SystemEnvType, TargetEnvType, InstallMethod).
get_default_options(Globals, Globals ^ g_default_options).
get_options(Globals, Globals ^ g_options).
@@ -862,6 +882,7 @@ get_maybe_feedback_info(Globals, Globals ^ g_maybe_feedback).
get_host_env_type(Globals, Globals ^ g_host_env_type).
get_system_env_type(Globals, Globals ^ g_system_env_type).
get_target_env_type(Globals, Globals ^ g_target_env_type).
+get_install_method(Globals, Globals ^ g_install_method).
get_file_install_cmd(Globals, Globals ^ g_file_install_cmd).
get_limit_error_contexts_map(Globals, Globals ^ g_limit_error_contexts_map).
get_linked_target_ext_map(Globals, Globals ^ g_linked_target_ext_map).
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index 95759d8..679f82b 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -265,7 +265,7 @@ check_option_values(!OptionTable, Target, WordSize, GC_Method,
WordSize = word_size_64, % dummy
BitsPerWordStr = string.int_to_string(BitsPerWord),
WordSizeSpec =
- [words("Invalid argument"), quote(BitsPerWordStr),
+ [words("Invalid argument"), quote(BitsPerWordStr),
words("to the"), quote("--bits-per-word"), words("option;"),
words("must be either"), quote("32"), words("or"), quote("64"),
suffix("."), nl],
@@ -846,6 +846,22 @@ convert_options_to_globals(ProgressStream, DefaultOptionTable, OptionTable0,
OT_OptFrames0 = OptTuple0 ^ ot_opt_frames,
OT_StringBinarySwitchSize0 = OptTuple0 ^ ot_string_binary_switch_size,
+ lookup_string_option(OptionTable0, install_method, InstallMethodStr),
+ ( if (InstallMethodStr = "" ; InstallMethodStr = "external") then
+ InstallMethod = install_method_external
+ else if InstallMethodStr = "internal" then
+ InstallMethod = install_method_internal
+ else
+ InstallMethodSpec = [words("Error: the value of the"),
+ quote("--install-method"), words("option is"),
+ quote(InstallMethodStr), suffix(","),
+ words("but the only valid values are") ] ++
+ list_to_quoted_pieces_or(["external", "internal"]) ++
+ [suffix("."), nl],
+ add_error(phase_options, InstallMethodSpec, !Specs),
+ InstallMethod = install_method_external % Dummy value
+ ),
+
lookup_string_option(OptionTable0, install_command, InstallCmd),
( if InstallCmd = "" then
FileInstallCmd = install_cmd_cp
@@ -859,15 +875,15 @@ convert_options_to_globals(ProgressStream, DefaultOptionTable, OptionTable0,
% the real value is set at the very end of this predicate,
% We can do this because no code between here and there uses
% the value of that field, and we *have* to do this because
- % the bcode between here and there *can* update the values of
+ % the code between here and there *can* update the values of
% the options from which the subdir setting is computed.
globals_init(DefaultOptionTable, OptionTable0, !.OptTuple, OpMode, Target,
WordSize, GC_Method, TermNorm, Term2Norm,
TraceLevel, TraceSuppress, SSTraceLevel,
MaybeThreadSafe, C_CompilerType, CSharp_CompilerType, use_cur_dir,
ReuseStrategy, MaybeFeedbackInfo,
- HostEnvType, SystemEnvType, TargetEnvType, FileInstallCmd,
- LimitErrorContextsMap, LinkExtMap, !:Globals),
+ HostEnvType, SystemEnvType, TargetEnvType, InstallMethod,
+ FileInstallCmd, LimitErrorContextsMap, LinkExtMap, !:Globals),
globals.lookup_bool_option(!.Globals, experiment2, Experiment2),
(
diff --git a/compiler/options.m b/compiler/options.m
index 91e86ef..94ab8ff 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -1082,6 +1082,7 @@
; use_symlinks
; mercury_configuration_directory
; mercury_configuration_directory_special
+ ; install_method
; install_command
; install_command_dir_option
; detect_libgrades
@@ -2045,6 +2046,7 @@ optdef(oc_buildsys, use_symlinks, bool(yes)).
% of the options.
optdef(oc_buildsys, mercury_configuration_directory_special, string_special).
optdef(oc_buildsys, mercury_configuration_directory, maybe_string(no)).
+optdef(oc_buildsys, install_method, string("external")).
optdef(oc_buildsys, install_command, string("cp")).
optdef(oc_buildsys, install_command_dir_option, string("-R")).
optdef(oc_buildsys, detect_libgrades, bool(yes)).
@@ -3111,6 +3113,7 @@ long_option("mercury-configuration-directory",
long_option("mercury-config-dir",
mercury_configuration_directory_special).
long_option("install-prefix", install_prefix).
+long_option("install-method", install_method).
long_option("install-command", install_command).
long_option("install-command-dir-option", install_command_dir_option).
long_option("use-symlinks", use_symlinks).
@@ -6689,6 +6692,10 @@ options_help_build_system(Stream, !IO) :-
% It controls whether the build system should attempt
% to use symlinks.
+ % --install-method is only used by Mercury.config.
+ % It controls how the build system attempts to copy files
+ % and directories.
+
"--install-command <command>",
"\tSpecify the command to use to install the files in",
"\tMercury libraries. The given command will be invoked as",
More information about the reviews
mailing list