2023-01-22 18:11:10 +00:00
|
|
|
# Copyright 2023 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
""" Tests all functions from pmb.build._package """
|
2018-02-19 22:04:01 +00:00
|
|
|
import datetime
|
|
|
|
import glob
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
import os
|
|
|
|
import pytest
|
2018-02-19 22:04:01 +00:00
|
|
|
import shutil
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
import sys
|
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
import pmb_test # noqa
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
import pmb.build
|
|
|
|
import pmb.build._package
|
|
|
|
import pmb.config
|
|
|
|
import pmb.config.init
|
|
|
|
import pmb.helpers.logging
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def args(tmpdir, request):
|
|
|
|
import pmb.parse
|
|
|
|
sys.argv = ["pmbootstrap", "init"]
|
|
|
|
args = pmb.parse.arguments()
|
|
|
|
args.log = args.work + "/log_testsuite.txt"
|
|
|
|
pmb.helpers.logging.init(args)
|
2021-09-20 10:00:13 +00:00
|
|
|
request.addfinalizer(pmb.helpers.logging.logfd.close)
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def return_none(*args, **kwargs):
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def return_string(*args, **kwargs):
|
|
|
|
return "some/random/path.apk"
|
|
|
|
|
|
|
|
|
|
|
|
def return_true(*args, **kwargs):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def return_false(*args, **kwargs):
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def return_fake_build_depends(*args, **kwargs):
|
|
|
|
"""
|
|
|
|
Fake return value for pmb.build._package.build_depends:
|
|
|
|
depends: ["alpine-base"], depends_built: []
|
|
|
|
"""
|
|
|
|
return (["alpine-base"], [])
|
|
|
|
|
|
|
|
|
|
|
|
def args_patched(monkeypatch, argv):
|
|
|
|
monkeypatch.setattr(sys, "argv", argv)
|
|
|
|
return pmb.parse.arguments()
|
|
|
|
|
|
|
|
|
2021-11-09 11:54:07 +00:00
|
|
|
def test_skip_already_built():
|
2017-12-05 23:17:39 +00:00
|
|
|
func = pmb.build._package.skip_already_built
|
2021-10-30 12:20:57 +00:00
|
|
|
assert pmb.helpers.other.cache["built"] == {}
|
2021-11-09 11:54:07 +00:00
|
|
|
assert func("test-package", "armhf") is False
|
2021-10-30 12:20:57 +00:00
|
|
|
assert pmb.helpers.other.cache["built"] == {"armhf": ["test-package"]}
|
2021-11-09 11:54:07 +00:00
|
|
|
assert func("test-package", "armhf") is True
|
2017-12-05 23:17:39 +00:00
|
|
|
|
|
|
|
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
def test_get_apkbuild(args):
|
|
|
|
func = pmb.build._package.get_apkbuild
|
|
|
|
|
|
|
|
# Valid aport
|
|
|
|
pkgname = "postmarketos-base"
|
|
|
|
assert func(args, pkgname, "x86_64")["pkgname"] == pkgname
|
|
|
|
|
|
|
|
# Valid binary package
|
|
|
|
assert func(args, "alpine-base", "x86_64") is None
|
|
|
|
|
|
|
|
# Invalid package
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func(args, "invalid-package-name", "x86_64")
|
|
|
|
assert "Could not find" in str(e.value)
|
|
|
|
|
|
|
|
|
2019-03-10 00:28:10 +00:00
|
|
|
def test_check_build_for_arch(monkeypatch, args):
|
new action: 'pmbootstrap repo_missing'
Add a new action that lists all aports, for which no binary packages
exist. Only list packages that can be built for the relevant arch
(specified with --arch). This works recursively: when a package can be
built for a certain arch, but one of its dependencies
(or their depends) can not be built for that arch, then don't list it.
This action will be used for the new sr.ht based build infrastructure,
to figure out which packages need to be built ahead of time (so we can
trigger each of them as single build job). Determining the order of the
packages to be built is not determined with pmbootstrap, the serverside
code of build.postmarketos.org takes care of that.
For testing purposes, a single package can also be specified and the
action will list if it can be built for that arch with its
dependencies, and what needs to be built exactly.
Add pmb/helpers/package.py to hold functions that work on both pmaports
and (binary package) repos - in contrary to the existing
pmb/helpers/pmaports.py (see previous commit) and pmb/helpers/repo.py,
which only work with one of those.
Refactoring:
* pmb/helpers/pmaports.py: add a get_list() function, which lists all
aports and use it instead of writing the same glob loop over and over
* add pmb.helpers.pmaports.get(), which finds an APKBUILD and parses it
in one step.
* rename pmb.build._package.check_arch to ...check_arch_abort to
distinguish it from the other check_arch function
2018-11-15 07:36:39 +00:00
|
|
|
# Fake APKBUILD data
|
|
|
|
apkbuild = {"pkgname": "testpkgname"}
|
|
|
|
|
|
|
|
def fake_helpers_pmaports_get(args, pkgname):
|
|
|
|
return apkbuild
|
|
|
|
monkeypatch.setattr(pmb.helpers.pmaports, "get", fake_helpers_pmaports_get)
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
2019-03-10 00:28:10 +00:00
|
|
|
# pmaport with arch exists
|
|
|
|
func = pmb.build._package.check_build_for_arch
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
apkbuild["arch"] = ["armhf"]
|
2019-03-10 00:28:10 +00:00
|
|
|
assert func(args, "testpkgname", "armhf") is True
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
apkbuild["arch"] = ["noarch"]
|
2019-03-10 00:28:10 +00:00
|
|
|
assert func(args, "testpkgname", "armhf") is True
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
apkbuild["arch"] = ["all"]
|
2019-03-10 00:28:10 +00:00
|
|
|
assert func(args, "testpkgname", "armhf") is True
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
2019-03-10 00:28:10 +00:00
|
|
|
# No binary package exists and can't build it
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
apkbuild["arch"] = ["x86_64"]
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
new action: 'pmbootstrap repo_missing'
Add a new action that lists all aports, for which no binary packages
exist. Only list packages that can be built for the relevant arch
(specified with --arch). This works recursively: when a package can be
built for a certain arch, but one of its dependencies
(or their depends) can not be built for that arch, then don't list it.
This action will be used for the new sr.ht based build infrastructure,
to figure out which packages need to be built ahead of time (so we can
trigger each of them as single build job). Determining the order of the
packages to be built is not determined with pmbootstrap, the serverside
code of build.postmarketos.org takes care of that.
For testing purposes, a single package can also be specified and the
action will list if it can be built for that arch with its
dependencies, and what needs to be built exactly.
Add pmb/helpers/package.py to hold functions that work on both pmaports
and (binary package) repos - in contrary to the existing
pmb/helpers/pmaports.py (see previous commit) and pmb/helpers/repo.py,
which only work with one of those.
Refactoring:
* pmb/helpers/pmaports.py: add a get_list() function, which lists all
aports and use it instead of writing the same glob loop over and over
* add pmb.helpers.pmaports.get(), which finds an APKBUILD and parses it
in one step.
* rename pmb.build._package.check_arch to ...check_arch_abort to
distinguish it from the other check_arch function
2018-11-15 07:36:39 +00:00
|
|
|
func(args, "testpkgname", "armhf")
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
assert "Can't build" in str(e.value)
|
|
|
|
|
2019-03-10 00:28:10 +00:00
|
|
|
# pmaport can't be built for x86_64, but binary package exists in Alpine
|
|
|
|
apkbuild = {"pkgname": "mesa",
|
|
|
|
"arch": "armhf",
|
|
|
|
"pkgver": "9999",
|
|
|
|
"pkgrel": "0"}
|
|
|
|
assert func(args, "mesa", "x86_64") is False
|
|
|
|
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
def test_get_depends(monkeypatch):
|
|
|
|
func = pmb.build._package.get_depends
|
2017-12-02 11:51:43 +00:00
|
|
|
apkbuild = {"pkgname": "test", "depends": ["a"], "makedepends": ["c", "b"],
|
2020-01-27 23:23:09 +00:00
|
|
|
"checkdepends": "e", "subpackages": {"d": None}, "options": []}
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
# Depends + makedepends
|
|
|
|
args = args_patched(monkeypatch, ["pmbootstrap", "build", "test"])
|
2018-06-04 19:07:52 +00:00
|
|
|
assert func(args, apkbuild) == ["a", "b", "c", "e"]
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
args = args_patched(monkeypatch, ["pmbootstrap", "install"])
|
2018-06-04 19:07:52 +00:00
|
|
|
assert func(args, apkbuild) == ["a", "b", "c", "e"]
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
# Ignore depends (-i)
|
|
|
|
args = args_patched(monkeypatch, ["pmbootstrap", "build", "-i", "test"])
|
2018-06-04 19:07:52 +00:00
|
|
|
assert func(args, apkbuild) == ["b", "c", "e"]
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
2017-12-02 11:51:43 +00:00
|
|
|
# Package depends on its own subpackage
|
|
|
|
apkbuild["makedepends"] = ["d"]
|
|
|
|
args = args_patched(monkeypatch, ["pmbootstrap", "build", "test"])
|
2018-06-04 19:07:52 +00:00
|
|
|
assert func(args, apkbuild) == ["a", "e"]
|
2017-12-02 11:51:43 +00:00
|
|
|
|
|
|
|
# Package depends on itself
|
|
|
|
apkbuild["makedepends"] = ["c", "b", "test"]
|
|
|
|
args = args_patched(monkeypatch, ["pmbootstrap", "build", "test"])
|
2018-06-04 19:07:52 +00:00
|
|
|
assert func(args, apkbuild) == ["a", "b", "c", "e"]
|
2017-12-02 11:51:43 +00:00
|
|
|
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
def test_build_depends(args, monkeypatch):
|
|
|
|
# Shortcut and fake apkbuild
|
|
|
|
func = pmb.build._package.build_depends
|
2021-12-06 19:30:58 +00:00
|
|
|
apkbuild = {"pkgname": "test", "depends": ["a", "!c"],
|
|
|
|
"makedepends": ["b"], "checkdepends": [],
|
|
|
|
"subpackages": {"d": None}, "options": []}
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
# No depends built (first makedepends + depends, then only makedepends)
|
|
|
|
monkeypatch.setattr(pmb.build._package, "package", return_none)
|
2021-12-06 19:30:58 +00:00
|
|
|
assert func(args, apkbuild, "armhf", True) == (["!c", "a", "b"], [])
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
# All depends built (makedepends only)
|
|
|
|
monkeypatch.setattr(pmb.build._package, "package", return_string)
|
2021-12-06 19:30:58 +00:00
|
|
|
assert func(args, apkbuild, "armhf", False) == (["!c", "a", "b"],
|
|
|
|
["a", "b"])
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
|
2019-03-15 08:54:27 +00:00
|
|
|
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"],
|
2020-01-27 23:23:09 +00:00
|
|
|
"makedepends": [], "checkdepends": [], "subpackages": {},
|
2019-03-15 08:54:27 +00:00
|
|
|
"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"], [])
|
|
|
|
|
|
|
|
|
2020-03-31 20:50:51 +00:00
|
|
|
def test_build_depends_binary_outdated(args, monkeypatch):
|
|
|
|
""" pmbootstrap runs with --no-depends and dependency binary package is
|
|
|
|
outdated (#1895) """
|
|
|
|
# Override pmb.parse.apkindex.package(): pretend hello-world is missing
|
|
|
|
# and binutils-aarch64 is outdated
|
|
|
|
func_orig = pmb.parse.apkindex.package
|
|
|
|
|
|
|
|
def func_patch(args, package, *args2, **kwargs):
|
|
|
|
print(f"func_patch: called for package: {package}")
|
|
|
|
if package == "hello-world":
|
2020-04-11 16:20:18 +00:00
|
|
|
print("pretending that it does not exist")
|
2020-03-31 20:50:51 +00:00
|
|
|
return None
|
|
|
|
if package == "binutils-aarch64":
|
2020-04-11 16:20:18 +00:00
|
|
|
print("pretending that it is outdated")
|
2020-03-31 20:50:51 +00:00
|
|
|
ret = func_orig(args, package, *args2, **kwargs)
|
|
|
|
ret["version"] = "0-r0"
|
|
|
|
return ret
|
|
|
|
return func_orig(args, package, *args2, **kwargs)
|
|
|
|
monkeypatch.setattr(pmb.parse.apkindex, "package", func_patch)
|
|
|
|
|
|
|
|
# Build hello-world with --no-depends and expect failure
|
|
|
|
args.no_depends = True
|
|
|
|
pkgname = "hello-world"
|
|
|
|
arch = "aarch64"
|
|
|
|
force = False
|
|
|
|
strict = True
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
pmb.build.package(args, pkgname, arch, force, strict)
|
|
|
|
assert "'binutils-aarch64' of 'gcc-aarch64' is outdated" in str(e.value)
|
|
|
|
|
|
|
|
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
def test_is_necessary_warn_depends(args, monkeypatch):
|
|
|
|
# Shortcut and fake apkbuild
|
|
|
|
func = pmb.build._package.is_necessary_warn_depends
|
|
|
|
apkbuild = {"pkgname": "test"}
|
|
|
|
|
|
|
|
# Necessary
|
|
|
|
monkeypatch.setattr(pmb.build, "is_necessary", return_true)
|
|
|
|
assert func(args, apkbuild, "armhf", False, []) is True
|
|
|
|
|
|
|
|
# Necessary (strict=True overrides is_necessary())
|
|
|
|
monkeypatch.setattr(pmb.build, "is_necessary", return_false)
|
|
|
|
assert func(args, apkbuild, "armhf", True, []) is True
|
|
|
|
|
|
|
|
# Not necessary (with depends: different code path that prints a warning)
|
|
|
|
assert func(args, apkbuild, "armhf", False, []) is False
|
|
|
|
assert func(args, apkbuild, "armhf", False, ["first", "second"]) is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_init_buildenv(args, monkeypatch):
|
Properly escape commands in pmb.chroot.user() (#1316)
## Introduction
In #1302 we noticed that `pmb.chroot.user()` does not escape commands
properly: When passing one string with spaces, it would pass them as
two strings to the chroot. The use case is passing a description with
a space inside to `newapkbuild` with `pmboostrap newapkbuild`.
This is not a security issue, as we don't pass strings from untrusted
input to this function.
## Functions for running commands in pmbootstrap
To put the rest of the description in context: We have four high level
functions that run commands:
* `pmb.helpers.run.user()`
* `pmb.helpers.run.root()`
* `pmb.chroot.root()`
* `pmb.chroot.user()`
In addition, one low level function that the others invoke:
* `pmb.helpers.run.core()`
## Flawed test case
The issue described above did not get detected for so long, because we
have a test case in place since day one, which verifies that all of the
functions above escape everything properly:
* `test/test_shell_escape.py`
So the test case ran a given command through all these functions, and
compared the result each time. However, `pmb.chroot.root()`
modified the command variable (passed by reference) and did the
escaping already, which means `pmb.chroot.user()` running directly
afterwards only returns the right output when *not* doing any escaping.
Without questioning the accuracy of the test case, I've escaped
commands and environment variables with `shlex.quote()` *before*
passing them to `pmb.chroot.user()`. In retrospective this does not
make sense at all and is reverted with this commit.
## Environment variables
By coincidence, we have only passed custom environment variables to
`pmb.chroot.user()`, never to the other high level functions. This only
worked, because we did not do any escaping and the passed line gets
executed as shell command:
```
$ MYENV=test echo test2
test 2
```
If it was properly escaped as one shell command:
```
$ 'MYENV=test echo test2'
sh: MYENV=test echo test2: not found
```
So doing that clearly doesn't work anymore. I have added a new `env`
parameter to `pmb.chroot.user()` (and to all other high level functions
for consistency), where environment variables can be passed as a
dictionary. Then the function knows what to do and we end up with
properly escaped commands and environment variables.
## Details
* Add new `env` parameter to all high level command execution functions
* New `pmb.helpers.run.flat_cmd()` function, that takes a command as
list and environment variables as dict, and creates a properly escaped
flat string from the input.
* Use that function for proper escaping in all high level exec funcs
* Don't escape commands *before* passing them to `pmb.chroot.user()`
* Describe parameters of the command execution functions
* `pmbootstrap -v` writes the exact command to the log that was
executed (in addition to the simplified form we always write down for
readability)
* `test_shell_escape.py`: verify that the command passed by reference
has not been modified, add a new test for strings with spaces, add
tests for new function `pmb.helpers.run.flat_cmd()`
* Remove obsolete commend in `pmb.chroot.distccd` about environment
variables, because we don't use any there anymore
* Add `TERM=xterm` to default environment variables in the chroot,
so running ncurses applications like `menuconfig` and `nano` works out of
the box
2018-03-10 22:58:39 +00:00
|
|
|
# First init native chroot buildenv properly without patched functions
|
|
|
|
pmb.build.init(args)
|
|
|
|
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
# Disable effects of functions we don't want to test here
|
|
|
|
monkeypatch.setattr(pmb.build._package, "build_depends",
|
|
|
|
return_fake_build_depends)
|
|
|
|
monkeypatch.setattr(pmb.build._package, "is_necessary_warn_depends",
|
|
|
|
return_true)
|
|
|
|
monkeypatch.setattr(pmb.chroot.apk, "install", return_none)
|
|
|
|
monkeypatch.setattr(pmb.chroot.distccd, "start", return_none)
|
|
|
|
|
|
|
|
# Shortcut and fake apkbuild
|
|
|
|
func = pmb.build._package.init_buildenv
|
2021-05-19 19:43:36 +00:00
|
|
|
apkbuild = {"pkgname": "test", "depends": ["a"], "makedepends": ["b"],
|
|
|
|
"options": []}
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
# Build is necessary (various code paths)
|
|
|
|
assert func(args, apkbuild, "armhf", strict=True) is True
|
|
|
|
assert func(args, apkbuild, "armhf", cross="native") is True
|
|
|
|
assert func(args, apkbuild, "armhf", cross="distcc") is True
|
|
|
|
|
|
|
|
# Build is not necessary (only builds dependencies)
|
|
|
|
monkeypatch.setattr(pmb.build._package, "is_necessary_warn_depends",
|
|
|
|
return_false)
|
|
|
|
assert func(args, apkbuild, "armhf") is False
|
|
|
|
|
|
|
|
|
2018-02-19 22:04:01 +00:00
|
|
|
def test_get_pkgver(monkeypatch):
|
|
|
|
# With original source
|
|
|
|
func = pmb.build._package.get_pkgver
|
|
|
|
assert func("1.0", True) == "1.0"
|
|
|
|
|
|
|
|
# Without original source
|
|
|
|
now = datetime.date(2018, 1, 1)
|
|
|
|
assert func("1.0", False, now) == "1.0_p20180101000000"
|
|
|
|
assert func("1.0_git20170101", False, now) == "1.0_p20180101000000"
|
|
|
|
|
|
|
|
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
def test_run_abuild(args, monkeypatch):
|
|
|
|
# Disable effects of functions we don't want to test here
|
|
|
|
monkeypatch.setattr(pmb.build, "copy_to_buildpath", return_none)
|
|
|
|
monkeypatch.setattr(pmb.chroot, "user", return_none)
|
|
|
|
|
|
|
|
# Shortcut and fake apkbuild
|
|
|
|
func = pmb.build._package.run_abuild
|
|
|
|
apkbuild = {"pkgname": "test", "pkgver": "1", "pkgrel": "2", "options": []}
|
|
|
|
|
|
|
|
# Normal run
|
|
|
|
output = "armhf/test-1-r2.apk"
|
2023-02-23 06:47:43 +00:00
|
|
|
env = {"CARCH": "armhf",
|
|
|
|
"GOCACHE": "/home/pmos/.cache/go-build",
|
|
|
|
"SUDO_APK": "abuild-apk --no-progress"}
|
2018-04-19 00:14:52 +00:00
|
|
|
cmd = ["abuild", "-D", "postmarketOS", "-d"]
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
assert func(args, apkbuild, "armhf") == (output, cmd, env)
|
|
|
|
|
|
|
|
# Force and strict
|
2018-04-19 00:14:52 +00:00
|
|
|
cmd = ["abuild", "-D", "postmarketOS", "-r", "-f"]
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
assert func(args, apkbuild, "armhf", True, True) == (output, cmd, env)
|
|
|
|
|
|
|
|
# cross=native
|
|
|
|
env = {"CARCH": "armhf",
|
2023-02-23 06:47:43 +00:00
|
|
|
"GOCACHE": "/home/pmos/.cache/go-build",
|
2018-02-09 18:43:58 +00:00
|
|
|
"SUDO_APK": "abuild-apk --no-progress",
|
2019-09-18 11:36:58 +00:00
|
|
|
"CROSS_COMPILE": "armv6-alpine-linux-musleabihf-",
|
|
|
|
"CC": "armv6-alpine-linux-musleabihf-gcc"}
|
2018-04-19 00:14:52 +00:00
|
|
|
cmd = ["abuild", "-D", "postmarketOS", "-d"]
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
assert func(args, apkbuild, "armhf", cross="native") == (output, cmd, env)
|
|
|
|
|
|
|
|
# cross=distcc
|
2017-12-21 16:42:29 +00:00
|
|
|
(output, cmd, env) = func(args, apkbuild, "armhf", cross="distcc")
|
|
|
|
assert output == "armhf/test-1-r2.apk"
|
|
|
|
assert env["CARCH"] == "armhf"
|
2023-02-23 06:47:43 +00:00
|
|
|
assert env["GOCACHE"] == "/home/pmos/.cache/go-build"
|
2017-12-21 16:42:29 +00:00
|
|
|
assert env["CCACHE_PREFIX"] == "distcc"
|
|
|
|
assert env["CCACHE_PATH"] == "/usr/lib/arch-bin-masquerade/armhf:/usr/bin"
|
|
|
|
assert env["CCACHE_COMPILERCHECK"].startswith("string:")
|
pmb: adjust to distcc 3.3 and wrap it with sshd
Overview:
Since Alpine updated to distcc 3.3 last week, pmbootstrap wasn't able to use
distcc for cross compilation anymore. It always falled back to running the
compiler in QEMU (which works, but is a lot slower). The reason for that is,
that distcc requires all compilers that are being used in a whitelist now.
This partially fixes CVE-2004-2687 in distccd, which allowed trivial remote
code execution by any process connecting to the distccd server. We only run
distccd on localhost, but still this can be used for privilege escalation of
sandboxed processes running on the host system (not part of pmbootstrap
chroots).
Because the CVE is only partially fixed (see the comment in
`pmb/chroot/distccd.py` for details), we make sure that only the building
chroots can talk to the distcc server by running distcc over ssh.
Details:
* Completely refactored `pmb/chroot/distccd.py` to run distcc over ssh
* Store the running distcc server's arguments as JSON now, not as INI
* Make debugging distcc issues easy:
* Set DISTCC_BACKOFF_PERIOD=0, so the distcc client will not ignore the
server after errors happened (this masks the original error!)
* New pmbootstrap parameters:
* `--distcc-nofallback`: avoids falling back to compiling with QEMU and not
throwing an error
* `--ccache-disable`: avoid ccache (when the compiler output is cached,
distcc does not get used)
* `--verbose` prints verbose output of the distcc too
* New test case, that uses the new pmbootstrap parameters to force
compilation through distcc, and shows the output of distcc and distccd in
verbose mode on error (as well as the log of sshd)
2018-07-25 19:09:45 +00:00
|
|
|
assert env["DISTCC_HOSTS"] == "@127.0.0.1:/home/pmos/.distcc-sshd/distccd"
|
|
|
|
assert env["DISTCC_BACKOFF_PERIOD"] == "0"
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_finish(args, monkeypatch):
|
|
|
|
# Real output path
|
|
|
|
output = pmb.build.package(args, "hello-world", force=True)
|
|
|
|
|
|
|
|
# Disable effects of functions we don't want to test below
|
|
|
|
monkeypatch.setattr(pmb.chroot, "user", return_none)
|
|
|
|
|
|
|
|
# Shortcut and fake apkbuild
|
|
|
|
func = pmb.build._package.finish
|
2019-03-27 21:31:49 +00:00
|
|
|
apkbuild = {"options": []}
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
# Non-existing output path
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func(args, apkbuild, "armhf", "/invalid/path")
|
|
|
|
assert "Package not found" in str(e.value)
|
|
|
|
|
|
|
|
# Existing output path
|
2021-10-16 16:33:27 +00:00
|
|
|
func(args, apkbuild, pmb.config.arch_native, output)
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_package(args):
|
|
|
|
# First build
|
|
|
|
assert pmb.build.package(args, "hello-world", force=True)
|
|
|
|
|
|
|
|
# Package exists
|
2021-10-30 12:20:57 +00:00
|
|
|
pmb.helpers.other.cache["built"] = {}
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
assert pmb.build.package(args, "hello-world") is None
|
|
|
|
|
|
|
|
# Force building again
|
2021-10-30 12:20:57 +00:00
|
|
|
pmb.helpers.other.cache["built"] = {}
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
assert pmb.build.package(args, "hello-world", force=True)
|
|
|
|
|
|
|
|
# Build for another architecture
|
|
|
|
assert pmb.build.package(args, "hello-world", "armhf", force=True)
|
|
|
|
|
|
|
|
# Upstream package, for which we don't have an aport
|
|
|
|
assert pmb.build.package(args, "alpine-base") is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_build_depends_high_level(args, monkeypatch):
|
|
|
|
"""
|
|
|
|
"hello-world-wrapper" depends on "hello-world". We build both, then delete
|
|
|
|
"hello-world" and check that it gets rebuilt correctly again.
|
|
|
|
"""
|
|
|
|
# Patch pmb.build.is_necessary() to always build the hello-world package
|
|
|
|
def fake_build_is_necessary(args, arch, apkbuild, apkindex_path=None):
|
|
|
|
if apkbuild["pkgname"] == "hello-world":
|
|
|
|
return True
|
|
|
|
return pmb.build.other.is_necessary(args, arch, apkbuild,
|
|
|
|
apkindex_path)
|
|
|
|
monkeypatch.setattr(pmb.build, "is_necessary",
|
|
|
|
fake_build_is_necessary)
|
|
|
|
|
|
|
|
# Build hello-world to get its full output path
|
2020-04-10 13:21:23 +00:00
|
|
|
channel = pmb.config.pmaports.read_config(args)["channel"]
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
output_hello = pmb.build.package(args, "hello-world")
|
2020-04-10 13:21:23 +00:00
|
|
|
output_hello_outside = f"{args.work}/packages/{channel}/{output_hello}"
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
assert os.path.exists(output_hello_outside)
|
|
|
|
|
|
|
|
# Make sure the wrapper exists
|
|
|
|
pmb.build.package(args, "hello-world-wrapper")
|
|
|
|
|
|
|
|
# Remove hello-world
|
|
|
|
pmb.helpers.run.root(args, ["rm", output_hello_outside])
|
2021-10-16 16:33:27 +00:00
|
|
|
pmb.build.index_repo(args, pmb.config.arch_native)
|
2021-10-30 12:20:57 +00:00
|
|
|
pmb.helpers.other.cache["built"] = {}
|
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935)
* Rename pmb/build/package.py to pmb/build/_package.py, so we can
access the functions it contains in testcases, and still use
pmb.build.package()
* Refactor the entire file. Instead of one big function that does
too many things, we have many small ones now, that are tested
in the testsuite and easier to modify
* Whenever building a package, pmbootstrap does not only build and
install the "makedepends" (like we did before), now it does the
same for the "depends". That's required to be compatible with
abuild. The old behavior can still be used with 'pmbootstrap
build --ignore-depends'.
* Because of that change, noarch packages can no longer be built in
the native chroot if we need them for a foreign chroot. A device-
package depending on a kernel would pull in the same kernel for
the native architecture otherwise.
* Running 'pmbootstrap build device-...' without '--ignore-depends'
and without a matching '--arch' displays a note that explains
this change to the user and tells how to use it instead.
* Noarch packages no longer get symlinked. That was only
implemented for packages built in the native chroot, and now that
is not always the case anymore. Symlinking these packages creates
packages with broken dependencies anyway (e.g.
device-samsung-i9100 can't be installed in x86_64, because
linux-samsung-i9100 is armhf only).
* Rename "carch" to "arch" wherever used. Naming it "carch"
sometimes is confusing with no benefit.
* Add a testcase for the aarch64 qemu workaround (because it failed
first and I needed to know for sure if it is working again).
* Improved some verbose logging, which helped with development of
this feature.
* Removed the old "build" test case (which was disabled in
testcases_fast.sh) as the new "build_package" test case covers its
functionallity.
* Only build indexes if the packages folder exists for that arch (Travis
couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
|
|
|
|
|
|
|
# Ask to build the wrapper. It should not build the wrapper (it exists, not
|
|
|
|
# using force), but build/update its missing dependency "hello-world"
|
|
|
|
# instead.
|
|
|
|
assert pmb.build.package(args, "hello-world-wrapper") is None
|
|
|
|
assert os.path.exists(output_hello_outside)
|
2018-02-19 22:04:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_build_local_source_high_level(args, tmpdir):
|
|
|
|
"""
|
|
|
|
Test building a package with overriding the source code:
|
|
|
|
pmbootstrap build --src=/some/path hello-world
|
|
|
|
|
2021-09-26 15:50:11 +00:00
|
|
|
We use a copy of the hello-world APKBUILD here that doesn't have the
|
2018-02-19 22:04:01 +00:00
|
|
|
source files it needs to build included. And we use the original aport
|
|
|
|
folder as local source folder, so pmbootstrap should take the source files
|
|
|
|
from there and the build should succeed.
|
|
|
|
"""
|
|
|
|
# aports: Add deviceinfo (required by pmbootstrap to start)
|
|
|
|
tmpdir = str(tmpdir)
|
|
|
|
aports = tmpdir + "/aports"
|
2020-02-26 11:13:26 +00:00
|
|
|
aport = aports + "/device/testing/device-" + args.device
|
2018-02-19 22:04:01 +00:00
|
|
|
os.makedirs(aport)
|
2020-04-11 16:40:11 +00:00
|
|
|
path_original = pmb.helpers.pmaports.find(args, f"device-{args.device}")
|
|
|
|
shutil.copy(f"{path_original}/deviceinfo", aport)
|
2018-02-19 22:04:01 +00:00
|
|
|
|
|
|
|
# aports: Add modified hello-world aport (source="", uses $builddir)
|
|
|
|
aport = aports + "/main/hello-world"
|
|
|
|
os.makedirs(aport)
|
|
|
|
shutil.copy(pmb.config.pmb_src + "/test/testdata/build_local_src/APKBUILD",
|
|
|
|
aport)
|
|
|
|
|
2019-11-10 10:20:00 +00:00
|
|
|
# aports: Add pmaports.cfg, .git
|
2018-09-05 05:57:38 +00:00
|
|
|
shutil.copy(args.aports + "/pmaports.cfg", aports)
|
2019-11-10 10:20:00 +00:00
|
|
|
shutil.copytree(args.aports + "/.git", aports + "/.git")
|
2018-09-05 05:57:38 +00:00
|
|
|
|
2018-02-19 22:04:01 +00:00
|
|
|
# src: Copy hello-world source files
|
|
|
|
src = tmpdir + "/src"
|
|
|
|
os.makedirs(src)
|
|
|
|
shutil.copy(args.aports + "/main/hello-world/Makefile", src)
|
|
|
|
shutil.copy(args.aports + "/main/hello-world/main.c", src)
|
|
|
|
|
|
|
|
# src: Create unreadable file (rsync should skip it)
|
|
|
|
unreadable = src + "/_unreadable_file"
|
|
|
|
shutil.copy(args.aports + "/main/hello-world/main.c", unreadable)
|
|
|
|
pmb.helpers.run.root(args, ["chown", "root:root", unreadable])
|
|
|
|
pmb.helpers.run.root(args, ["chmod", "500", unreadable])
|
|
|
|
|
2018-03-05 21:04:28 +00:00
|
|
|
# Test native arch and foreign arch chroot
|
2020-04-10 13:21:23 +00:00
|
|
|
channel = pmb.config.pmaports.read_config(args)["channel"]
|
2021-10-16 16:33:27 +00:00
|
|
|
for arch in [pmb.config.arch_native, "armhf"]:
|
2018-03-05 21:04:28 +00:00
|
|
|
# Delete all hello-world --src packages
|
2020-04-10 13:21:23 +00:00
|
|
|
pattern = f"{args.work}/packages/{channel}/{arch}/hello-world-*_p*.apk"
|
2018-03-05 21:04:28 +00:00
|
|
|
for path in glob.glob(pattern):
|
|
|
|
pmb.helpers.run.root(args, ["rm", path])
|
|
|
|
assert len(glob.glob(pattern)) == 0
|
|
|
|
|
|
|
|
# Build hello-world --src package
|
|
|
|
pmb.helpers.run.user(args, [pmb.config.pmb_src + "/pmbootstrap.py",
|
|
|
|
"--aports", aports, "build", "--src", src,
|
|
|
|
"hello-world", "--arch", arch])
|
|
|
|
|
|
|
|
# Verify that the package has been built and delete it
|
|
|
|
paths = glob.glob(pattern)
|
|
|
|
assert len(paths) == 1
|
|
|
|
pmb.helpers.run.root(args, ["rm", paths[0]])
|
|
|
|
|
|
|
|
# Clean up: update index, delete temp folder
|
2021-10-16 16:33:27 +00:00
|
|
|
pmb.build.index_repo(args, pmb.config.arch_native)
|
2018-02-19 22:04:01 +00:00
|
|
|
pmb.helpers.run.root(args, ["rm", "-r", tmpdir])
|
2022-12-07 20:52:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_build_abuild_leftovers(args, tmpdir):
|
|
|
|
"""
|
|
|
|
Test building a package with having abuild leftovers, that will error if
|
|
|
|
copied:
|
|
|
|
pmbootstrap build hello-world
|
|
|
|
"""
|
|
|
|
# aports: Add deviceinfo (required by pmbootstrap to start)
|
|
|
|
tmpdir = str(tmpdir)
|
|
|
|
aports = f"{tmpdir}/aports"
|
|
|
|
aport = f"{aports}/device/testing/device-{args.device}"
|
|
|
|
os.makedirs(aport)
|
|
|
|
path_original = pmb.helpers.pmaports.find(args, f"device-{args.device}")
|
|
|
|
shutil.copy(f"{path_original}/deviceinfo", aport)
|
|
|
|
|
|
|
|
# aports: Add modified hello-world aport (source="", uses $builddir)
|
|
|
|
test_aport = "main/hello-world"
|
|
|
|
aport = f"{aports}/{test_aport}"
|
|
|
|
shutil.copytree(f"{args.aports}/{test_aport}", aport)
|
|
|
|
|
|
|
|
# aports: Add pmaports.cfg, .git
|
|
|
|
shutil.copy(f"{args.aports}/pmaports.cfg", aports)
|
|
|
|
shutil.copytree(f"{args.aports}/.git", f"{aports}/.git")
|
|
|
|
|
|
|
|
# aport: create abuild dir with broken symlink
|
|
|
|
src = f"{aport}/src"
|
|
|
|
os.makedirs(src)
|
|
|
|
os.symlink("/var/cache/distfiles/non-existent.tar.gz",
|
|
|
|
f"{src}/broken-tarball-symlink.tar.gz")
|
|
|
|
|
|
|
|
# Delete all hello-world packages
|
|
|
|
channel = pmb.config.pmaports.read_config(args)["channel"]
|
|
|
|
pattern = f"{args.work}/packages/{channel}/*/hello-world-*_p*.apk"
|
|
|
|
for path in glob.glob(pattern):
|
|
|
|
pmb.helpers.run.root(args, ["rm", path])
|
|
|
|
assert len(glob.glob(pattern)) == 0
|
|
|
|
|
|
|
|
# Build hello-world package
|
|
|
|
pmb.helpers.run.user(args, [f"{pmb.config.pmb_src}/pmbootstrap.py",
|
|
|
|
"--aports", aports, "build", "--src", src,
|
|
|
|
"hello-world", "--arch", pmb.config.arch_native])
|
|
|
|
|
|
|
|
# Verify that the package has been built and delete it
|
|
|
|
paths = glob.glob(pattern)
|
|
|
|
assert len(paths) == 1
|
|
|
|
pmb.helpers.run.root(args, ["rm", paths[0]])
|
|
|
|
|
|
|
|
# Clean up: update index, delete temp folder
|
|
|
|
pmb.build.index_repo(args, pmb.config.arch_native)
|
|
|
|
pmb.helpers.run.root(args, ["rm", "-r", tmpdir])
|