42 lines
2.4 KiB
Python
42 lines
2.4 KiB
Python
"""Copy stable native-saved source and check its complete Project independently."""
|
|
from pathlib import Path
|
|
import datetime, hashlib, json, re, shutil, subprocess, sys
|
|
root = Path('C:/ar-multiselect-9e8r6t')
|
|
native = root / '.local/multiselect-native'
|
|
label, mode, *rest = sys.argv[1:]
|
|
assert not rest and re.fullmatch('[a-z0-9-]+', label)
|
|
working = native / 'working-2'
|
|
out = native / 'run-2/snapshots' / label
|
|
out.mkdir(parents=True, exist_ok=False)
|
|
gate_path = root / '.local/group-movement-gates/native-build-2/result.json'
|
|
gate = json.loads(gate_path.read_bytes())
|
|
assert gate['exitCode'] == 0 and gate['inputsUnchanged']
|
|
artifact, = [a for a in gate['artifacts'] if a['cargo']['target']['name'] == 'multiselect_native']
|
|
binary = Path(artifact['cargo']['executable'])
|
|
baseline = native / 'fixture-2/baseline.json'
|
|
def pin(path):
|
|
b = path.read_bytes()
|
|
return {'bytes': len(b), 'sha256': hashlib.sha256(b).hexdigest()}
|
|
def inventory():
|
|
return {p.relative_to(working).as_posix():pin(p) for p in sorted(working.rglob('*.arcadia')) if p.is_file()}
|
|
def now(): return datetime.datetime.now(datetime.timezone.utc).isoformat()
|
|
before = inventory()
|
|
assert 'project.arcadia' in before and pin(binary) == artifact['readback']
|
|
for name in before:
|
|
target = out/'source'/name
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(working/name, target)
|
|
assert before == inventory() == {name:pin(out/'source'/name) for name in before}
|
|
command = [str(binary), 'check', mode, str(baseline), str(out/'source/project.arcadia')]
|
|
start = {'start':now(), 'command':command, 'buildReceipt':pin(gate_path), 'binary':pin(binary), 'helper':pin(Path(__file__)), 'source':before, 'baseline':pin(baseline)}
|
|
(out/'started.json').write_text(json.dumps(start,indent=2),encoding='utf-8')
|
|
r = subprocess.run(command,cwd=root,capture_output=True)
|
|
(out/'stdout.log').write_bytes(r.stdout)
|
|
(out/'stderr.log').write_bytes(r.stderr)
|
|
result = {**start, 'finish':now(), 'exitCode':r.returncode, 'binaryUnchanged':pin(binary)==artifact['readback'], 'workingSourceUnchanged':before==inventory(), 'baselineUnchanged':pin(baseline)==start['baseline'], 'stdout':pin(out/'stdout.log'), 'stderr':pin(out/'stderr.log')}
|
|
(out/'result.json').write_text(json.dumps(result,indent=2),encoding='utf-8')
|
|
print(r.stdout.decode(errors='replace'))
|
|
print(r.stderr.decode(errors='replace'))
|
|
assert result['binaryUnchanged'] and result['workingSourceUnchanged'] and result['baselineUnchanged']
|
|
sys.exit(r.returncode)
|