Skip to content

Commit 30e89f8

Browse files
committed
buildroot: Add support for applying local patches
LoongArch support is only available as an in-review patch on the mailing list. Add scaffolding to make it easy to apply patches on top of the Buildroot tarball. To make it easy to add and remove patches while ensuring they get applied properly, keep the downloaded tarball instead of removing it after extraction, so that the source can be cleanly recreated each run. Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent aff63bf commit 30e89f8

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

buildroot/rebuild.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,17 @@ def build_image(architecture, edit_config):
7272

7373

7474
def download_and_extract_buildroot():
75+
if SRC_FOLDER.exists():
76+
shutil.rmtree(SRC_FOLDER)
7577
SRC_FOLDER.mkdir(parents=True)
7678

7779
tarball = Path(ROOT_FOLDER, f"buildroot-{BUILDROOT_VERSION}.tar.gz")
78-
tarball.unlink(missing_ok=True)
79-
80-
curl_cmd = [
81-
'curl', '-LSs', '-o', tarball,
82-
f"https://buildroot.org/downloads/{tarball.name}"
83-
]
84-
subprocess.run(curl_cmd, check=True)
80+
if not tarball.exists():
81+
curl_cmd = [
82+
'curl', '-LSs', '-o', tarball,
83+
f"https://buildroot.org/downloads/{tarball.name}"
84+
]
85+
subprocess.run(curl_cmd, check=True)
8586

8687
sha256_cmd = ['sha256sum', '--quiet', '-c', f"{tarball.name}.sha256"]
8788
subprocess.run(sha256_cmd, check=True, cwd=ROOT_FOLDER)
@@ -91,27 +92,18 @@ def download_and_extract_buildroot():
9192
]
9293
subprocess.run(tar_cmd, check=True)
9394

94-
tarball.unlink(missing_ok=True)
95-
96-
97-
def download_buildroot_if_necessary():
98-
if SRC_FOLDER.exists():
99-
# Make support/scripts/setlocalversion do nothing because we are in a
100-
# git repository so it will return information about this repo, not
101-
# Buildroot
102-
setlocalversion = Path(SRC_FOLDER, 'support/scripts/setlocalversion')
103-
setlocalversion.write_text('', encoding='utf-8')
104-
105-
installed_version = subprocess.run(['make', 'print-version'],
106-
capture_output=True,
107-
check=True,
108-
cwd=SRC_FOLDER,
109-
text=True).stdout.strip()
110-
if installed_version != BUILDROOT_VERSION:
111-
shutil.rmtree(SRC_FOLDER)
112-
download_and_extract_buildroot()
113-
else:
114-
download_and_extract_buildroot()
95+
if (patches := list(ROOT_FOLDER.glob('*.patch'))):
96+
for patch in patches:
97+
patch_cmd = [
98+
'patch', '--directory', SRC_FOLDER, '--input', patch,
99+
'--strip', '1'
100+
]
101+
try:
102+
subprocess.run(patch_cmd, check=True)
103+
except subprocess.CalledProcessError as err:
104+
raise RuntimeError(
105+
f"{patch} did not apply to Buildroot {BUILDROOT_VERSION}, does it need to be updated?"
106+
) from err
115107

116108

117109
def release_images():
@@ -161,7 +153,7 @@ def parse_arguments():
161153

162154
architectures = SUPPORTED_ARCHES if 'all' in args.architectures else args.architectures
163155

164-
download_buildroot_if_necessary()
156+
download_and_extract_buildroot()
165157
for arch in architectures:
166158
build_image(arch, args.edit_config)
167159

0 commit comments

Comments
 (0)