Skip to content

Commit 5b74ea2

Browse files
committed
Arm backend: Optimize public API manifest validation
Validate all public API manifests in one Python process to avoid repeated Torch imports while preserving per-manifest reporting and failure aggregation. Authored with Codex. Signed-off-by: Per Held <per.held@arm.com> Change-Id: I6213188a92795ef4bdaab4dae0894bbfc207adf9
1 parent a5174dc commit 5b74ea2

3 files changed

Lines changed: 58 additions & 32 deletions

File tree

‎backends/arm/scripts/public_api_manifest/validate_all_public_api_manifests.sh‎

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,5 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
set -u
8-
9-
echo "Validating Arm public API manifests"
10-
11-
manifest_failures=0
12-
for manifest_path in backends/arm/public_api_manifests/api_manifest_*.toml; do
13-
if [[ ! -f "${manifest_path}" ]]; then
14-
continue
15-
fi
16-
manifest_name="${manifest_path##*/}"
17-
echo
18-
echo "=== ${manifest_name} ==="
19-
validator_output=$(
20-
python backends/arm/scripts/public_api_manifest/validate_public_api_manifest.py \
21-
--manifest "${manifest_path}" 2>&1
22-
)
23-
validator_status=$?
24-
printf '%s\n' "${validator_output}"
25-
if [[ ${validator_status} -ne 0 ]]; then
26-
manifest_failures=$((manifest_failures + 1))
27-
fi
28-
done
29-
30-
echo
31-
if [[ ${manifest_failures} -eq 0 ]]; then
32-
echo "Arm public API manifests OK"
33-
else
34-
echo "${manifest_failures} manifest(s) failed validation"
35-
exit 1
36-
fi
7+
exec python backends/arm/scripts/public_api_manifest/validate_public_api_manifest.py \
8+
--all-manifests

‎backends/arm/scripts/public_api_manifest/validate_public_api_manifest.py‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
7-
"""Validate one Arm public API manifest against the current API."""
7+
"""Validate Arm public API manifests against the current API."""
88

99
from __future__ import annotations
1010

@@ -13,6 +13,7 @@
1313
import importlib.util
1414
import inspect
1515
from pathlib import Path
16+
from typing import Sequence
1617

1718
try:
1819
import tomllib
@@ -357,19 +358,48 @@ def validate_manifest(manifest_path: Path) -> list[Issue]:
357358
return issues
358359

359360

361+
def validate_manifests(manifest_paths: Sequence[Path]) -> int:
362+
failures = 0
363+
for manifest_path in manifest_paths:
364+
print()
365+
print(f"=== {manifest_path.name} ===")
366+
issues = validate_manifest(manifest_path)
367+
print(format_validation_report(manifest_path, issues))
368+
if issues:
369+
failures += 1
370+
return failures
371+
372+
360373
def parse_args() -> argparse.Namespace:
361374
parser = argparse.ArgumentParser()
362-
parser.add_argument(
375+
manifest_group = parser.add_mutually_exclusive_group()
376+
manifest_group.add_argument(
363377
"--manifest",
364378
type=Path,
365379
default=MANIFEST_PATH,
366380
help="Path to the public API manifest TOML file.",
367381
)
382+
manifest_group.add_argument(
383+
"--all-manifests",
384+
action="store_true",
385+
help="Validate every public API manifest in one process.",
386+
)
368387
return parser.parse_args()
369388

370389

371390
def main() -> None:
372391
args = parse_args()
392+
if args.all_manifests:
393+
print("Validating Arm public API manifests")
394+
manifest_paths = sorted(MANIFEST_PATH.parent.glob("api_manifest_*.toml"))
395+
failures = validate_manifests(manifest_paths)
396+
print()
397+
if failures:
398+
print(f"{failures} manifest(s) failed validation")
399+
raise SystemExit(1)
400+
print("Arm public API manifests OK")
401+
return
402+
373403
issues = validate_manifest(args.manifest)
374404
print(format_validation_report(args.manifest, issues))
375405
if issues:

‎backends/arm/test/misc/test_validate_public_api_manifest.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,30 @@ def test_running_manifest_validation_rejects_cmake_drift(tmp_path, monkeypatch):
122122
assert issues[0][1] == "signature changed"
123123

124124

125+
def test_validate_manifests_checks_every_manifest(monkeypatch, capsys):
126+
manifest_paths = [
127+
Path("api_manifest_1_4.toml"),
128+
Path("api_manifest_running.toml"),
129+
]
130+
validated_paths = []
131+
132+
def validate_manifest(manifest_path):
133+
validated_paths.append(manifest_path)
134+
if manifest_path.name == "api_manifest_running.toml":
135+
return [("foo", "signature changed", "foo()", "foo(x)")]
136+
return []
137+
138+
monkeypatch.setattr(vpam, "validate_manifest", validate_manifest)
139+
140+
failures = vpam.validate_manifests(manifest_paths)
141+
142+
assert failures == 1
143+
assert validated_paths == manifest_paths
144+
output = capsys.readouterr().out
145+
assert "=== api_manifest_1_4.toml ===" in output
146+
assert "=== api_manifest_running.toml ===" in output
147+
148+
125149
def test_nested_python_manifest_entries_are_validated():
126150
manifest_symbols = get_manifest_python_symbols(
127151
tomllib.loads(

0 commit comments

Comments
 (0)