diff --git a/lib/functions/cli/commands.sh b/lib/functions/cli/commands.sh index 86363aab28c8..6cc89a4b7035 100644 --- a/lib/functions/cli/commands.sh +++ b/lib/functions/cli/commands.sh @@ -42,10 +42,12 @@ function armbian_register_commands() { # Patch to git & patch rewrite, for kernel ["kernel-patches-to-git"]="patch_kernel" # implemented in cli_patch_kernel_pre_run and cli_patch_kernel_run ["rewrite-kernel-patches"]="patch_kernel" # implemented in cli_patch_kernel_pre_run and cli_patch_kernel_run + ["rewrite-kernel-patches-needing-rebase"]="patch_kernel" # implemented in cli_patch_kernel_pre_run and cli_patch_kernel_run # Patch to git & patch rewrite, for u-boot ["uboot-patches-to-git"]="patch_uboot" # implemented in cli_patch_uboot_pre_run and cli_patch_uboot_run ["rewrite-uboot-patches"]="patch_uboot" # implemented in cli_patch_uboot_pre_run and cli_patch_uboot_run + ["rewrite-uboot-patches-needing-rebase"]="patch_uboot" # implemented in cli_patch_uboot_pre_run and cli_patch_uboot_run ["build"]="standard_build" # implemented in cli_standard_build_pre_run and cli_standard_build_run ["distccd"]="distccd" # implemented in cli_distccd_pre_run and cli_distccd_run @@ -114,8 +116,10 @@ function armbian_register_commands() { ["inventory-boards"]="TARGETS_FILE='something_that_does_not_exist_so_defaults_are_used'" # patching - ["rewrite-kernel-patches"]="REWRITE_PATCHES=yes" # rewrite the patches after round-tripping to git: "rebase patches" - ["rewrite-uboot-patches"]="REWRITE_PATCHES=yes" # rewrite the patches after round-tripping to git: "rebase patches" + ["rewrite-kernel-patches"]="REWRITE_PATCHES='yes'" # rewrite the patches after round-tripping to git: "rebase patches" + ["rewrite-uboot-patches"]="REWRITE_PATCHES='yes'" # rewrite the patches after round-tripping to git: "rebase patches" + ["rewrite-kernel-patches-needing-rebase"]="REWRITE_PATCHES='yes' REWRITE_PATCHES_NEEDING_REBASE='yes'" + ["rewrite-uboot-patches-needing-rebase"]="REWRITE_PATCHES='yes' REWRITE_PATCHES_NEEDING_REBASE='yes'" # artifact shortcuts ["rootfs"]="WHAT='rootfs' ${common_cli_artifact_vars}" diff --git a/lib/functions/compilation/kernel-patching.sh b/lib/functions/compilation/kernel-patching.sh index 9d1e1086c01b..ee426680ab00 100644 --- a/lib/functions/compilation/kernel-patching.sh +++ b/lib/functions/compilation/kernel-patching.sh @@ -38,9 +38,10 @@ function kernel_main_patching_python() { "PATH=${PATH}" "HOME=${HOME}" # What to do? - "APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash. - "PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches. - "REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting. + "APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash. + "PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches. + "REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting. + "REWRITE_PATCHES_NEEDING_REBASE=${REWRITE_PATCHES_NEEDING_REBASE:-no}" # Only rewrite those patch files in need of a rebase. # Git dir, revision, and target branch "GIT_WORK_DIR=${kernel_work_dir}" # "Where to apply patches?" "BASE_GIT_REVISION=${kernel_git_revision}" # The revision we're building/patching. Python will reset and clean to this. diff --git a/lib/functions/compilation/uboot-patching.sh b/lib/functions/compilation/uboot-patching.sh index d039510c2156..2e50be3db5cd 100644 --- a/lib/functions/compilation/uboot-patching.sh +++ b/lib/functions/compilation/uboot-patching.sh @@ -33,9 +33,10 @@ function uboot_main_patching_python() { "PATH=${PATH}" "HOME=${HOME}" # What to do? - "APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash. - "PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches. - "REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting. + "APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash. + "PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches. + "REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting. + "REWRITE_PATCHES_NEEDING_REBASE=${REWRITE_PATCHES_NEEDING_REBASE:-no}" # Only rewrite those patch files in need of a rebase. # Git dir, revision, and target branch "GIT_WORK_DIR=${uboot_work_dir}" # "Where to apply patches?" "BASE_GIT_REVISION=${uboot_git_revision}" # The revision we're building/patching. Python will reset and clean to this. diff --git a/lib/tools/patching.py b/lib/tools/patching.py index 4f11a4409319..d14c53f6987c 100755 --- a/lib/tools/patching.py +++ b/lib/tools/patching.py @@ -44,6 +44,7 @@ APPLY_PATCHES = armbian_utils.get_from_env("APPLY_PATCHES") PATCHES_TO_GIT = armbian_utils.get_from_env("PATCHES_TO_GIT") REWRITE_PATCHES = armbian_utils.get_from_env("REWRITE_PATCHES") +REWRITE_PATCHES_NEEDING_REBASE = armbian_utils.get_from_env("REWRITE_PATCHES_NEEDING_REBASE") SPLIT_PATCHES = armbian_utils.get_from_env("SPLIT_PATCHES") ALLOW_RECREATE_EXISTING_FILES = armbian_utils.get_from_env("ALLOW_RECREATE_EXISTING_FILES") GIT_ARCHEOLOGY = armbian_utils.get_from_env("GIT_ARCHEOLOGY") @@ -53,6 +54,7 @@ git_archeology = GIT_ARCHEOLOGY == "yes" fast_archeology = FAST_ARCHEOLOGY == "yes" rewrite_patches_in_place = REWRITE_PATCHES == "yes" +rewrite_only_patches_needing_rebase = REWRITE_PATCHES_NEEDING_REBASE == "yes" split_patches = SPLIT_PATCHES == "yes" apply_options = { "allow_recreate_existing_files": (ALLOW_RECREATE_EXISTING_FILES == "yes"), @@ -357,6 +359,12 @@ if one_patch.rewritten_patch is None: log.warning(f"Skipping patch {one_patch} from rewrite because it was not rewritten.") continue + + # Skip the patch if it doesn't need rebasing + if rewrite_only_patches_needing_rebase: + if "needs_rebase" not in one_patch.problems: + log.info(f"Skipping patch {one_patch} from rewrite because it doesn't need a rebase.") + continue if one_patch.parent not in patch_files_by_parent: patch_files_by_parent[one_patch.parent] = [] @@ -365,8 +373,8 @@ for parent in patch_files_by_parent: patches = patch_files_by_parent[parent] parent.rewrite_patch_file(patches) - UNAPPLIED_PATCHES = [one_patch for one_patch in VALID_PATCHES if (not one_patch.applied_ok) or (one_patch.rewritten_patch is None)] - for failed_patch in UNAPPLIED_PATCHES: + FAILED_PATCHES = [one_patch for one_patch in VALID_PATCHES if (not one_patch.applied_ok) or (one_patch.rewritten_patch is None)] + for failed_patch in FAILED_PATCHES: log.info( f"Consider removing {failed_patch.parent.full_file_path()}(:{failed_patch.counter}); " f"it was not applied successfully.")