diff options
author | pennae <github@quasiparticle.net> | 2022-09-01 19:23:59 +0200 |
---|---|---|
committer | pennae <82953136+pennae@users.noreply.github.com> | 2022-09-10 18:23:13 +0200 |
commit | 767485a0dee24329e2b34cd4af0c08ea21e959ea (patch) | |
tree | 13a42cff4608334fcd9f6f21e5a5758020782d7b /nixos/lib/make-options-doc | |
parent | 8c309aa43ae9e5e4dbdd542e4e5e49253d3dd763 (diff) | |
download | nixpkgs-767485a0dee24329e2b34cd4af0c08ea21e959ea.tar nixpkgs-767485a0dee24329e2b34cd4af0c08ea21e959ea.tar.gz nixpkgs-767485a0dee24329e2b34cd4af0c08ea21e959ea.tar.bz2 nixpkgs-767485a0dee24329e2b34cd4af0c08ea21e959ea.tar.lz nixpkgs-767485a0dee24329e2b34cd4af0c08ea21e959ea.tar.xz nixpkgs-767485a0dee24329e2b34cd4af0c08ea21e959ea.tar.zst nixpkgs-767485a0dee24329e2b34cd4af0c08ea21e959ea.zip |
lib/options: deprecate docbook text and literalDocBook
deprecate literalDocBook by adding a warning (that will not fire yet) to its uses and other docbook literal strings by adding optional warning message to mergeJSON.
Diffstat (limited to 'nixos/lib/make-options-doc')
-rw-r--r-- | nixos/lib/make-options-doc/default.nix | 29 | ||||
-rw-r--r-- | nixos/lib/make-options-doc/mergeJSON.py | 39 |
2 files changed, 52 insertions, 16 deletions
diff --git a/nixos/lib/make-options-doc/default.nix b/nixos/lib/make-options-doc/default.nix index 3f98e2cf87b..43dbff0e68d 100644 --- a/nixos/lib/make-options-doc/default.nix +++ b/nixos/lib/make-options-doc/default.nix @@ -34,6 +34,10 @@ # instead of printing warnings for eg options with missing descriptions (which may be lost # by nix build unless -L is given), emit errors instead and fail the build , warningsAreErrors ? true +# allow docbook option docs if `true`. only markdown documentation is allowed when set to +# `false`, and a different renderer may be used with different bugs and performance +# characteristics but (hopefully) indistinguishable output. +, allowDocBook ? true }: let @@ -127,26 +131,23 @@ in rec { ]; options = builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON optionsNix)); + # merge with an empty set if baseOptionsJSON is null to run markdown + # processing on the input options + baseJSON = + if baseOptionsJSON == null + then builtins.toFile "base.json" "{}" + else baseOptionsJSON; } '' # Export list of options in different format. dst=$out/share/doc/nixos mkdir -p $dst - ${ - if baseOptionsJSON == null - then '' - # `cp $options $dst/options.json`, but with temporary - # markdown processing - python ${./mergeJSON.py} $options <(echo '{}') > $dst/options.json - '' - else '' - python ${./mergeJSON.py} \ - ${lib.optionalString warningsAreErrors "--warnings-are-errors"} \ - ${baseOptionsJSON} $options \ - > $dst/options.json - '' - } + python ${./mergeJSON.py} \ + ${lib.optionalString warningsAreErrors "--warnings-are-errors"} \ + ${lib.optionalString (! allowDocBook) "--error-on-docbook"} \ + $baseJSON $options \ + > $dst/options.json brotli -9 < $dst/options.json > $dst/options.json.br diff --git a/nixos/lib/make-options-doc/mergeJSON.py b/nixos/lib/make-options-doc/mergeJSON.py index 1a1af11337e..eae9ca03124 100644 --- a/nixos/lib/make-options-doc/mergeJSON.py +++ b/nixos/lib/make-options-doc/mergeJSON.py @@ -212,8 +212,17 @@ def convertMD(options: Dict[str, Any]) -> str: return options -warningsAreErrors = sys.argv[1] == "--warnings-are-errors" -optOffset = 1 if warningsAreErrors else 0 +warningsAreErrors = False +errorOnDocbook = False +optOffset = 0 +for arg in sys.argv[1:]: + if arg == "--warnings-are-errors": + optOffset += 1 + warningsAreErrors = True + if arg == "--error-on-docbook": + optOffset += 1 + errorOnDocbook = True + options = pivot(json.load(open(sys.argv[1 + optOffset], 'r'))) overrides = pivot(json.load(open(sys.argv[2 + optOffset], 'r'))) @@ -241,9 +250,33 @@ for (k, v) in overrides.items(): severity = "error" if warningsAreErrors else "warning" +def is_docbook(o, key): + val = o.get(key, {}) + if not isinstance(val, dict): + return False + return val.get('_type', '') == 'literalDocBook' + # check that every option has a description hasWarnings = False +hasErrors = False for (k, v) in options.items(): + if errorOnDocbook: + if isinstance(v.value.get('description', {}), str): + hasErrors = True + print( + f"\x1b[1;31merror: option {v.name} description uses DocBook\x1b[0m", + file=sys.stderr) + elif is_docbook(v.value, 'defaultText'): + hasErrors = True + print( + f"\x1b[1;31merror: option {v.name} default uses DocBook\x1b[0m", + file=sys.stderr) + elif is_docbook(v.value, 'example'): + hasErrors = True + print( + f"\x1b[1;31merror: option {v.name} example uses DocBook\x1b[0m", + file=sys.stderr) + if v.value.get('description', None) is None: hasWarnings = True print(f"\x1b[1;31m{severity}: option {v.name} has no description\x1b[0m", file=sys.stderr) @@ -254,6 +287,8 @@ for (k, v) in options.items(): f"\x1b[1;31m{severity}: option {v.name} has no type. Please specify a valid type, see " + "https://nixos.org/manual/nixos/stable/index.html#sec-option-types\x1b[0m", file=sys.stderr) +if hasErrors: + sys.exit(1) if hasWarnings and warningsAreErrors: print( "\x1b[1;31m" + |