From 112c2c3d02e77983645aabc0d4528b7e5582a9bf Mon Sep 17 00:00:00 2001 From: Andre Brisco Date: Wed, 25 Nov 2026 11:44:38 -0800 Subject: [PATCH] convert: Error on undecided decisions.bzl --- docs/src/convert.md | 12 ++-- gnulib/m4/decisions.bzl | 3 +- tools/convert/cli.py | 41 ++++++----- tools/convert/decisions.py | 67 +++++++++++------- tools/convert/tests/decisions_test.py | 69 ++++++++++++------- tools/convert/tests/golden/gzip.decisions.bzl | 3 +- .../tests/golden/gzip.decisions.needed.bzl | 3 +- .../tests/golden/posix_memalign.decisions.bzl | 3 +- .../posix_memalign.decisions.needed.bzl | 3 +- tools/convert/tests/translate_test.py | 6 +- tools/convert/translate.py | 3 +- 11 files changed, 132 insertions(+), 81 deletions(-) diff --git a/docs/src/convert.md b/docs/src/convert.md index bb80593c2..3f0ac764c 100644 --- a/docs/src/convert.md +++ b/docs/src/convert.md @@ -75,7 +75,11 @@ not translate under "Decisions required" in the report. Each is an entry of `decisions.bzl` with `decision.UNDECIDED` as its value: replace the value and run the same command again. The outputs are written even while decisions are missing, so the project can be looked at, but a conversion is complete only -when the file answers every question. +when the file answers every question. `UNDECIDED` is the placeholder the +converter writes, not an answer: a run that finds one still in the file stops +with an error naming the keys, and neither `DEFAULTS` nor the bundled +decisions answer for it. Every key gets an explicit decision, `IGNORE` when +the construct is to stay out. The file is read with a parser, never evaluated; its header names the rules_cc_autoconf that wrote it. New entries are added in key order with a @@ -85,7 +89,7 @@ converter stops asking for are reported as unused. A `checks.X(...)` value reads as in a BUILD file: add `load("@rules_cc_autoconf//autoconf:checks.bzl", "checks")` at the top. -A `DEFAULTS` table answers every undecided key of a kind at once, for a +A `DEFAULTS` table answers every key of a kind the table has no entry for, for a construct that never matters for the module (a firmware compiler's probes, a toolchain's warning flags); the report lists what a default answered: @@ -134,8 +138,8 @@ The questions every gnulib project raises the same way, the gettext probes and substitutions of a project that builds no message catalogs, gnulib's own witness variables, are answered once, in `gnulib/m4/decisions.bzl` beside the ports. The converter reads it beneath the project's decisions -file: a key the project's file answers wins, a key it leaves out or -`UNDECIDED` takes the bundled answer, and only then does `DEFAULTS` apply. +file: a key the project's file answers wins, a key it leaves out takes the +bundled answer, and only then does `DEFAULTS` apply. The report lists every answer taken from it under "Decisions inherited", so nothing applies silently; the bundled file's own keys never count as unused. `--bundled-decisions FILE` reads another file, `none` reads none; diff --git a/gnulib/m4/decisions.bzl b/gnulib/m4/decisions.bzl index ff53b9e63..7eef2fe9b 100644 --- a/gnulib/m4/decisions.bzl +++ b/gnulib/m4/decisions.bzl @@ -17,7 +17,8 @@ Reference: https://periareon.github.io/rules_cc_autoconf/convert.html#decisions # The words a decision may be, besides a literal, a select() or checks.X(...). decision = struct( - # Not decided yet: the construct stays out and the run exits 3. + # The placeholder written for a key the converter asks about; not an answer. + # The next run rejects the file while one remains. UNDECIDED = "UNDECIDED", # Leave the construct out for good. IGNORE = "IGNORE", diff --git a/tools/convert/cli.py b/tools/convert/cli.py index 1cab6160a..40afcb6dd 100644 --- a/tools/convert/cli.py +++ b/tools/convert/cli.py @@ -40,7 +40,7 @@ from tools.convert import project as project_mod from tools.convert import source as source_mod from tools.convert.common import DEFAULT_COMMAND, TOP_HEADERS -from tools.convert.decisions import MIGRATION_GUIDE, Decisions +from tools.convert.decisions import MIGRATION_GUIDE, DecisionError, Decisions from tools.convert.index import PortIndex, ports_checkout from tools.convert.ir import Package from tools.convert.ports import PortSnapshot @@ -876,7 +876,8 @@ def _write_report( "", "The constructs below have no mechanical translation and were left out. Decide each", f"key in `{decisions_path}` (the migration guide, {MIGRATION_GUIDE}, is the reference", - "for how each construct maps) and run the same command again" + "for how each construct maps) and run the same command again; an entry left `UNDECIDED`" + " is an error on that run" + (f" ({len(added)} new entries were added with `UNDECIDED` as the value)." if added else "."), "", ] @@ -895,7 +896,7 @@ def _write_report( "", f"## Decisions taken by default ({len(decisions.defaulted)})", "", - "Keys the table leaves undecided that `DEFAULTS` answered by kind; an entry for a key", + "Keys the table has no entry for that `DEFAULTS` answered by kind; an entry for a key", "overrides its kind's default.", "", ] + decisions.defaulted_lines() @@ -910,7 +911,10 @@ def _write_report( print(f"wrote {path}") print(f"report: {out / 'CONVERSION_REPORT.md'}") if pending: - print(f"{len(pending)} decision(s) required; fill in {decisions_path} and rerun", file=sys.stderr) + print( + f"{len(pending)} decision(s) required; answer every UNDECIDED entry in {decisions_path} and rerun", + file=sys.stderr, + ) return 3 return 0 @@ -1611,21 +1615,26 @@ def build_parser() -> argparse.ArgumentParser: def main(argv: list[str] | None = None) -> int: """Run the command line. The exit code is 0, 1 when the expansion fails, 2 on a usage or - environment error, 3 when decisions are required. + environment error or a decisions file the converter rejects (an entry still `UNDECIDED`, + a value of the wrong shape), 3 when decisions are required. """ args = build_parser().parse_args(argv) command: Callable[[argparse.Namespace], int] = args.func - if args.profile: - profile_path = _resolve(args.profile) - profiler = cProfile.Profile() - code = profiler.runcall(command, args) - profiler.dump_stats(profile_path) - with profile_path.with_suffix(profile_path.suffix + ".txt").open("w", encoding="utf-8") as out: - stats = pstats.Stats(profiler, stream=out).sort_stats("cumulative") - stats.print_stats(40) - stats.sort_stats("tottime").print_stats(25) - return code - return command(args) + try: + if args.profile: + profile_path = _resolve(args.profile) + profiler = cProfile.Profile() + code = profiler.runcall(command, args) + profiler.dump_stats(profile_path) + with profile_path.with_suffix(profile_path.suffix + ".txt").open("w", encoding="utf-8") as out: + stats = pstats.Stats(profiler, stream=out).sort_stats("cumulative") + stats.print_stats(40) + stats.sort_stats("tottime").print_stats(25) + return code + return command(args) + except DecisionError as error: + print(f"error: {error}", file=sys.stderr) + return 2 if __name__ == "__main__": diff --git a/tools/convert/decisions.py b/tools/convert/decisions.py index 8577db5aa..8e29a24cc 100644 --- a/tools/convert/decisions.py +++ b/tools/convert/decisions.py @@ -6,8 +6,11 @@ construct up in a decisions file by a stable key. A missing decision is reported, the construct is left out of the output, and the key is added to the decisions file with its context as comments and `UNDECIDED` as its -value; nothing is guessed. Regenerating with the same sources and the same -decisions file reproduces the same output. +value; nothing is guessed. `UNDECIDED` is that placeholder and not an +answer: a file that still holds one is rejected at load, so every key gets +an explicit decision (`IGNORE` when the construct is to stay out). +Regenerating with the same sources and the same decisions file reproduces +the same output. The decisions file is Starlark, written in the vocabulary of the output and read with Python's `ast` module (never executed). It defines the `decision` @@ -26,10 +29,10 @@ "flag:gcc_warnings": False, } -A value is a word of the struct (`decision.UNDECIDED`, `decision.IGNORE`, -`decision.ACCEPT`, `decision.ACCEPT_PARTIAL`, `decision.ALWAYS`, -`decision.NEVER`, `decision.MANUAL`; the bare word is still read, for files -written before the struct); a literal; a `select({...})` over configuration labels; or +A value is a word of the struct (`decision.IGNORE`, `decision.ACCEPT`, +`decision.ACCEPT_PARTIAL`, `decision.ALWAYS`, `decision.NEVER`, +`decision.MANUAL`; the bare word is still read, for files written before +the struct); a literal; a `select({...})` over configuration labels; or `checks.*` / `macros.*` / `utils.*` calls exactly as they would appear in `BUILD.bazel` (one call or a list of calls). Which of these a key accepts depends on its kind; see `FORMS`. @@ -359,6 +362,24 @@ def _parse(text: str, source: str) -> tuple[dict[str, DecisionValue], ast.Dict | return table, node, defaults +def _reject_undecided(table: dict[str, DecisionValue], node: ast.Dict | None, source: str) -> None: + """`UNDECIDED` is the placeholder the skeleton writes for a key the converter asked about, + not an answer: a file that still holds one is rejected, naming the keys, so that every + question gets an explicit decision rather than a silent omission or a default.""" + undecided = [key for key, value in table.items() if isinstance(value, Word) and value.name == "UNDECIDED"] + if not undecided: + return + lines = {k.value: k.lineno for k in node.keys if isinstance(k, ast.Constant)} if node is not None else {} + where = f"{source}:{lines[undecided[0]]}" if undecided[0] in lines else source + count = f"{len(undecided)} {'entry is' if len(undecided) == 1 else 'entries are'}" + shown = ", ".join(undecided[:6]) + (", ..." if len(undecided) > 6 else "") + raise DecisionError( + f"{where}: {count} still {STRUCT_NAME}.UNDECIDED ({shown}); that is the placeholder the " + f"converter writes, not an answer: decide each ({STRUCT_NAME}.IGNORE leaves the construct out) " + "and run again" + ) + + def _attr_value(value: DecisionValue, where: str) -> AttrValue: """A decision value as a call's argument: a Starlark value. A word, a `select()` or a rule call has no place inside `checks.X(...)` (the emitter renders none of them) and is an error.""" @@ -689,11 +710,13 @@ def load(cls, path: Path | None) -> Decisions: return cls(source=str(path) if path else None) text = path.read_text(encoding="utf-8").replace("\r\n", "\n") data, node, defaults = _parse(text, str(path)) + _reject_undecided(data, node, str(path)) return cls(data, str(path), node, text, defaults) @classmethod def from_text(cls, text: str, source: str = "") -> Decisions: data, node, defaults = _parse(text, source) + _reject_undecided(data, node, source) return cls(data, source, node, text, defaults) def _record(self, request: Request) -> None: @@ -704,9 +727,7 @@ def resolve(self, request: Request) -> Decision | None: """The normalized decision for `request`: the key's, else the kind's default (recorded under `defaulted`), else None and the request is pending.""" value = self.data.get(request.key) - if value is not None: - self.used.add(request.key) - if value is None or (isinstance(value, Word) and value.name == "UNDECIDED"): + if value is None: shared = self._shared(request.key) if shared is not None: return normalize(request.kind, request.key, shared) @@ -715,6 +736,7 @@ def resolve(self, request: Request) -> Decision | None: return normalize(request.kind, request.key, self.defaults[request.kind]) self._record(request) return None + self.used.add(request.key) return normalize(request.kind, request.key, value) def lookup(self, key: str) -> DecisionValue | None: @@ -738,7 +760,7 @@ def _shared(self, key: str) -> DecisionValue | None: if self.shared is None: return None value = self.shared.data.get(key) - if value is None or (isinstance(value, Word) and value.name == "UNDECIDED"): + if value is None: return None self.shared.used.add(key) self.inherited.setdefault(key, _spell(value)) @@ -747,31 +769,22 @@ def _shared(self, key: str) -> DecisionValue | None: def optional(self, key: str, kind: str) -> Decision | None: """A decision that is applied when present and never requested.""" value = self.data.get(key) - if value is None or (isinstance(value, Word) and value.name == "UNDECIDED"): + if value is None: shared = self._shared(key) return normalize(kind, key, shared) if shared is not None else None self.used.add(key) return normalize(kind, key, value) def decided(self, key: str) -> bool: - """Whether the file, or the bundled one beneath it, answers `key`: an entry whose value is - not `UNDECIDED`. Reading the tables directly, it does not count the key as used - (`optional` and `resolve` do).""" - value = self.data.get(key) - if value is not None and not (isinstance(value, Word) and value.name == "UNDECIDED"): - return True - return self.shared is not None and self.shared.decided(key) + """Whether the file, or the bundled one beneath it, has an entry for `key`. Reading the + tables directly, it does not count the key as used (`optional` and `resolve` do).""" + return key in self.data or (self.shared is not None and self.shared.decided(key)) @property def unused(self) -> list[str]: """Decisions the conversion never asked for.""" return sorted(k for k in self.data if k not in self.used) - @property - def missing(self) -> list[str]: - """Pending keys that are not in the file at all (as opposed to UNDECIDED).""" - return sorted(k for k in self.pending if k not in self.data) - # -- writing the skeleton ------------------------------------------------- def entries(self, keys: list[str] | None = None) -> str: @@ -795,8 +808,9 @@ def write_needed(self, path: Path, title: str | None = None, version: str = "?") The table stays sorted by key (buildifier's `unsorted-dict-items`): a new entry goes in front of the first existing key that sorts after it, above that key's comment block, - or at the end when none does.""" - keys = self.missing + or at the end when none does. Every pending key is absent from the file: an entry + still `UNDECIDED` from an earlier run is rejected at load.""" + keys = sorted(self.pending) if not keys: return [] if self._node is None or not self._text: @@ -869,7 +883,8 @@ def _spell(value: DecisionValue) -> str: STRUCT = """# The words a decision may be, besides a literal, a select() or checks.X(...). decision = struct( - # Not decided yet: the construct stays out and the run exits 3. + # The placeholder written for a key the converter asks about; not an answer. + # The next run rejects the file while one remains. UNDECIDED = "UNDECIDED", # Leave the construct out for good. IGNORE = "IGNORE", diff --git a/tools/convert/tests/decisions_test.py b/tools/convert/tests/decisions_test.py index 90810de40..79520b9c0 100644 --- a/tools/convert/tests/decisions_test.py +++ b/tools/convert/tests/decisions_test.py @@ -37,7 +37,6 @@ "flag:gcc_warnings": False, "src_condition:GL_X": "REPLACE_X==1", "am_conditional:AMC": ":dfltcc_enabled", - "probe:gl_cv_later": UNDECIDED, } ''') @@ -101,7 +100,7 @@ def resolve(key: str, kind: str) -> dec.Decision: arm = resolve("am_conditional:AMC", "am_conditional") assert (shape(arm), arm.arm) == ({"arm"}, ":dfltcc_enabled") assert decisions.pending == {} - assert decisions.unused == ["probe:gl_cv_later"] + assert decisions.unused == [] def test_guard_select_arms() -> None: @@ -147,27 +146,24 @@ def test_includes_spelled_as_directives() -> None: def test_defaults_by_kind() -> None: - """`DEFAULTS` answers every undecided key of a kind; an entry overrides it; the answered - keys are reported apart and never pending; a bad default is an error at load.""" + """`DEFAULTS` answers every key of a kind the table has no entry for; an entry overrides it; + the answered keys are reported apart and never pending; a bad default is an error at load.""" decisions = dec.Decisions.from_text("""DEFAULTS = { "probe": decision.IGNORE, } DECISIONS = { "probe:my_cv_kept": decision.ACCEPT, - "probe:my_cv_open": decision.UNDECIDED, }""") def resolve(key: str, kind: str) -> dec.Decision | None: return decisions.resolve(dec.Request(key, kind, "configure.ac:1", "why")) assert must(resolve("probe:my_cv_kept", "probe")).accept - assert must(resolve("probe:my_cv_open", "probe")).ignore assert must(resolve("probe:my_cv_new", "probe")).ignore assert resolve("variable:X", "variable") is None - assert sorted(decisions.defaulted) == ["probe:my_cv_new", "probe:my_cv_open"] + assert sorted(decisions.defaulted) == ["probe:my_cv_new"] assert sorted(decisions.pending) == ["variable:X"] - assert decisions.missing == ["variable:X"] assert decisions.unused == [] assert "-> `decision.IGNORE`" in decisions.defaulted_lines()[0] with pytest.raises(dec.DecisionError): @@ -301,13 +297,29 @@ def test_multiline_reason_stays_a_comment() -> None: assert " # *yes*) ;; esac)" in lines -def test_undecided_and_missing_are_pending(decisions: dec.Decisions) -> None: - assert decisions.resolve(request("probe:gl_cv_later", "probe")) is None +def test_missing_keys_are_pending(decisions: dec.Decisions) -> None: assert decisions.resolve(request("probe:gl_cv_new", "probe")) is None - assert sorted(decisions.pending) == ["probe:gl_cv_later", "probe:gl_cv_new"] - # UNDECIDED entries are in the file already: only the new key is missing from it. - assert decisions.missing == ["probe:gl_cv_new"] - assert "probe:gl_cv_later" not in decisions.unused + assert sorted(decisions.pending) == ["probe:gl_cv_new"] + + +def test_undecided_entry_is_rejected() -> None: + """`UNDECIDED` is the skeleton's placeholder, not an answer: a file that still holds one is + rejected at load, naming the keys and the first one's line, whatever else it answers. A + bundled answer or a `DEFAULTS` entry for the key does not excuse it.""" + text = ( + 'DEFAULTS = {"probe": decision.IGNORE}\n' + "DECISIONS = {\n" + ' "probe:gl_cv_a": "yes",\n' + ' "probe:gl_cv_later": decision.UNDECIDED,\n' + ' "variable:Z": UNDECIDED,\n' + "}\n" + ) + with pytest.raises( + dec.DecisionError, match=r"^d\.bzl:4: 2 entries are still decision\.UNDECIDED \(probe:gl_cv_later, variable:Z\)" + ): + dec.Decisions.from_text(text, "d.bzl") + with pytest.raises(dec.DecisionError, match=r"1 entry is still"): + dec.Decisions.from_text('DECISIONS = {"macro:m": decision.UNDECIDED}\n') def test_wrong_shapes(decisions: dec.Decisions) -> None: @@ -328,6 +340,7 @@ def test_wrong_shapes(decisions: dec.Decisions) -> None: pytest.param("x = 1\n", id="no-table"), pytest.param('DECISIONS = {"k": SOMETHING}\n', id="unknown-word"), pytest.param('DECISIONS = {"k": 1, "k": 2}\n', id="duplicate-key"), + pytest.param('DECISIONS = {"probe:k": decision.UNDECIDED}\n', id="undecided-entry"), pytest.param('DECISIONS = {"k": b"x"}\n', id="bytes-literal"), pytest.param('DECISIONS = {"k": checks.AC_DEFINE("X", decision.IGNORE)}\n', id="word-in-call"), pytest.param( @@ -355,12 +368,16 @@ def test_create_then_append(tmp_path: Path) -> None: # The probe program sits in a fenced block tagged with its language. assert " # program:\n # ```c\n # int x;\n # int y;\n # ```\n" in text assert "Generated by: rules_cc_autoconf ?\n" in text # no version given here - # The user decides one key and hand-formats the file; a later run adds the new key only. + # The skeleton is not an answer: the file is rejected until every key is decided. + with pytest.raises(dec.DecisionError, match=r"2 entries are still .*probe:gl_cv_x, variable:Y"): + dec.Decisions.load(path) + # The user decides both keys and hand-formats the file; a later run adds the new key only. edited = text.replace('"probe:gl_cv_x": decision.UNDECIDED,', '"probe:gl_cv_x": "no", # decided') + edited = edited.replace('"variable:Y": decision.UNDECIDED,', '"variable:Y": decision.IGNORE,') path.write_text(edited, encoding="utf-8") second = dec.Decisions.load(path) assert must(second.resolve(request("probe:gl_cv_x", "probe"))).value == "no" - assert second.resolve(request("variable:Y", "variable")) is None + assert must(second.resolve(request("variable:Y", "variable"))).ignore assert second.resolve(request("macro:gl_Z", "macro")) is None assert second.write_needed(path) == ["macro:gl_Z"] final = path.read_text(encoding="utf-8") @@ -370,9 +387,9 @@ def test_create_then_append(tmp_path: Path) -> None: assert final.startswith(head + "DECISIONS = {\n # ---- macro: gl_Z\n"), final[:400] assert final.endswith(body), "existing text is kept" assert '"macro:gl_Z": decision.UNDECIDED,\n\n # ---- probe: gl_cv_x\n' in final - assert final.count("UNDECIDED,") == 2 - third = dec.Decisions.load(path) - assert sorted(third.data) == ["macro:gl_Z", "probe:gl_cv_x", "variable:Y"] + assert final.count("UNDECIDED,") == 1 + with pytest.raises(dec.DecisionError, match=r"1 entry is still .*\(macro:gl_Z\)"): + dec.Decisions.load(path) # the new entry is the one still to decide def test_append_to_empty_table(tmp_path: Path) -> None: @@ -384,7 +401,8 @@ def test_append_to_empty_table(tmp_path: Path) -> None: text = path.read_text(encoding="utf-8") assert "DECISIONS = {\n" in text assert text.rstrip().endswith(' "flag:x": decision.UNDECIDED,\n}'), text - dec.Decisions.load(path) # still parses + with pytest.raises(dec.DecisionError, match=r"\(flag:x\)"): + dec.Decisions.load(path) # parses; rejected for the entry still to decide def test_new_entries_keep_the_table_sorted(tmp_path: Path) -> None: @@ -411,19 +429,20 @@ def test_new_entries_keep_the_table_sorted(tmp_path: Path) -> None: " # ---- variable: z\n" ) in text assert text.rstrip().endswith(' "variable:z": decision.UNDECIDED,\n}'), text - assert sorted(dec.Decisions.load(path).data) == keys # still parses, nothing lost + with pytest.raises(dec.DecisionError, match=r"\(macro:m, probe:b, variable:z\)"): + dec.Decisions.load(path) # parses; the three new entries are the ones still to decide def test_bundled_layer() -> None: - """The bundled decisions answer beneath the project's own: a key the project leaves out or - UNDECIDED takes the bundled answer and is recorded as inherited; the project's own entry - wins; the bundled file's keys never count as unused; `decided` sees both.""" + """The bundled decisions answer beneath the project's own: a key the project leaves out + takes the bundled answer and is recorded as inherited; the project's own entry wins; the + bundled file's keys never count as unused; `decided` sees both.""" bundled = dec.Decisions.from_text( 'DECISIONS = {"variable:LIBINTL": decision.IGNORE, "variable:POSUB": decision.IGNORE, "probe:x": "no"}\n', "gnulib/m4/decisions.bzl", ) own = dec.Decisions.from_text( - 'DECISIONS = {"variable:LIBINTL": decision.UNDECIDED, "probe:x": "yes", "probe:own": "1"}\n', + 'DECISIONS = {"probe:x": "yes", "probe:own": "1"}\n', "decisions.bzl", ) own.shared = bundled diff --git a/tools/convert/tests/golden/gzip.decisions.bzl b/tools/convert/tests/golden/gzip.decisions.bzl index eb8492e1e..4fab7ef31 100644 --- a/tools/convert/tests/golden/gzip.decisions.bzl +++ b/tools/convert/tests/golden/gzip.decisions.bzl @@ -10,7 +10,8 @@ Reference: https://periareon.github.io/rules_cc_autoconf/convert.html#decisio # The words a decision may be, besides a literal, a select() or checks.X(...). decision = struct( - # Not decided yet: the construct stays out and the run exits 3. + # The placeholder written for a key the converter asks about; not an answer. + # The next run rejects the file while one remains. UNDECIDED = "UNDECIDED", # Leave the construct out for good. IGNORE = "IGNORE", diff --git a/tools/convert/tests/golden/gzip.decisions.needed.bzl b/tools/convert/tests/golden/gzip.decisions.needed.bzl index 14afbf3d8..abac4c1ef 100644 --- a/tools/convert/tests/golden/gzip.decisions.needed.bzl +++ b/tools/convert/tests/golden/gzip.decisions.needed.bzl @@ -10,7 +10,8 @@ Reference: https://periareon.github.io/rules_cc_autoconf/convert.html#decisio # The words a decision may be, besides a literal, a select() or checks.X(...). decision = struct( - # Not decided yet: the construct stays out and the run exits 3. + # The placeholder written for a key the converter asks about; not an answer. + # The next run rejects the file while one remains. UNDECIDED = "UNDECIDED", # Leave the construct out for good. IGNORE = "IGNORE", diff --git a/tools/convert/tests/golden/posix_memalign.decisions.bzl b/tools/convert/tests/golden/posix_memalign.decisions.bzl index 854e81ca4..dd9874d3e 100644 --- a/tools/convert/tests/golden/posix_memalign.decisions.bzl +++ b/tools/convert/tests/golden/posix_memalign.decisions.bzl @@ -10,7 +10,8 @@ Reference: https://periareon.github.io/rules_cc_autoconf/convert.html#decisio # The words a decision may be, besides a literal, a select() or checks.X(...). decision = struct( - # Not decided yet: the construct stays out and the run exits 3. + # The placeholder written for a key the converter asks about; not an answer. + # The next run rejects the file while one remains. UNDECIDED = "UNDECIDED", # Leave the construct out for good. IGNORE = "IGNORE", diff --git a/tools/convert/tests/golden/posix_memalign.decisions.needed.bzl b/tools/convert/tests/golden/posix_memalign.decisions.needed.bzl index d46c24f8e..090bfd360 100644 --- a/tools/convert/tests/golden/posix_memalign.decisions.needed.bzl +++ b/tools/convert/tests/golden/posix_memalign.decisions.needed.bzl @@ -10,7 +10,8 @@ Reference: https://periareon.github.io/rules_cc_autoconf/convert.html#decisio # The words a decision may be, besides a literal, a select() or checks.X(...). decision = struct( - # Not decided yet: the construct stays out and the run exits 3. + # The placeholder written for a key the converter asks about; not an answer. + # The next run rejects the file while one remains. UNDECIDED = "UNDECIDED", # Leave the construct out for good. IGNORE = "IGNORE", diff --git a/tools/convert/tests/translate_test.py b/tools/convert/tests/translate_test.py index ad951c831..7dc74db36 100644 --- a/tools/convert/tests/translate_test.py +++ b/tools/convert/tests/translate_test.py @@ -2958,7 +2958,7 @@ def test_subdir_gates(tmp_path: Path) -> None: notes: list[str] = [] kept, gates = _subdir_gates(root, state, decisions, ["extension", "doc", "linuxonly"], notes) assert kept == ["extension", "doc", "linuxonly"] - assert "subdir:extension" in decisions.missing + assert "subdir:extension" in decisions.pending assert "doc" not in gates # Undecided: defined but manual, as a probe-conditioned program is. assert gates["extension"].compatible_with is None @@ -2976,7 +2976,7 @@ def test_subdir_gates(tmp_path: Path) -> None: assert '"@rules_cc//cc/compiler:msvc-cl": ["@platforms//:incompatible"]' in text assert '"//:extensions_off": ["@platforms//:incompatible"]' in text assert '"//conditions:default": []' in text - assert decisions.missing == [] + assert decisions.pending == {} decisions = Decisions.from_text('DECISIONS = {"subdir:extension": decision.MANUAL}') kept, gates = _subdir_gates(root, state, decisions, ["extension"], []) assert kept == ["extension"] @@ -2986,7 +2986,7 @@ def test_subdir_gates(tmp_path: Path) -> None: kept, gates = _subdir_gates(root, state, decisions, ["extension"], []) assert kept == ["extension"] assert '":extensions_on": []' in must(gates["extension"].compatible_with).text - assert decisions.missing == [] + assert decisions.pending == {} def test_gate_package() -> None: diff --git a/tools/convert/translate.py b/tools/convert/translate.py index f18daaf4a..c29383d37 100644 --- a/tools/convert/translate.py +++ b/tools/convert/translate.py @@ -1369,8 +1369,7 @@ def _pkg_verdict(self, specs: str) -> tuple[bool, list[libraries.Library], str]: def _decided_probe(self, node: Node) -> bool: """The decisions file has a value for this cache check's variable.""" var = cache_node_var(node) - value = self.decisions.lookup(f"probe:{var}") if var else None - return value is not None and not (isinstance(value, dec.Word) and value.name == "UNDECIDED") + return bool(var) and self.decisions.lookup(f"probe:{var}") is not None def _cond_if_shell(self, node: Node) -> str: """The shell that stands in for `AM_COND_IF([COND], [if-true], [if-false])` in the