diff --git a/pmb/build/_package.py b/pmb/build/_package.py index 6c73dc38..14f760ef 100644 --- a/pmb/build/_package.py +++ b/pmb/build/_package.py @@ -140,13 +140,22 @@ def build_depends(args, apkbuild, arch, strict): logging.verbose(pkgname + ": build/install dependencies: " + ", ".join(depends)) - # Build them + # --no-depends: check for binary packages depends_built = [] - for depend in depends: - if package(args, depend, arch, strict=strict): - depends_built += [depend] - logging.verbose(pkgname + ": build dependencies: done, built: " + - ", ".join(depends_built)) + if "no_depends" in args and args.no_depends: + for depend in depends: + if not pmb.parse.apkindex.package(args, depend, arch, False): + raise RuntimeError("Missing binary package for dependency '" + + depend + "' of '" + pkgname + "', but" + " pmbootstrap won't build any depends since" + " it was started with --no-depends.") + else: + # Build the dependencies + for depend in depends: + if package(args, depend, arch, strict=strict): + depends_built += [depend] + logging.verbose(pkgname + ": build dependencies: done, built: " + + ", ".join(depends_built)) return (depends, depends_built) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 02b1ef06..bcbc3ab7 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -496,6 +496,9 @@ def arguments(): " you don't need to build and install the kernel. But it" " is incompatible with how Alpine's abuild handles it.", dest="ignore_depends") + build.add_argument("-n", "--no-depends", action="store_true", + help="never build dependencies, abort instead", + dest="no_depends") build.add_argument("--envkernel", action="store_true", help="Create an apk package from the build output of" " a kernel compiled with envkernel.sh.") diff --git a/test/test_build_package.py b/test/test_build_package.py index 92fcb30b..f0549013 100644 --- a/test/test_build_package.py +++ b/test/test_build_package.py @@ -174,6 +174,26 @@ def test_build_depends(args, monkeypatch): assert func(args, apkbuild, "armhf", False) == (["a", "b"], ["a", "b"]) +def test_build_depends_no_binary_error(args, monkeypatch): + # Shortcut and fake apkbuild + func = pmb.build._package.build_depends + apkbuild = {"pkgname": "test", "depends": ["some-invalid-package-here"], + "makedepends": [], "checkdepends": [], "subpackages": [], + "options": []} + + # pmbootstrap build --no-depends + args.no_depends = True + + # Missing binary package error + with pytest.raises(RuntimeError) as e: + func(args, apkbuild, "armhf", True) + assert str(e.value).startswith("Missing binary package for dependency") + + # All depends exist + apkbuild["depends"] = ["alpine-base"] + assert func(args, apkbuild, "armhf", True) == (["alpine-base"], []) + + def test_is_necessary_warn_depends(args, monkeypatch): # Shortcut and fake apkbuild func = pmb.build._package.is_necessary_warn_depends