Skip to content

Commit fe6ff51

Browse files
keerthi-gosimonbeaudoin0935
authored andcommitted
Add support for local path with --extra-package
Signed-off-by: keerthi-go <kbalehal@qti.qualcomm.com>
1 parent 439d5f2 commit fe6ff51

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

docker_deb_build.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ 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+
76+
parser.add_argument("-p", "--extra-package",
77+
type=str,
78+
action='append',
79+
default=[],
80+
help="Additional .deb file or directory to install inside the build chroot. Can be specified multiple times.")
7581

7682
parser.add_argument("-r", "--rebuild",
7783
action='store_true',
@@ -232,7 +238,7 @@ def rebuild_docker_images(build_arch: str) -> None:
232238

233239
build_docker_image(build_arch, suite_name)
234240

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:
241+
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:
236242
"""
237243
Build the debian package inside the given docker image.
238244
source_dir: path to the debian package source (mounted into the container)
@@ -254,9 +260,10 @@ def build_package_in_docker(image_name: str, source_dir: str, output_dir: str, b
254260
# Build the gbp command
255261
# The --git-builder value is a single string passed to gbp
256262
extra_repo_option = " ".join(f"--extra-repository='{repo}'" for repo in extra_repo) if extra_repo else ""
263+
extra_package_option = " ".join(f"--extra-package='{pkg}'" for pkg in extra_package) if extra_package else ""
257264
lintian_option = '--no-run-lintian' if not run_lintian else ""
258265
# --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}"
266+
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}"
260267

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

291+
# Prepare volume mounts for extra packages (files or directories)
292+
extra_mounts = []
293+
for pkg_path in extra_package:
294+
abs_path = os.path.abspath(pkg_path)
295+
if not os.path.exists(abs_path):
296+
logger.warning(f"Extra package path does not exist and will be ignored: {pkg_path}")
297+
continue
298+
# Mount at the same absolute path inside the container
299+
extra_mounts.extend(['-v', f"{abs_path}:{abs_path}:Z"])
300+
284301
docker_cmd = [
285302
'docker', 'run', '--rm', '--privileged', "-t",
286303
'-v', f"{source_dir}:/workspace/src:Z",
287304
'-v', f"{output_dir}:/workspace/output:Z",
305+
# Insert any extra package mounts
306+
*extra_mounts,
288307
'-w', '/workspace/src',
289308
image_name, 'bash', '-c', build_cmd
290309
]
@@ -419,7 +438,7 @@ def main() -> None:
419438
else:
420439
logger.info(f"Docker image '{image_name}' is present locally.")
421440

422-
ret = build_package_in_docker(image_name, args.source_dir, args.output_dir, build_arch, args.distro, args.run_lintian, args.extra_repo)
441+
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)
423442

424443
if ret:
425444
sys.exit(0)
@@ -436,4 +455,4 @@ def main() -> None:
436455

437456
traceback.print_exc()
438457

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

0 commit comments

Comments
 (0)