#!/usr/bin/env python3
# Verify generated code matches current ARXML - fail build if stale
import hashlib, json, os, subprocess, sys
ARXML_FILES = ["Com_Cfg.arxml", "PduR_Cfg.arxml", "NvM_Cfg.arxml", "Dcm_Cfg.arxml"]
CHECKSUM_FILE = "GENDATA/.arxml_checksums.json"
def compute_checksums(files):
result = {}
for f in files:
with open(f"Config/{f}", "rb") as fp:
result[f] = hashlib.sha256(fp.read()).hexdigest()
return result
# Compare stored checksums with current ARXML content
current = compute_checksums(ARXML_FILES)
stored = json.load(open(CHECKSUM_FILE)) if os.path.exists(CHECKSUM_FILE) else {}
stale = [f for f in ARXML_FILES if current.get(f) != stored.get(f)]
if stale:
print(f"GENDATA is stale for: {stale}")
print("Re-running code generation...")
subprocess.run(["davinci_cli.exe", "-project", "ECU.dpj", "-gen",
"-output", "GENDATA/"], check=True)
json.dump(current, open(CHECKSUM_FILE, "w"), indent=2)
# Fail build — regenerated code must be reviewed before merge
sys.exit(1)
print("GENDATA is up to date.")