From 9786066cb3815ce3ad827503c5154d899c1f2f78 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Tue, 17 Sep 2024 12:51:25 +0200 Subject: [PATCH] patching: emit warnings when files in `dt` folder overwrite pre-existing files (DTs that landed upstream) - it's more and more common that the (bare) DT files in our `dt` folders have landed upstream - this adds warnings and marks the patching table red when some bare-dt file overwrites what's already in git - without this it's very easy to forget them there during bumps --- lib/tools/common/dt_makefile_patcher.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/tools/common/dt_makefile_patcher.py b/lib/tools/common/dt_makefile_patcher.py index 8ae11bddd7e2..07a68adc2b68 100644 --- a/lib/tools/common/dt_makefile_patcher.py +++ b/lib/tools/common/dt_makefile_patcher.py @@ -42,12 +42,18 @@ def __init__(self): self.name = "Not initted name" self.description = "Not initted desc" self.files = [] + self.overwrites = [] def rich_name_status(self): + if len(self.overwrites) > 0: + return f"[bold][red]{self.name}" return f"[bold][blue]{self.name}" def rich_diffstats(self): files_bare = [] + # Always list all overwrites. + for one_file in self.overwrites: + files_bare.append(f"[OVERWRITTEN]{os.path.basename(one_file)}") max_files_to_show = 15 # show max 15 for one_file in self.files[:max_files_to_show]: files_bare.append(os.path.basename(one_file)) @@ -231,9 +237,14 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[Au all_files_to_copy_dict[base_filename] = one_file # do the actual copy all_copied_files = [] + overwritten_files = [] for one_file in all_files_to_copy_dict: log.debug(f"Copy '{one_file}' (from {all_files_to_copy_dict[one_file]}) to '{full_path_target_dir}'...") full_path_target_file = os.path.join(full_path_target_dir, one_file) + # If the target already exists, emit a warning; DTs land upstream all the time and we might forget to remove them from our 'dt' directory + if os.path.exists(full_path_target_file): + overwritten_files.append(full_path_target_file) + log.warning(f"Target file '{one_file}' already exists; will overwrite it; consider if it should be removed.") shutil.copyfile(all_files_to_copy_dict[one_file], full_path_target_file) all_copied_files.append(full_path_target_file) if type == "dt": @@ -246,7 +257,12 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[Au desc = AutomaticPatchDescription() desc.name = f"Armbian Bare {type.upper()} auto-patch" desc.description = f"Armbian Bare {type.upper()} files for {target_dir}" + # if overwritten files, add to description and name + if len(overwritten_files) > 0: + desc.description += f" (overwriting {len(overwritten_files)} files)" + desc.name += f" (overwriting {len(overwritten_files)} files)" desc.files = all_copied_files + desc.overwrites = overwritten_files ret_desc_list.append(desc) if autopatcher_params.apply_patches_to_git and len(all_copied_files) > 0: