diff --git a/lib/tools/common/dt_makefile_patcher.py b/lib/tools/common/dt_makefile_patcher.py index b8274d1ef..72cd4f6be 100644 --- a/lib/tools/common/dt_makefile_patcher.py +++ b/lib/tools/common/dt_makefile_patcher.py @@ -33,6 +33,8 @@ class AutoPatcherParams: self.root_dirs_by_root_type = root_dirs_by_root_type self.apply_patches_to_git = apply_patches_to_git self.git_repo = git_repo + self.all_dt_files_copied: list[str] = [] + self.all_overlay_files_copied: list[str] = [] class AutomaticPatchDescription: @@ -57,7 +59,7 @@ class AutomaticPatchDescription: 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]: +def auto_patch_dt_makefile(git_work_dir: str, dt_rel_dir: str, config_var: str, dt_files_to_add: list[str], incremental: bool) -> dict[str, str]: ret: dict[str, str] = {} dt_path = os.path.join(git_work_dir, dt_rel_dir) # Bomb if it does not exist or is not a directory @@ -114,18 +116,30 @@ def auto_patch_dt_makefile(git_work_dir: str, dt_rel_dir: str, config_var: str) # Now compute the preambles and the postamble preamble_lines = makefile_lines[:line_first_match - 1] postamble_lines = makefile_lines[line_last_match:] - # Find all .dts files in DT_PATH (not subdirectories), but add to the list without .dts suffix + dts_files = [] - listdir: list[str] = os.listdir(dt_path) - for file in listdir: - if file.endswith(".dts"): - dts_files.append(file[:-4]) - # sort the list. alpha-sort: `meson-sm1-a95xf3-air-gbit` should come sooner than `meson-sm1-a95xf3-air`? why? - dts_files.sort() - log.info(f"Found {len(dts_files)} .dts files in {dt_path}") - # Show them all - for dts_file in dts_files: - log.debug(f"Found {dts_file}") + if incremental: + # For incremental, we'll just use the parsed-from-Makefile list of .dts files... + for previously_in_makefile_dt in list_dts_basenames: + log.debug(f"Adding {previously_in_makefile_dt} to the list of .dts files") + dts_files.append(previously_in_makefile_dt) + # ...and add the ones we copied. We're passed the list as parameter + for one_dt_file in dt_files_to_add: + log.debug(f"Adding newly-added DT {one_dt_file} to the list of .dts files") + dts_files.append(one_dt_file[:-4]) # remove the .dts suffix + else: + # Find all .dts files in DT_PATH (not subdirectories), but add to the list without .dts suffix + listdir: list[str] = os.listdir(dt_path) + for file in listdir: + if file.endswith(".dts"): + dts_files.append(file[:-4]) + # sort the list. alpha-sort: `meson-sm1-a95xf3-air-gbit` should come sooner than `meson-sm1-a95xf3-air`? why? + dts_files.sort() + log.info(f"Found {len(dts_files)} .dts files in {dt_path}") + # Show them all + for dts_file in dts_files: + log.debug(f"Found {dts_file}") + # Create the mid-amble, which is the list of .dtb files to be built midamble_lines = [] @@ -148,11 +162,15 @@ def auto_patch_dt_makefile(git_work_dir: str, dt_rel_dir: str, config_var: str) overlay_lines = [] DT_OVERLAY_PATH = os.path.join(dt_path, "overlay") DT_OVERLAY_MAKEFILE_PATH = os.path.join(DT_OVERLAY_PATH, "Makefile") + overlay_lines.append("") if os.path.isfile(DT_OVERLAY_MAKEFILE_PATH): - ret["DT_OVERLAY_MAKEFILE_PATH"] = DT_OVERLAY_MAKEFILE_PATH - ret["DT_OVERLAY_PATH"] = DT_OVERLAY_PATH - overlay_lines.append("") - overlay_lines.append("subdir-y := $(dts-dirs) overlay") + if incremental: + overlay_lines.append("# Armbian: Incremental: assuming overlay targets are already in the Makefile") + else: + ret["DT_OVERLAY_MAKEFILE_PATH"] = DT_OVERLAY_MAKEFILE_PATH + ret["DT_OVERLAY_PATH"] = DT_OVERLAY_PATH + overlay_lines.append("# Added by Armbian autopatcher for DT overlay") + overlay_lines.append("subdir-y := $(dts-dirs) overlay") # Now join the preambles, midamble, postamble and overlay stuff into a single list new_makefile_lines = preamble_lines + midamble_lines + postamble_lines + overlay_lines @@ -161,6 +179,9 @@ def auto_patch_dt_makefile(git_work_dir: str, dt_rel_dir: str, config_var: str) f.write("\n".join(new_makefile_lines)) log.info(f"Wrote {len(new_makefile_lines)} lines to {makefile_path}") + if incremental: + ret["extra_desc"] += " (incremental)" + return ret @@ -215,6 +236,11 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[Au 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 type == "dt": + if one_file.endswith(".dts"): + autopatcher_params.all_dt_files_copied.append(one_file) + elif type == "overlay": + autopatcher_params.all_overlay_files_copied.append(one_file) # If more than 0 files were copied, commit them if we're doing commits desc = AutomaticPatchDescription() @@ -241,7 +267,9 @@ def auto_patch_all_dt_makefiles(autopatcher_params: AutoPatcherParams) -> list[A 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) + autopatcher_params.git_work_dir, one_autopatch_config.directory, one_autopatch_config.config_var, + autopatcher_params.all_dt_files_copied, one_autopatch_config.incremental + ) desc = AutomaticPatchDescription() desc.name = "Armbian DT Makefile auto-patch" diff --git a/lib/tools/common/patching_config.py b/lib/tools/common/patching_config.py index 359801a56..5f24d1407 100644 --- a/lib/tools/common/patching_config.py +++ b/lib/tools/common/patching_config.py @@ -16,9 +16,10 @@ class PatchingAutoPatchMakefileDTConfig: def __init__(self, data: dict): self.config_var: str = data.get("config-var", None) self.directory: str = data.get("directory", None) + self.incremental: bool = not not data.get("incremental", False) def __str__(self): - return f"PatchingAutoPatchMakefileDTConfig(config-var={self.config_var}, directory={self.directory})" + return f"PatchingAutoPatchMakefileDTConfig(config-var={self.config_var}, directory={self.directory}, incremental={self.incremental})" class PatchingDTSDirectoryConfig: