From a1a41e4cde61666199b3983fc02484c6c6811585 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 15 Mar 2024 06:41:56 -0500 Subject: [PATCH] Fix duplicate addition of LLVM header --- LLVMImporter.py | 7 ++++++- helperFunctions.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/LLVMImporter.py b/LLVMImporter.py index 90e1b925..b5cbcba0 100755 --- a/LLVMImporter.py +++ b/LLVMImporter.py @@ -33,7 +33,7 @@ get_generation_timestamp, src_matches_old_src, include_file, - gen_c_doxygen, + gen_c_doxygen, get_delimiter_line, ) import PluginInfo import HexagonArchInfo @@ -504,6 +504,11 @@ def add_license_info_header(self) -> None: with open(p, "r+") as f: content = f.read() f.seek(0, 0) + + # If header message is there, skip it. + match = re.search(get_delimiter_line(), content) + if match: + content = content[match.start():] f.write(get_license() + "\n" + get_generation_timestamp(self.config) + "\n" + content) if p not in self.edited_files: log("Write {}".format(p), LogLevel.INFO) diff --git a/helperFunctions.py b/helperFunctions.py index 1fd883d3..1e3924c6 100644 --- a/helperFunctions.py +++ b/helperFunctions.py @@ -242,9 +242,13 @@ def set_pos_after_license(file: TextIO) -> None: return +def get_delimiter_line() -> str: + return "{}\n".format(PluginInfo.GENERATION_WARNING_DELIMITER) + + def get_generation_warning_c_code() -> str: url = PluginInfo.REPO_URL - msg = "{}\n".format(PluginInfo.GENERATION_WARNING_DELIMITER) + msg = get_delimiter_line() msg += "// The following code is generated.\n" msg += "// Do not edit. Repository of code generator:\n" msg += "// {}\n".format(url)