summaryrefslogtreecommitdiffstats
path: root/tools/test-surface.py
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-20 23:53:49 +0000
committeraur-build <aur-build@localhost>2026-11-20 23:53:49 +0000
commit28023ba17adbe6fc096a31d5e2c62d017a88fc4c (patch)
tree53b948169a47c012126466142aec80450eb07f9d /tools/test-surface.py
parent66814ddb86009de7a519f167db634dab3e924fa8 (diff)
downloadaur-build-28023ba17adbe6fc096a31d5e2c62d017a88fc4c.tar.gz
aur-build-28023ba17adbe6fc096a31d5e2c62d017a88fc4c.zip
tools: the detector learns to see through a private inner module
`aliased_behind_private_module` reports an item as not release-exposed only when both halves of the pattern hold: a `pub use ..::NAME;` whose attribute block carries the test-support gate, and every `pub` declaration of the name sitting inside a module that is itself private. Either half alone is not enough — a gated alias to a genuinely public type says nothing, and a `pub` type in a public module is reachable whatever the alias says. The census still counts the inner `pub` as a public declaration, which is the honest reading of the text and the reason this needed a second check rather than a change to the first. New `narrowed` disposition, distinct from `already-gated`: production *does* use these items, just never from outside their module. `residue` and `ungated` are now 0 and the ratchet records it. Every one of the 46 items carries a hand-written reason naming its production caller or explaining why it has none.
Diffstat (limited to 'tools/test-surface.py')
-rw-r--r--tools/test-surface.py56
1 files changed, 55 insertions, 1 deletions
diff --git a/tools/test-surface.py b/tools/test-surface.py
index b21133a..6121889 100644
--- a/tools/test-surface.py
+++ b/tools/test-surface.py
@@ -182,6 +182,59 @@ def gated_declarations(path):
return out
+def aliased_behind_private_module(path, name):
+ """True when the only public path to `name` is a gated `pub use` alias.
+
+ The inner-module narrowing declares the item `pub` inside a module nobody
+ outside can name, then re-exports it under a feature gate:
+
+ mod kata_backend { pub struct KataBackend { ... } }
+ #[cfg(feature = "test-support")] pub use kata_backend::KataBackend;
+ #[cfg(not(feature = "test-support"))] pub(crate) use kata_backend::KataBackend;
+
+ The census sees the inner `pub` and calls it a public declaration. It is
+ not one: a `pub` item in a private module has no nameable path, and the
+ alias that gives it one is gated. Both halves must hold for this to be true.
+ """
+ lines = open(path).read().split("\n")
+
+ # 1. is there a `pub use ...::NAME;` whose attribute block carries the gate?
+ aliased = False
+ for i, line in enumerate(lines):
+ if not re.search(r"^\s*pub\s+use\s+[^;]*::%s\b" % re.escape(name), line):
+ continue
+ k = i - 1
+ while k >= i - 8 and (lines[k].strip().startswith("#[")
+ or lines[k].strip().startswith("//")
+ or not lines[k].strip()):
+ if GATE in lines[k]:
+ aliased = True
+ k -= 1
+ if not aliased:
+ return False
+
+ # 2. does every `pub` declaration of the name sit inside a private module?
+ decls = [i for i, l in enumerate(lines)
+ if re.match(r"^\s*pub\s+(?:fn|struct|enum|trait|const|static|type)\s+%s\b"
+ % re.escape(name), l)]
+ if not decls:
+ return False
+ for d in decls:
+ depth, enclosed = 0, []
+ for k in range(d - 1, -1, -1):
+ # Walking backwards, an unmatched `{` means that line opens a block
+ # we are inside of.
+ depth += lines[k].count("{") - lines[k].count("}")
+ if depth > 0:
+ m = re.match(r"^\s*(pub(?:\(crate\))?\s+)?mod\s+(\w+)", lines[k])
+ if m:
+ enclosed.append(m.group(1))
+ depth -= 1
+ if not enclosed or any(enc for enc in enclosed):
+ return False
+ return True
+
+
def integration_tests(path):
lines = open(path).read().split("\n")
starts = [i for i, l in enumerate(lines) if l.lstrip().startswith("#[test]")]
@@ -220,7 +273,8 @@ def analyse():
occ = [(os.path.relpath(p, ROOT), ln, g)
for p in paths for (ln, g) in gated_declarations(p).get(name, [])]
- gated = any(g for _, _, g in occ)
+ gated = any(g for _, _, g in occ) or any(
+ aliased_behind_private_module(p, name) for p in paths)
# A mention inside a string literal is not a call.
string_only = all(