mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
patching: show auto-patch'ed in summary table (in blue); remove spurious warnings
This commit is contained in:
@@ -35,6 +35,28 @@ class AutoPatcherParams:
|
||||
self.git_repo = git_repo
|
||||
|
||||
|
||||
class AutomaticPatchDescription:
|
||||
def __init__(self):
|
||||
self.name = "Not initted name"
|
||||
self.description = "Not initted desc"
|
||||
self.files = []
|
||||
|
||||
def rich_name_status(self):
|
||||
return f"[bold][blue]{self.name}"
|
||||
|
||||
def rich_diffstats(self):
|
||||
files_bare = []
|
||||
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))
|
||||
if len(self.files) > max_files_to_show:
|
||||
files_bare.append(f"and {len(self.files) - max_files_to_show} more")
|
||||
return ", ".join(files_bare)
|
||||
|
||||
def rich_subject(self):
|
||||
return f"Armbian Autopatcher: {self.description}"
|
||||
|
||||
|
||||
def auto_patch_dt_makefile(git_work_dir: str, dt_rel_dir: str, config_var: str) -> dict[str, str]:
|
||||
ret: dict[str, str] = {}
|
||||
dt_path = os.path.join(git_work_dir, dt_rel_dir)
|
||||
@@ -109,11 +131,13 @@ def auto_patch_dt_makefile(git_work_dir: str, dt_rel_dir: str, config_var: str)
|
||||
|
||||
# If we've found an equal number of dtbs and configvars, means one-rule-per-dtb (arm64) style
|
||||
if len(list_dts_basenames) == len(list_configvars):
|
||||
ret["extra_desc"] = "one-rule-per-dtb (arm64) style"
|
||||
for dts_file in dts_files:
|
||||
midamble_lines.append(f"dtb-$({config_var}) += {dts_file}.dtb")
|
||||
# Otherwise one-rule-for-all-dtbs (arm 32-bit) style, where the last one hasn't a trailing backslash
|
||||
# Important, this requires 6.5-rc1's move to subdir-per-vendor and can't handle the all-in-one Makefile before it
|
||||
else:
|
||||
ret["extra_desc"] = "one-rule-for-all-dtbs (arm 32-bit) style"
|
||||
midamble_lines.append(f"dtb-$({config_var}) += \\")
|
||||
dtb_single_rule_list = []
|
||||
for dts_file in dts_files:
|
||||
@@ -140,7 +164,9 @@ def auto_patch_dt_makefile(git_work_dir: str, dt_rel_dir: str, config_var: str)
|
||||
return ret
|
||||
|
||||
|
||||
def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str):
|
||||
def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[AutomaticPatchDescription]:
|
||||
ret_desc_list: list[AutomaticPatchDescription] = []
|
||||
|
||||
# group the pconfig.dts_directories by target dir
|
||||
dts_dirs_by_target = {}
|
||||
if type == "dt":
|
||||
@@ -168,7 +194,7 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str):
|
||||
root_dirs = autopatcher_params.root_dirs_by_root_type[type_in_order]
|
||||
for root_dir in root_dirs:
|
||||
full_path_source = os.path.join(root_dir.abs_dir, one_dts_dir)
|
||||
log.warning(f"Would copy {full_path_source} to {full_path_target_dir}...")
|
||||
log.debug(f"Will copy {full_path_source} to {full_path_target_dir}...")
|
||||
if not os.path.isdir(full_path_source):
|
||||
continue
|
||||
# get a list of regular files in the source directory
|
||||
@@ -185,12 +211,18 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str):
|
||||
# do the actual copy
|
||||
all_copied_files = []
|
||||
for one_file in all_files_to_copy_dict:
|
||||
log.warning(f"Copy '{one_file}' (from {all_files_to_copy_dict[one_file]}) to '{full_path_target_dir}'...")
|
||||
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)
|
||||
shutil.copyfile(all_files_to_copy_dict[one_file], full_path_target_file)
|
||||
all_copied_files.append(full_path_target_file)
|
||||
|
||||
# If more than 0 files were copied, commit them if we're doing commits
|
||||
desc = AutomaticPatchDescription()
|
||||
desc.name = f"Armbian Bare {type.upper()} auto-patch"
|
||||
desc.description = f"Armbian Bare {type.upper()} files for {target_dir}"
|
||||
desc.files = all_copied_files
|
||||
ret_desc_list.append(desc)
|
||||
|
||||
if autopatcher_params.apply_patches_to_git and len(all_copied_files) > 0:
|
||||
autopatcher_params.git_repo.git.add(all_copied_files)
|
||||
maintainer_actor: Actor = Actor(f"Armbian Bare {type.upper()} AutoPatcher", "patching@armbian.com")
|
||||
@@ -201,12 +233,22 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str):
|
||||
log.info(f"Committed Bare {type.upper()} changes to git: {commit.hexsha} for {target_dir}")
|
||||
log.info(f"Done with Bare {type.upper()} autopatch commit for {target_dir}.")
|
||||
|
||||
return ret_desc_list
|
||||
|
||||
def auto_patch_all_dt_makefiles(autopatcher_params: AutoPatcherParams):
|
||||
|
||||
def auto_patch_all_dt_makefiles(autopatcher_params: AutoPatcherParams) -> list[AutomaticPatchDescription]:
|
||||
ret_desc_list: list[AutomaticPatchDescription] = []
|
||||
for one_autopatch_config in autopatcher_params.pconfig.autopatch_makefile_dt_configs:
|
||||
log.warning(f"Autopatching DT Makefile in {one_autopatch_config.directory} with config '{one_autopatch_config.config_var}'...")
|
||||
autopatch_makefile_info = auto_patch_dt_makefile(
|
||||
autopatcher_params.git_work_dir, one_autopatch_config.directory, one_autopatch_config.config_var)
|
||||
|
||||
desc = AutomaticPatchDescription()
|
||||
desc.name = "Armbian DT Makefile auto-patch"
|
||||
desc.description = f"Armbian DT Makefile AutoPatch for {one_autopatch_config.directory}; {autopatch_makefile_info['extra_desc']}"
|
||||
desc.files = [autopatch_makefile_info["MAKEFILE_PATH"]]
|
||||
ret_desc_list.append(desc)
|
||||
|
||||
if autopatcher_params.apply_patches_to_git:
|
||||
autopatcher_params.git_repo.git.add(autopatch_makefile_info["MAKEFILE_PATH"])
|
||||
maintainer_actor: Actor = Actor("Armbian DT Makefile AutoPatcher", "patching@armbian.com")
|
||||
@@ -216,3 +258,4 @@ def auto_patch_all_dt_makefiles(autopatcher_params: AutoPatcherParams):
|
||||
)
|
||||
log.info(f"Committed changes to git: {commit.hexsha} for {one_autopatch_config.directory}")
|
||||
log.info(f"Done with Makefile autopatch commit for {one_autopatch_config.directory}.")
|
||||
return ret_desc_list
|
||||
|
||||
@@ -249,6 +249,8 @@ total_patches = len(VALID_PATCHES)
|
||||
any_failed_to_apply = False
|
||||
failed_to_apply_list = []
|
||||
|
||||
autopatcher_descriptions: list[dt_makefile_patcher.AutomaticPatchDescription] = []
|
||||
|
||||
if apply_patches:
|
||||
log.debug("Cleaning target git directory...")
|
||||
git_repo = Repo(GIT_WORK_DIR, odbt=GitCmdObjectDB)
|
||||
@@ -326,15 +328,15 @@ if apply_patches:
|
||||
|
||||
# Include the dts/dtsi marked dts-directories in the config
|
||||
if pconfig.has_dts_directories:
|
||||
dt_makefile_patcher.copy_bare_files(autopatcher_params, "dt")
|
||||
autopatcher_descriptions.extend(dt_makefile_patcher.copy_bare_files(autopatcher_params, "dt"))
|
||||
|
||||
# Include the overlay stuff
|
||||
if pconfig.has_dts_directories:
|
||||
dt_makefile_patcher.copy_bare_files(autopatcher_params, "overlay")
|
||||
autopatcher_descriptions.extend(dt_makefile_patcher.copy_bare_files(autopatcher_params, "overlay"))
|
||||
|
||||
# Autopatch the Makefile(s) according to the config
|
||||
if pconfig.has_autopatch_makefile_dt_configs:
|
||||
dt_makefile_patcher.auto_patch_all_dt_makefiles(autopatcher_params)
|
||||
autopatcher_descriptions.extend(dt_makefile_patcher.auto_patch_all_dt_makefiles(autopatcher_params))
|
||||
|
||||
if rewrite_patches_in_place:
|
||||
# Now; we need to write the patches to files.
|
||||
@@ -429,9 +431,9 @@ console = Console(color_system="standard", width=console_width, highlight=False)
|
||||
# Use Rich to print a summary of the patches
|
||||
if True:
|
||||
summary_table = Table(title=f"Summary of {PATCH_TYPE} patches", show_header=True, show_lines=True, box=rich.box.ROUNDED)
|
||||
summary_table.add_column("Patch / Status", overflow="fold", min_width=25, max_width=35)
|
||||
summary_table.add_column("Patch / Status", overflow="fold", min_width=25)
|
||||
summary_table.add_column("Diffstat / files", max_width=35)
|
||||
summary_table.add_column("Author / Subject", overflow="ellipsis")
|
||||
summary_table.add_column("Author / Subject", overflow="ellipsis", min_width=25, max_width=40)
|
||||
for one_patch in VALID_PATCHES:
|
||||
summary_table.add_row(
|
||||
# (one_patch.markdown_name(skip_markdown=True)), # + " " + one_patch.markdown_problems()
|
||||
@@ -439,6 +441,13 @@ if True:
|
||||
(one_patch.text_diffstats() + " " + one_patch.text_files()),
|
||||
(one_patch.text_author() + ": " + one_patch.text_subject())
|
||||
)
|
||||
# Extra items for auto-patched stuff
|
||||
for autopatcher_description in autopatcher_descriptions:
|
||||
summary_table.add_row(
|
||||
autopatcher_description.rich_name_status(),
|
||||
autopatcher_description.rich_diffstats(),
|
||||
autopatcher_description.rich_subject()
|
||||
)
|
||||
console.print(summary_table)
|
||||
|
||||
# Use Rich to print a summary of the failed patches and their rejects
|
||||
|
||||
Reference in New Issue
Block a user