mirror of
https://github.com/rosalinux/image-builder.git
synced 2025-02-23 18:32:51 +00:00
add patch.py
This commit is contained in:
parent
fae5d22966
commit
d509a1ba76
4 changed files with 62 additions and 4 deletions
6
build.py
6
build.py
|
@ -11,6 +11,8 @@ from utils.make_disk import create_partitions, mount_partitions
|
||||||
from utils.generate_spec import generate_spec_file
|
from utils.generate_spec import generate_spec_file
|
||||||
from utils.kernel import clone_kernel, make_kernel_tar
|
from utils.kernel import clone_kernel, make_kernel_tar
|
||||||
from utils.uboot import build_uboot
|
from utils.uboot import build_uboot
|
||||||
|
from utils.patch import apply_uboot_patches, apply_kernel_patches
|
||||||
|
|
||||||
|
|
||||||
BASE_DIR = os.getcwd()
|
BASE_DIR = os.getcwd()
|
||||||
TMP_DIR = os.path.join(BASE_DIR, "tmp")
|
TMP_DIR = os.path.join(BASE_DIR, "tmp")
|
||||||
|
@ -47,14 +49,14 @@ def main():
|
||||||
if not skip_kernel:
|
if not skip_kernel:
|
||||||
generate_spec_file(TMP_DIR, config, vendor, device)
|
generate_spec_file(TMP_DIR, config, vendor, device)
|
||||||
kernel_dir = os.path.join(TMP_DIR, vendor, device, "kernel")
|
kernel_dir = os.path.join(TMP_DIR, vendor, device, "kernel")
|
||||||
clone_kernel(TMP_DIR, config, vendor, device, kernel_dir)
|
clone_kernel(TMP_DIR, BASE_DIR, config, vendor, device, kernel_dir)
|
||||||
kernel_rpm_dir = os.path.join(TMP_DIR, vendor, device, "kernel-build")
|
kernel_rpm_dir = os.path.join(TMP_DIR, vendor, device, "kernel-build")
|
||||||
make_kernel_tar(kernel_dir, kernel_rpm_dir)
|
make_kernel_tar(kernel_dir, kernel_rpm_dir)
|
||||||
else:
|
else:
|
||||||
print("Skipping kernel build.")
|
print("Skipping kernel build.")
|
||||||
|
|
||||||
if not skip_uboot:
|
if not skip_uboot:
|
||||||
build_uboot(TMP_DIR, config, vendor, device)
|
build_uboot(TMP_DIR, BASE_DIR, config, vendor, device)
|
||||||
else:
|
else:
|
||||||
print("Skipping U-Boot build.")
|
print("Skipping U-Boot build.")
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,14 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from utils.common import clone_repo
|
from utils.common import clone_repo
|
||||||
|
from utils.patch import apply_kernel_patches
|
||||||
|
|
||||||
def clone_kernel(TMP_DIR, config, vendor, device, kernel_dir):
|
|
||||||
|
def clone_kernel(TMP_DIR, BASE_DIR, config, vendor, device, kernel_dir):
|
||||||
kernel_git = config.get("KERNEL").split("#")[0]
|
kernel_git = config.get("KERNEL").split("#")[0]
|
||||||
kernel_branch = config.get("KERNEL").split("#")[1]
|
kernel_branch = config.get("KERNEL").split("#")[1]
|
||||||
clone_repo(kernel_git, kernel_branch, kernel_dir, "kernel")
|
clone_repo(kernel_git, kernel_branch, kernel_dir, "kernel")
|
||||||
|
apply_kernel_patches(BASE_DIR, vendor, device, kernel_dir)
|
||||||
|
|
||||||
|
|
||||||
def make_kernel_tar(kernel_dir, kernel_rpm_dir):
|
def make_kernel_tar(kernel_dir, kernel_rpm_dir):
|
||||||
|
|
50
utils/patch.py
Normal file
50
utils/patch.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def apply_patches(patch_dir, target_dir):
|
||||||
|
"""
|
||||||
|
Applies patches from the specified patch directory to the target directory using `git apply`.
|
||||||
|
"""
|
||||||
|
if not os.path.exists(patch_dir):
|
||||||
|
print(f"No patches directory found at {patch_dir}. Skipping patch application.")
|
||||||
|
return
|
||||||
|
|
||||||
|
patches = sorted(os.listdir(patch_dir))
|
||||||
|
|
||||||
|
if not patches:
|
||||||
|
print(f"No patches found in {patch_dir}. Skipping patch application.")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"Applying patches from {patch_dir} to {target_dir}...")
|
||||||
|
|
||||||
|
for patch in patches:
|
||||||
|
patch_path = os.path.join(patch_dir, patch)
|
||||||
|
if os.path.isfile(patch_path):
|
||||||
|
print(f"Applying patch: {patch}")
|
||||||
|
try:
|
||||||
|
subprocess.run(["git", "apply", patch_path], cwd=target_dir, check=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Failed to apply patch {patch}: {e}")
|
||||||
|
else:
|
||||||
|
print(f"Skipping non-file item: {patch_path}")
|
||||||
|
|
||||||
|
|
||||||
|
def apply_kernel_patches(base_dir, vendor, device, kernel_dir):
|
||||||
|
"""
|
||||||
|
Apply kernel patches for the specified vendor and device.
|
||||||
|
"""
|
||||||
|
patch_dir = os.path.join(base_dir, "device", vendor, device, "patches", "kernel")
|
||||||
|
apply_patches(patch_dir, kernel_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_uboot_patches(base_dir, vendor, device, uboot_dir):
|
||||||
|
"""
|
||||||
|
Apply U-Boot patches for the specified vendor and device.
|
||||||
|
"""
|
||||||
|
patch_dir = os.path.join(base_dir, "device", vendor, device, "patches", "u-boot")
|
||||||
|
apply_patches(patch_dir, uboot_dir)
|
||||||
|
|
|
@ -5,8 +5,10 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from utils.common import clone_repo
|
from utils.common import clone_repo
|
||||||
|
from utils.patch import apply_uboot_patches
|
||||||
|
|
||||||
def build_uboot(TMP_DIR, config, vendor, device):
|
|
||||||
|
def build_uboot(TMP_DIR, BASE_DIR, config, vendor, device):
|
||||||
uboot_git = config.get("UBOOT")
|
uboot_git = config.get("UBOOT")
|
||||||
uboot_branch = config.get("UBOOT_VERSION")
|
uboot_branch = config.get("UBOOT_VERSION")
|
||||||
|
|
||||||
|
@ -16,6 +18,7 @@ def build_uboot(TMP_DIR, config, vendor, device):
|
||||||
|
|
||||||
uboot_dir = os.path.join(TMP_DIR, vendor, device, "u-boot")
|
uboot_dir = os.path.join(TMP_DIR, vendor, device, "u-boot")
|
||||||
clone_repo(uboot_git, uboot_branch, uboot_dir, "u-boot")
|
clone_repo(uboot_git, uboot_branch, uboot_dir, "u-boot")
|
||||||
|
apply_uboot_patches(BASE_DIR, vendor, device, uboot_dir)
|
||||||
|
|
||||||
|
|
||||||
#os.chdir(uboot_dir)
|
#os.chdir(uboot_dir)
|
||||||
|
|
Loading…
Add table
Reference in a new issue