Skip to content

Commit

Permalink
patching: emit warnings when files in dt folder overwrite pre-exist…
Browse files Browse the repository at this point in the history
…ing 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
  • Loading branch information
rpardini committed Sep 17, 2024
1 parent 5522814 commit 9786066
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/tools/common/dt_makefile_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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":
Expand All @@ -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:
Expand Down

0 comments on commit 9786066

Please sign in to comment.