Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/cmake/modules/LLVMLibCHeaderRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function(add_gen_header target_name)
COMMAND ${Python3_EXECUTABLE} "${LIBC_SOURCE_DIR}/utils/hdrgen/main.py"
--output ${out_file}
--depfile ${dep_file}
--write-if-changed
${entry_points}
${yaml_file}
DEPENDS ${yaml_file} ${fq_data_files}
Expand Down
16 changes: 13 additions & 3 deletions libc/utils/hdrgen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def main():
help="Path to write a depfile",
type=Path,
)
parser.add_argument(
"--write-if-changed",
help="Write the output file only if its contents have changed",
action="store_true",
default=False,
)
parser.add_argument(
"-e",
"--entry-point",
Expand Down Expand Up @@ -72,9 +78,13 @@ def write_depfile():

write_depfile()

args.output.parent.mkdir(parents=True, exist_ok=True)
with open(args.output, "w") as out:
out.write(contents)
if (
not args.write_if_changed
or not args.output.exists()
or args.output.read_text() != contents
):
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(contents)


if __name__ == "__main__":
Expand Down
Loading