elasticai.creator.hw_function_id#

Module Contents#

Classes#

HwFunctionIdUpdater

Hash all files in build_dir except for target_file and uses replace_id_fn to write the result to target_file.

API#

class elasticai.creator.hw_function_id.HwFunctionIdUpdater(build_dir: pathlib.Path, target_file: str | pathlib.Path, replace_id_fn: collections.abc.Callable[[collections.abc.Iterable[str], bytes], collections.abc.Iterator[str]], file_filter: collections.abc.Callable[[pathlib.Path], bool] = lambda f: ...)[source]#

Hash all files in build_dir except for target_file and uses replace_id_fn to write the result to target_file.

The id will stay the same, if none of the files, except for the target file changed.

You can use the optional file_filter to exclude additional files from the id computation. Example:

generate_my_source_files(build_dir)
def replace_id(code: Iterable[str], id: bytes) -> Iterator[str]:
    for line in code:
        if line == "my_id_placeholder":
            yield f"my_id = {id.hex()};"
        else:
            yield line

def filter_non_vhd(file):
    return str(file).endswith(".vhd")

id_updater = HwFunctionIdUpdate(build_dir, "id_package.vhd", replace_id, filter_non_vhd)
id_update.compute_id()
id_updater.write_id()
print(id_updater.id)

Initialization

compute_id() None[source]#
write_id() None[source]#
property id: bytes#