[m-rev.] for review: Add --error-files-in-subdir option.
Peter Wang
novalazy at gmail.com
Fri Jul 26 15:29:43 AEST 2024
Add --error-files-in-subdir option.
Add an option, --error-files-in-subdir, which tells mmc --make
to create .err files under the Mercury subdirectory.
compiler/options.m:
Add the option.
compiler/file_names.m:
Replace the existing ext_cur_user_err constructor
with a constructor, ext_cur_ngs_gs_err_err, in a new category.
Implement the rules for .err files:
- When neither of --use-subdirs is enabled, .err files are placed in
the current directory (as before).
- When --use-subdirs is enabled, .err files are placed in the
non-grade-specific Mercury/errs subdirectory.
- When --use-grade-subdirs is enabled, .err files are placed in a
grade-specific err subdirectory.
compiler/make.build.m:
compiler/make.file_names.m:
compiler/make.get_module_dep_info.m:
Conform to above changes.
doc/user_guide.texi:
Document the option.
NEWS.md:
Announce change.
diff --git a/NEWS.md b/NEWS.md
index dd483d6fa..13672146c 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -64,6 +64,9 @@ Changes that may break compatibility
additional options to be passed to the C compiler in order for it to find
those header files.
+* We have added the option `--error-files-in-subdir` to place `.err` files
+ under the `Mercury` subdirectory when using `mmc --make`.
+
* We have changed the meaning of `mmc --make name.cs`.
The `mmc --make` target `name.cs` now means "build the .cs file
diff --git a/compiler/file_names.m b/compiler/file_names.m
index d28b93b9c..c0ed677c2 100644
--- a/compiler/file_names.m
+++ b/compiler/file_names.m
@@ -198,6 +198,11 @@
% directory, or into a non-grade-specific subdirectory, or into
% a grade-specific subdirectory, with search being irrelevant.
+ ; ext_cur_ngs_gs_err(ext_cur_ngs_gs_err)
+ % .err files can be placed into the current directory, or into a
+ % non-grade-specific subdirectory, or into a grade-specific
+ % subdirectory, depending on options.
+
; ext_cur_ngs_gs_java(ext_cur_ngs_gs_java)
% All extensions using a java-specific set of rules.
% With respect to directory structure, they use the same sort
@@ -263,7 +268,6 @@
; ext_cur_user_defn_lc % ".defn_line_counts"
; ext_cur_user_defns % ".defns"
; ext_cur_user_depgraph % ".dependency_graph"
- ; ext_cur_user_err % ".err"
; ext_cur_user_hlds_dump % ".hlds_dump"
; ext_cur_user_imports_graph % ".imports_graph"
; ext_cur_user_lct % ".local_call_tree"
@@ -402,6 +406,9 @@
; ext_cur_ngs_gs_misc_used % ".used"
; ext_cur_ngs_gs_misc_track_flags. % ".track_flags"
+:- type ext_cur_ngs_gs_err
+ ---> ext_cur_ngs_gs_err_err. % ".err"
+
:- type ext_cur_ngs_gs_java
% Java source files generated by the Mercury compiler.
% The names of these files, and of the directories
@@ -702,6 +709,10 @@ extension_to_string(Globals, Ext) = ExtStr :-
Ext = ext_cur_ngs_gs(ExtCurNgsGs),
ext_cur_ngs_gs_extension_dir(Globals, ExtCurNgsGs,
ExtStr, _SubDirName)
+ ;
+ Ext = ext_cur_ngs_gs_err(ExtCurNgsGsErr),
+ ext_cur_ngs_gs_err_extension_dir(ExtCurNgsGsErr,
+ ExtStr, _SubDirName)
;
Ext = ext_cur_ngs_gs_java(ExtCurNgsGsJava),
ext_cur_ngs_gs_java_extension_dir(ExtCurNgsGsJava,
@@ -747,7 +758,6 @@ ext_cur_extension(Ext, Str) :-
; Ext = ext_cur_user_defn_lc, Str = ".defn_line_counts"
; Ext = ext_cur_user_defns, Str = ".defns"
; Ext = ext_cur_user_depgraph, Str = ".dependency_graph"
- ; Ext = ext_cur_user_err, Str = ".err"
; Ext = ext_cur_user_hlds_dump, Str = ".hlds_dump"
; Ext = ext_cur_user_imports_graph, Str = ".imports_graph"
; Ext = ext_cur_user_lct, Str = ".local_call_tree"
@@ -873,6 +883,12 @@ ext_cur_ngs_gs_extension_dir(Globals, Ext, Str, Dir) :-
Str = ".track_flags", Dir = "track_flags"
).
+:- pred ext_cur_ngs_gs_err_extension_dir(ext_cur_ngs_gs_err::in,
+ string::out, string::out) is det.
+
+ext_cur_ngs_gs_err_extension_dir(Ext, Str, Dir) :-
+ Ext = ext_cur_ngs_gs_err_err, Str = ".err", Dir = "errs".
+
:- pred ext_cur_ngs_gs_java_extension_dir(ext_cur_ngs_gs_java::in,
string::out, string::out) is det.
@@ -919,6 +935,7 @@ module_name_to_base_file_name_no_ext(Ext, ModuleName) = BaseNameNoExt :-
; Ext = ext_cur_ngs(_)
; Ext = ext_cur_gs(_)
; Ext = ext_cur_ngs_gs(_)
+ ; Ext = ext_cur_ngs_gs_err(_)
; Ext = ext_cur_ngs_max_cur(_)
; Ext = ext_cur_ngs_gs_max_cur(_)
; Ext = ext_cur_ngs_gs_max_ngs(_)
@@ -1160,6 +1177,31 @@ ext_to_dir_path(Globals, Search, Ext, DirNames) :-
_ExtStr, SubDirName),
DirNames = make_gs_dir_names(Globals, SubDirName)
)
+ ;
+ Ext = ext_cur_ngs_gs_err(ExtCurNgsGsErr),
+ globals.lookup_bool_option(Globals, error_files_in_subdir,
+ ErrorFilesInSubdir),
+ (
+ ErrorFilesInSubdir = no,
+ DirNames = []
+ ;
+ ErrorFilesInSubdir = yes,
+ globals.get_subdir_setting(Globals, SubdirSetting),
+ (
+ SubdirSetting = use_cur_dir,
+ DirNames = []
+ ;
+ SubdirSetting = use_cur_ngs_subdir,
+ ext_cur_ngs_gs_err_extension_dir(ExtCurNgsGsErr,
+ _ExtStr, SubDirName),
+ DirNames = make_ngs_dir_names(SubDirName)
+ ;
+ SubdirSetting = use_cur_ngs_gs_subdir,
+ ext_cur_ngs_gs_err_extension_dir(ExtCurNgsGsErr,
+ _ExtStr, SubDirName),
+ DirNames = make_gs_dir_names(Globals, SubDirName)
+ )
+ )
;
Ext = ext_cur_ngs_gs_java(ExtCurNgsGsJava),
% The Java code generator starts every .java file it creates with
diff --git a/compiler/make.build.m b/compiler/make.build.m
index a570d92b3..06b11bfce 100644
--- a/compiler/make.build.m
+++ b/compiler/make.build.m
@@ -275,7 +275,8 @@ setup_for_build_with_module_options(ProgressStream, DefaultOptionTable,
open_module_error_stream(ProgressStream, Globals, ModuleName, MaybeErrorStream,
!Info, !IO) :-
module_name_to_file_name_create_dirs(Globals, $pred,
- ext_cur(ext_cur_user_err), ModuleName, ErrorFileName, !IO),
+ ext_cur_ngs_gs_err(ext_cur_ngs_gs_err_err), ModuleName, ErrorFileName,
+ !IO),
ErrorFileModules0 = make_info_get_error_file_modules(!.Info),
( if set.contains(ErrorFileModules0, ModuleName) then
% Write the output to a temporary file first, to allow us to print
diff --git a/compiler/make.file_names.m b/compiler/make.file_names.m
index c93c67a43..32b94c636 100644
--- a/compiler/make.file_names.m
+++ b/compiler/make.file_names.m
@@ -197,7 +197,7 @@ target_type_to_target_extension(Target, TargetExt) :-
TargetExt = source
;
Target = module_target_errors,
- TargetExt = extension(ext_cur(ext_cur_user_err))
+ TargetExt = extension(ext_cur_ngs_gs_err(ext_cur_ngs_gs_err_err))
;
Target = module_target_int0,
TargetExt = extension(ext_cur_ngs(ext_cur_ngs_int_int0))
@@ -263,7 +263,7 @@ date_file_extension(ModuleTargetType, Ext) :-
% We need a timestamp file for `.err' files because errors are written
% to the `.err' file even when writing interfaces. The timestamp
% is only updated when compiling to target code.
- Ext = ext_cur_ngs_gs(ext_cur_ngs_gs_misc_err_date)
+ Ext = ext_cur_ngs_gs_err(ext_cur_ngs_gs_err_err)
;
ModuleTargetType = module_target_int0,
Ext = ext_cur_ngs(ext_cur_ngs_int_date_int0)
diff --git a/compiler/make.get_module_dep_info.m b/compiler/make.get_module_dep_info.m
index 23db18fb1..eb61e71f5 100644
--- a/compiler/make.get_module_dep_info.m
+++ b/compiler/make.get_module_dep_info.m
@@ -584,8 +584,8 @@ cannot_write_module_dep_files(Globals, ProgressStream, MESI, ErrorStream,
Globals, UnredirectGlobals),
close_module_error_stream_handle_errors(ProgressStream, UnredirectGlobals,
ModuleName, MESI, ErrorStream, !Info, !IO),
- module_name_to_file_name(Globals, $pred, ext_cur(ext_cur_user_err),
- ModuleName, ErrFileName),
+ module_name_to_file_name(Globals, $pred,
+ ext_cur_ngs_gs_err(ext_cur_ngs_gs_err_err), ModuleName, ErrFileName),
io.file.remove_file(ErrFileName, _, !IO),
ModuleDepMap0 = make_info_get_maybe_module_dep_info_map(!.Info),
diff --git a/compiler/options.m b/compiler/options.m
index 526319d6c..8e13f11ff 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -1143,6 +1143,7 @@
; options_search_directories
; setting_only_use_subdirs
; setting_only_use_grade_subdirs
+ ; error_files_in_subdir
; std_int_file_not_written_msgs
; search_directories
; intermod_directories
@@ -2132,6 +2133,7 @@ optdef(oc_buildsys, config_file, maybe_string(yes(""))).
optdef(oc_buildsys, options_search_directories, accumulating(["."])).
optdef(oc_buildsys, setting_only_use_subdirs, bool(no)).
optdef(oc_buildsys, setting_only_use_grade_subdirs, bool(no)).
+optdef(oc_buildsys, error_files_in_subdir, bool(no)).
optdef(oc_buildsys, std_int_file_not_written_msgs, bool(no)).
optdef(oc_buildsys, search_directories, accumulating(["."])).
optdef(oc_buildsys, intermod_directories, accumulating([])).
@@ -3304,6 +3306,7 @@ long_table("config-file", config_file).
long_table("options-search-directory", options_search_directories).
long_table("use-subdirs", setting_only_use_subdirs).
long_table("use-grade-subdirs", setting_only_use_grade_subdirs).
+long_table("error-files-in-subdir", error_files_in_subdir).
long_table("std-int-file-not-written-msgs",
std_int_file_not_written_msgs).
long_table("search-directory", search_directories).
@@ -7015,6 +7018,10 @@ options_help_build_system(Stream, !IO) :-
"\tthe current directory.",
"\t`--use-grade-subdirs' does not work with Mmake (it does",
"\twork with `mmc --make').",
+ "--error-files-in-subdir",
+ "\tGenerate .err files under the `Mercury' subdirectory",
+ "\trather than in the current directory.",
+ "\t(This option is only supported by `mmc --make'.)",
% This is used to eliminate the need for a .int_err_exp file for the
% -use-subdir case for every test in the tests/invalid_make_int directory.
% "--std-int-file-not-written-msgs",
diff --git a/doc/user_guide.texi b/doc/user_guide.texi
index 05e14881f..54151c795 100644
--- a/doc/user_guide.texi
+++ b/doc/user_guide.texi
@@ -10641,6 +10641,18 @@ current directory.
@samp{--use-grade-subdirs} does not work with Mmake (it does
work with @samp{mmc --make}).
+ at sp 1
+ at item --error-files-in-subdir
+ at findex --error-files-in-subdir
+ at cindex File names
+ at cindex Directories
+ at cindex Subdirectories
+ at cindex @file{Mercury} subdirectory
+Generate @file{.err} files (containing compiler error messages)
+under the @file{Mercury} subdirectory
+rather than in the current directory,
+when using @samp{mmc --make}.
+
@sp 1
@item --order-make-by-timestamp
@findex --order-make-by-timestamp
--
2.44.0
More information about the reviews
mailing list