From 7f9bfee7220c9c0800e1ed30f841808f5694d198 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Fri, 15 Mar 2019 09:54:27 +0100 Subject: [PATCH] Add "pmbootstrap build --no-depends" (!1769) Aborts the build if any dependencies would have to be build first. This is useful for build.postmarketos.org, because we want to build exactly one package in one build job. If dependencies would need to be built, we made a mistake earlier, and not aborting the build makes it harder to find that orginal mistake. --- pmb/build/_package.py | 21 +++++++++++++++------ pmb/parse/arguments.py | 3 +++ test/test_build_package.py | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) 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