cb424d7448
verify-patch-sanity.py validates every active recipe .patch has internally- consistent hunk line counts — catching the 'malformed patch at line N' failure at commit/CI/preflight time instead of hours into a cook. This cycle hit that class three times (qtwaylandscanner, sddm, xwayland), each only discovered when cookbook tried to apply the patch. Running it across the repo found 29 latent malformed patches (validated against GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22'). They were harmless only because they sit in vendored recipes (baked, not re- applied) — but would fail on any version-bump re-derivation. --fix recounts the hunk headers (body untouched) and repaired all 29. Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test (test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats (empty placeholders, bare-@@ git hunks).
79 lines
1.9 KiB
Python
79 lines
1.9 KiB
Python
"""
|
|
DTLTO JSON Validator.
|
|
|
|
This script is used for DTLTO testing to check that the distributor has
|
|
been invoked correctly.
|
|
|
|
Usage:
|
|
python validate.py <json_file>
|
|
|
|
Arguments:
|
|
- <json_file> : JSON file describing the DTLTO jobs.
|
|
|
|
The script does the following:
|
|
1. Prints the supplied distributor arguments.
|
|
2. Loads the JSON file.
|
|
3. Pretty prints the JSON.
|
|
4. Validates the structure and required fields.
|
|
"""
|
|
|
|
import sys
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def take(jvalue, jpath):
|
|
parts = jpath.split(".")
|
|
for part in parts[:-1]:
|
|
jvalue = jvalue[part]
|
|
return jvalue.pop(parts[-1], KeyError)
|
|
|
|
|
|
def validate(jdoc):
|
|
# Check the format of the JSON
|
|
assert type(take(jdoc, "common.linker_output")) is str
|
|
|
|
args = take(jdoc, "common.args")
|
|
assert type(args) is list
|
|
assert len(args) > 0
|
|
assert all(type(i) is str for i in args)
|
|
|
|
inputs = take(jdoc, "common.inputs")
|
|
assert type(inputs) is list
|
|
assert all(type(i) is str for i in inputs)
|
|
|
|
assert len(take(jdoc, "common")) == 0
|
|
|
|
jobs = take(jdoc, "jobs")
|
|
assert type(jobs) is list
|
|
for j in jobs:
|
|
assert type(j) is dict
|
|
|
|
for attr, min_size in (("args", 0), ("inputs", 2), ("outputs", 1)):
|
|
array = take(j, attr)
|
|
assert len(array) >= min_size
|
|
assert type(array) is list
|
|
assert all(type(a) is str for a in array)
|
|
|
|
assert len(j) == 0
|
|
|
|
assert len(jdoc) == 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
json_arg = Path(sys.argv[-1])
|
|
distributor_args = sys.argv[1:-1]
|
|
|
|
# Print the supplied distributor arguments.
|
|
print(f"{distributor_args=}")
|
|
|
|
# Load the DTLTO information from the input JSON file.
|
|
with json_arg.open() as f:
|
|
jdoc = json.load(f)
|
|
|
|
# Write the input JSON to stdout.
|
|
print(json.dumps(jdoc, indent=4))
|
|
|
|
# Check the format of the JSON.
|
|
validate(jdoc)
|