Skip to content

Commit

Permalink
cli: rewrite-<uboot,kernel>-patches-needing-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ColorfulRhino committed Mar 13, 2024
1 parent ab7e8c5 commit 7d38b42
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/functions/cli/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
7 changes: 4 additions & 3 deletions lib/functions/compilation/kernel-patching.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions lib/functions/compilation/uboot-patching.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions lib/tools/patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"),
Expand Down Expand Up @@ -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] = []
Expand All @@ -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.")
Expand Down

0 comments on commit 7d38b42

Please sign in to comment.