Files
carbon-lang/scripts/check_sha_filenames.py
T
Chandler Carruth b344f3af12 Switch a few stragglers to uv and update python to 3.12 (#7296)
Not sure how these got missed when moving other things to `uv`, but this
should clean them up.

The bump to Python 3.12 is so that we can use `@override` with the
simple import from `typing`. This is needed by the newest versions of
`ty` to do type checking. Added the relevant `@override` annotations.

Assisted-by: Antigravity with Gemini
2026-06-03 05:34:44 +00:00

49 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# ///
"""Requires files be named for their SHA1.
We name fuzzer corpus files for their SHA1. The choice of SHA1 is for
consistency with git.
This maintains the current extension for .textproto, but at some point we might
want to specify the extension by path.
"""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import hashlib
import sys
from pathlib import Path
def main() -> None:
has_errors = False
for arg in sys.argv[1:]:
path = Path(arg)
with path.open("rb") as f:
content = f.read()
if len(content) == 0:
want = "empty"
else:
want = hashlib.sha1(content).hexdigest()
want_path = path.parent.joinpath(want).with_suffix(path.suffix)
if path != want_path:
print(f"Renaming {path} to {want_path}", file=sys.stderr)
path.rename(want_path)
has_errors = True
if has_errors:
exit(1)
if __name__ == "__main__":
main()