diff --git a/src/blight/actions/embed_commands.py b/src/blight/actions/embed_commands.py index 5bda6df..5bdbe02 100644 --- a/src/blight/actions/embed_commands.py +++ b/src/blight/actions/embed_commands.py @@ -20,11 +20,6 @@ from blight.util import flock_append -def SHA256(value): - """Get sha256 hash from the value""" - return hashlib.sha256(value.encode("utf-8")).hexdigest() - - def cc_as_string(tool_record: Dict): return json.dumps(tool_record).replace('"', '\\"').replace("\\\\", "\\") @@ -79,10 +74,10 @@ def align_string(string: str) -> str: class EmbedCommands(CompilerAction): - def __init__(self, config): + def __init__(self, config: dict[str, str]) -> None: super().__init__(config) - def _get_header_file(self, cmd_hash: str): + def _get_header_file(self, cmd_hash: str) -> str: output = Path(self._config["output"]) header_file = "{}/{}_{}_{}.h".format( output, cmd_hash, os.getpid(), random.randint(0, 9999999) @@ -91,7 +86,7 @@ def _get_header_file(self, cmd_hash: str): os.remove(header_file) return header_file - def before_run(self, tool: Tool) -> None: + def before_run(self, tool: CompilerTool) -> None: if tool.lang not in (Lang.C, Lang.Cxx): return @@ -99,7 +94,7 @@ def before_run(self, tool: Tool) -> None: return cc_string = cc_as_string(cc_as_dict(tool)).strip() - cmd_hash = SHA256(cc_string) + cmd_hash = hashlib.sha256(cc_string.encode()).hexdigest() header_file = self._get_header_file(cmd_hash) with flock_append(header_file) as io: variable = """