Skip to content

Commit 432658b

Browse files
committed
Add support for local path with --extra-package
1 parent 2fdc1c0 commit 432658b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

docker_deb_build.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ def parse_arguments() -> argparse.Namespace:
7272
action='append',
7373
default=[],
7474
help="Additional APT repository to include. Can be specified multiple times. Example: 'deb [arch=arm64 trusted=yes] http://pkg.qualcomm.com noble/stable main'")
75+
parser.add_argument("-p", "--extra-package",
76+
type=str,
77+
action='append',
78+
default=[],
79+
help="Additional .deb file or directory to install inside the build chroot. Can be specified multiple times.")
7580

7681
parser.add_argument("-r", "--rebuild",
7782
action='store_true',
@@ -232,7 +237,7 @@ def rebuild_docker_images(build_arch: str) -> None:
232237

233238
build_docker_image(build_arch, suite_name)
234239

235-
def build_package_in_docker(image_name: str, source_dir: str, output_dir: str, build_arch: str, distro: str, run_lintian: bool, extra_repo: str) -> bool:
240+
def build_package_in_docker(image_name: str, source_dir: str, output_dir: str, build_arch: str, distro: str, run_lintian: bool, extra_repo: str, extra_package: str) -> bool:
236241
"""
237242
Build the debian package inside the given docker image.
238243
source_dir: path to the debian package source (mounted into the container)
@@ -254,9 +259,10 @@ def build_package_in_docker(image_name: str, source_dir: str, output_dir: str, b
254259
# Build the gbp command
255260
# The --git-builder value is a single string passed to gbp
256261
extra_repo_option = " ".join(f"--extra-repository='{repo}'" for repo in extra_repo) if extra_repo else ""
262+
extra_package_option = " ".join(f"--extra-package='{pkg}'" for pkg in extra_package) if extra_package else ""
257263
lintian_option = '--no-run-lintian' if not run_lintian else ""
258264
# --no-clean-source: skip dpkg-buildpackage --clean on host (avoids build-dep check outside chroot)
259-
sbuild_cmd = f"sbuild --no-clean-source --build-dir=/workspace/output --host=arm64 --build={build_arch} --dist={distro} {lintian_option} {extra_repo_option}"
265+
sbuild_cmd = f"sbuild --no-clean-source --build-dir=/workspace/output --host=arm64 --build={build_arch} --dist={distro} {lintian_option} {extra_repo_option} {extra_package_option}"
260266

261267
# Ensure git inside the container treats the mounted checkout as safe
262268
git_safe_cmd = "git config --global --add safe.directory /workspace/src"
@@ -281,10 +287,22 @@ def build_package_in_docker(image_name: str, source_dir: str, output_dir: str, b
281287
else:
282288
raise Exception(f"Unsupported debian/source/format in {format_file}. Expected to contain 'native' or 'quilt', got: {fmt!r}")
283289

290+
# Prepare volume mounts for extra packages (files or directories)
291+
extra_mounts = []
292+
for pkg_path in extra_package:
293+
abs_path = os.path.abspath(pkg_path)
294+
if not os.path.exists(abs_path):
295+
logger.warning(f"Extra package path does not exist and will be ignored: {pkg_path}")
296+
continue
297+
# Mount at the same absolute path inside the container
298+
extra_mounts.extend(['-v', f"{abs_path}:{abs_path}:Z"])
299+
284300
docker_cmd = [
285301
'docker', 'run', '--rm', '--privileged', "-t",
286302
'-v', f"{source_dir}:/workspace/src:Z",
287303
'-v', f"{output_dir}:/workspace/output:Z",
304+
# Insert any extra package mounts
305+
*extra_mounts,
288306
'-w', '/workspace/src',
289307
image_name, 'bash', '-c', build_cmd
290308
]
@@ -419,7 +437,7 @@ def main() -> None:
419437
else:
420438
logger.info(f"Docker image '{image_name}' is present locally.")
421439

422-
ret = build_package_in_docker(image_name, args.source_dir, args.output_dir, build_arch, args.distro, args.run_lintian, args.extra_repo)
440+
ret = build_package_in_docker(image_name, args.source_dir, args.output_dir, build_arch, args.distro, args.run_lintian, args.extra_repo, args.extra_package)
423441

424442
if ret:
425443
sys.exit(0)
@@ -436,4 +454,4 @@ def main() -> None:
436454

437455
traceback.print_exc()
438456

439-
sys.exit(1)
457+
sys.exit(1)

0 commit comments

Comments
 (0)