From 85aabb772c69ca461d7c237a662831b8d05e4f70 Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Thu, 11 May 2023 11:33:50 +0200 Subject: [PATCH] [machdep] better warning for missing fields in generated YAML + documentation --- doc/developer/advance.tex | 11 ++++++++++- share/machdeps/make_machdep/make_machdep.py | 13 +++++++------ share/machdeps/make_machdep/nsig.c | 2 +- share/machdeps/make_machdep/posix_version.c | 2 -- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/doc/developer/advance.tex b/doc/developer/advance.tex index eccc95f2e52..13357f76e11 100644 --- a/doc/developer/advance.tex +++ b/doc/developer/advance.tex @@ -3240,11 +3240,20 @@ is to use standard output). \item \texttt{--help}: outputs the list of all options of the script. \end{description} +Note that for some compiler setups, notably for non-POSIX compilation targets, +the script may fail to find an appropriate value for some fields and will +instead put some default value. In that case, warnings will give the names of +the problematic fields. Since the issue likely stems from the fact that the +corresponding C feature is not supported on the compilation target in the first +place, in practice, such feature is not expected to be found in code written for +such target. However, users are invited to review the generated YAML and +provide more appropriate values for these fields if needed. + In order to communicate machine-related information to the preprocessor (notably the value of standard macros), \framac generates a specific header, \verb+__fc_machdep.h+, that is automatically included by the standard headers from \framac's standard C library. Field \verb+custom_defs+ of the YAML file allows -customizing this header (see next section for more information) +customizing this header (see next section for more information). \subsection{Machdep record fields}\label{sec:machdep-fields} diff --git a/share/machdeps/make_machdep/make_machdep.py b/share/machdeps/make_machdep/make_machdep.py index 6d15918e72b..c7a8cabe9fc 100755 --- a/share/machdeps/make_machdep/make_machdep.py +++ b/share/machdeps/make_machdep/make_machdep.py @@ -169,8 +169,8 @@ def default_value(typ): def make_machdep(): machdep = {} - for key, value in schema.items(): - machdep[key] = default_value(value["type"]) + for key in schema: + machdep[key] = None return machdep @@ -269,8 +269,7 @@ def find_value(name, typ, output): machdep[name] = value else: logging.warning( - f"cannot find value of field '{name}', using default value: '{default}'", - stacklevel=-1, + f"cannot find value of field '{name}', using default value: '{default}'" ) machdep[name] = default if args.verbose: @@ -419,7 +418,9 @@ else: missing_fields = [f for [f, v] in machdep.items() if v is None] if missing_fields: - print("WARNING: the following fields are missing from the machdep definition:") - print(", ".join(missing_fields)) + msg = ", ".join(missing_fields) + logging.warning(f"the following fields are missing from the machdep definition: {msg}") + for field in missing_fields: + machdep[field] = default_value(schema[field]["type"]) print_machdep(machdep) diff --git a/share/machdeps/make_machdep/nsig.c b/share/machdeps/make_machdep/nsig.c index 5fa6451f020..e82b4fbe2eb 100644 --- a/share/machdeps/make_machdep/nsig.c +++ b/share/machdeps/make_machdep/nsig.c @@ -24,6 +24,6 @@ #if defined(NSIG) int nsig_is = NSIG; -#elif defined(_NSIG); +#elif defined(_NSIG) int nsig_is = _NSIG; #endif diff --git a/share/machdeps/make_machdep/posix_version.c b/share/machdeps/make_machdep/posix_version.c index 73d92daf747..bdd131ffc0d 100644 --- a/share/machdeps/make_machdep/posix_version.c +++ b/share/machdeps/make_machdep/posix_version.c @@ -24,6 +24,4 @@ #if defined(_POSIX_VERSION) long posix_version_is = _POSIX_VERSION; -#else -#error "not a posix arch" #endif -- GitLab