Skip to content

Commit 64caccc

Browse files
committed
refactor: apply patch in the order of patch number
A dedicated python script is also introduced to handle the patch applying logic.
1 parent 844db91 commit 64caccc

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

apply-patches.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import os, subprocess
5+
6+
# accept patch dir and branch name as arguments
7+
def parse_args():
8+
parser = argparse.ArgumentParser(description="Apply patches to a git repository.")
9+
parser.add_argument("patch_dir", type=str, help="Directory containing the patch files.")
10+
parser.add_argument("branch_name", type=str, help="Name of the branch to apply patches to.")
11+
return parser.parse_args()
12+
13+
def main():
14+
args = parse_args()
15+
patch_dir = args.patch_dir
16+
branch_name = args.branch_name
17+
18+
print(f"Using patch directory: {patch_dir}")
19+
print(f"Using branch name: {branch_name}")
20+
21+
common_patch_dir = patch_dir
22+
branch_specific_patch_dir = f"{patch_dir}/{branch_name}"
23+
24+
# collect all patch files from the two directories
25+
# into a dict [patch_file_name: patch_file_path]
26+
patch_files = {}
27+
for dir_path in [common_patch_dir, branch_specific_patch_dir]:
28+
if os.path.exists(dir_path):
29+
for file_name in os.listdir(dir_path):
30+
if file_name.endswith(".patch"):
31+
patch_files[file_name] = os.path.join(dir_path, file_name)
32+
33+
# sort patch files by name
34+
sorted_patch_files = sorted(patch_files.items())
35+
for file_name, file_path in sorted_patch_files:
36+
print(f"Applying patch: {file_name}")
37+
# apply the patch using git
38+
result = subprocess.run(["git", "apply", file_path], check=False)
39+
if result.returncode != 0:
40+
print(f"Failed to apply patch, halting build!")
41+
exit(1)
42+
43+
44+
45+
if __name__ == "__main__":
46+
main()

setup.sh

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,7 @@ fi
7979

8080
cd linux
8181
PATCH_DIR=${PATCH_DIR:-"../patches"}
82-
83-
# Determine the patch directory
84-
if [[ $BRANCH == "LTS" ]]; then
85-
SPESIFIC_PATCH_DIR="$PATCH_DIR/LTS"
86-
else
87-
SPESIFIC_PATCH_DIR="$PATCH_DIR/MAIN"
88-
fi
89-
90-
function loop_apply_patch {
91-
for patch_file in "$1/"*.patch; do
92-
git apply "$patch_file"
93-
94-
if [ $? != 0 ]; then
95-
echo -e "Failed to apply $patch_file"
96-
echo -e "Halting build!"
97-
exit 1
98-
fi
99-
done
100-
}
101-
102-
# Apply common patches
103-
loop_apply_patch $PATCH_DIR
104-
# Apply LTS/MAIN specific patches
105-
loop_apply_patch $SPESIFIC_PATCH_DIR
106-
82+
../apply_patches.py "$PATCH_DIR" "$BRANCH"
10783
cp ../wsl2_defconfig.$BRANCH ./arch/x86/configs/wsl2_defconfig
10884

10985
make LLVM=1 LLVM_IAS=1 wsl2_defconfig

0 commit comments

Comments
 (0)