32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Обновляет stamp только при смене команды или содержимого зависимостей."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
mode = sys.argv[1]
|
|
if mode not in ('check', 'save'):
|
|
raise SystemExit('Ожидается check или save')
|
|
stamp = Path(sys.argv[2])
|
|
args = sys.argv[3:]
|
|
files = set()
|
|
for arg in args:
|
|
path = Path(arg.split('=', 1)[-1] if '=' in arg else arg)
|
|
if path.is_file(): files.add(path.resolve())
|
|
# Manifest предыдущей debug-сборки содержит все препроцессорные зависимости.
|
|
for name in list(files):
|
|
if name.name == 'manifest.json':
|
|
files.update(Path(p) for p in json.loads(name.read_text()).get('sources', {}))
|
|
files.discard(name)
|
|
content = json.dumps({'args': args, 'files': {str(p): hashlib.sha256(p.read_bytes()).hexdigest()
|
|
if p.is_file() else None for p in sorted(files)}}, sort_keys=True)
|
|
changed = not stamp.is_file() or stamp.read_text() != content
|
|
if mode == 'check':
|
|
print('changed' if changed else 'same')
|
|
elif changed:
|
|
stamp.parent.mkdir(parents=True, exist_ok=True)
|
|
temporary = stamp.with_suffix('.tmp')
|
|
temporary.write_text(content)
|
|
temporary.replace(stamp)
|