import hashlib, json, sys
from pathlib import Path
base = Path(sys.argv[1]).resolve()
files = sorted(p for p in base.rglob('*') if p.is_file())
manifest = {'version': 1, 'files': [
    {'path': p.relative_to(base).as_posix(),
     'sha256': hashlib.sha256(p.read_bytes()).hexdigest()}
    for p in files]}
# Write outside the source directory to avoid including a prior manifest.
sys.stdout.write(json.dumps(manifest, sort_keys=True, separators=(',', ':')) + '\n')
