pmbootstrap/pmb/build/_package.py

524 lines
21 KiB
Python
Raw Normal View History

2022-01-02 21:38:21 +00:00
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import datetime
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 logging
import os
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.autodetect
import pmb.chroot
import pmb.chroot.apk
import pmb.chroot.distccd
import pmb.helpers.pmaports
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.helpers.repo
import pmb.parse
import pmb.parse.arch
2021-11-09 11:54:07 +00:00
def skip_already_built(pkgname, arch):
"""
Check if the package was already built in this session, and add it
to the cache in case it was not built yet.
:returns: True when it can be skipped or False
"""
if arch not in pmb.helpers.other.cache["built"]:
pmb.helpers.other.cache["built"][arch] = []
if pkgname in pmb.helpers.other.cache["built"][arch]:
logging.verbose(pkgname + ": already checked this session,"
" no need to build it or its dependencies")
return True
pmb.helpers.other.cache["built"][arch].append(pkgname)
return 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 get_apkbuild(args, pkgname, arch):
"""
2018-11-15 07:36:39 +00:00
Parse the APKBUILD path for pkgname. When there is none, try to find it in
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
the binary package APKINDEX files or raise an exception.
:param pkgname: package name to be built, as specified in the APKBUILD
2018-11-15 07:36:39 +00:00
:returns: None or parsed APKBUILD
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
"""
# Get existing binary package indexes
pmb.helpers.repo.update(args, 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
2018-11-15 07:36:39 +00:00
# Get pmaport, skip upstream only packages
pmaport = pmb.helpers.pmaports.get(args, pkgname, False)
if pmaport:
return pmaport
if pmb.parse.apkindex.providers(args, pkgname, arch, 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
return None
raise RuntimeError("Package '" + pkgname + "': Could not find aport, and"
" could not find this package in any APKINDEX!")
def check_build_for_arch(args, pkgname, 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
"""
Check if pmaport can be built or exists as binary for a specific arch.
:returns: * True when it can be built
* False when it can't be built, but exists in a binary repo
(e.g. temp/mesa can't be built for x86_64, but Alpine has it)
:raises: RuntimeError if the package can't be built for the given arch and
does not exist as binary package.
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
"""
# Check for pmaport with arch
2018-11-15 07:36:39 +00:00
if pmb.helpers.package.check_arch(args, pkgname, arch, False):
return 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
# Check for binary package
binary = pmb.parse.apkindex.package(args, pkgname, arch, False)
if binary:
pmaport = pmb.helpers.pmaports.get(args, pkgname)
pmaport_version = pmaport["pkgver"] + "-r" + pmaport["pkgrel"]
logging.debug(pkgname + ": found pmaport (" + pmaport_version + ") and"
" binary package (" + binary["version"] + ", from"
" postmarketOS or Alpine), but pmaport can't be built"
" for " + arch + " -> using binary package")
return False
# 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
logging.info("NOTE: You can edit the 'arch=' line inside the APKBUILD")
if args.action == "build":
logging.info("NOTE: Alternatively, use --arch to build for another"
" architecture ('pmbootstrap build --arch=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
pkgname + "')")
raise RuntimeError("Can't build '" + pkgname + "' for architecture " +
arch)
def get_depends(args, apkbuild):
"""
Alpine's abuild always builds/installs the "depends" and "makedepends"
of a package before building it. We used to only care about "makedepends"
and it's still possible to ignore the depends with --ignore-depends.
:returns: list of dependency pkgnames (eg. ["sdl2", "sdl2_net"])
"""
# Read makedepends and depends
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
ret = list(apkbuild["makedepends"])
if "!check" not in apkbuild["options"]:
ret += apkbuild["checkdepends"]
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
if "ignore_depends" not in args or not args.ignore_depends:
ret += apkbuild["depends"]
ret = sorted(set(ret))
# Don't recurse forever when a package depends on itself (#948)
for pkgname in ([apkbuild["pkgname"]] +
list(apkbuild["subpackages"].keys())):
if pkgname in ret:
logging.verbose(apkbuild["pkgname"] + ": ignoring dependency on"
" itself: " + pkgname)
ret.remove(pkgname)
return ret
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 build_depends(args, apkbuild, arch, strict):
"""
Get and build dependencies with verbose logging messages.
:returns: (depends, depends_built)
"""
# Get dependencies
pkgname = apkbuild["pkgname"]
depends = get_depends(args, apkbuild)
logging.verbose(pkgname + ": build/install dependencies: " +
", ".join(depends))
# --no-depends: check for binary packages
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_built = []
if "no_depends" in args and args.no_depends:
pmb.helpers.repo.update(args, arch)
for depend in depends:
# Ignore conflicting dependencies
if depend.startswith("!"):
continue
# Check if binary package is missing
if not pmb.parse.apkindex.package(args, depend, arch, False):
raise RuntimeError("Missing binary package for dependency '" +
depend + "' of '" + pkgname + "', but"
" pmbootstrap won't build any depends since"
" it was started with --no-depends.")
# Check if binary package is outdated
apkbuild_dep = get_apkbuild(args, depend, arch)
if apkbuild_dep and \
pmb.build.is_necessary(args, arch, apkbuild_dep):
raise RuntimeError(f"Binary package for dependency '{depend}'"
f" of '{pkgname}' is outdated, but"
f" pmbootstrap won't build any depends"
f" since it was started with --no-depends.")
else:
# Build the dependencies
for depend in depends:
if depend.startswith("!"):
continue
if package(args, depend, arch, strict=strict):
depends_built += [depend]
logging.verbose(pkgname + ": build dependencies: done, built: " +
", ".join(depends_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
return (depends, depends_built)
def is_necessary_warn_depends(args, apkbuild, arch, force, depends_built):
"""
Check if a build is necessary, and warn if it is not, but there were
dependencies built.
:returns: True or False
"""
pkgname = apkbuild["pkgname"]
# Check if necessary (this warns about binary version > aport version, so
# call it even in force mode)
ret = pmb.build.is_necessary(args, arch, apkbuild)
if force:
ret = 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
if not ret and len(depends_built):
logging.verbose(f"{pkgname}: depends on rebuilt package(s): "
f" {', '.join(depends_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
logging.verbose(pkgname + ": build necessary: " + str(ret))
return ret
def init_buildenv(args, apkbuild, arch, strict=False, force=False, cross=None,
suffix="native", skip_init_buildenv=False, src=None):
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 all dependencies, check if we need to build at all (otherwise we've
just initialized the build environment for nothing) and then setup the
whole build environment (abuild, gcc, dependencies, cross-compiler).
:param cross: None, "native", "distcc", or "crossdirect"
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
:param skip_init_buildenv: can be set to False to avoid initializing the
build environment. Use this when building
something during initialization of the build
environment (e.g. qemu aarch64 bug workaround)
:param src: override source used to build the package with a local folder
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
:returns: True when the build is necessary (otherwise False)
"""
depends_arch = arch
if cross == "native":
depends_arch = pmb.config.arch_native
# Build dependencies
depends, built = build_depends(args, apkbuild, depends_arch, strict)
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
# Check if build is necessary
if not is_necessary_warn_depends(args, apkbuild, arch, force, 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
return False
# Install and configure abuild, ccache, gcc, dependencies
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
if not skip_init_buildenv:
pmb.build.init(args, suffix)
pmb.build.other.configure_abuild(args, suffix)
pmb.build.other.configure_ccache(args, suffix)
if not strict and "pmb:strict" not in apkbuild["options"] and len(depends):
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
pmb.chroot.apk.install(args, depends, suffix)
if src:
pmb.chroot.apk.install(args, ["rsync"], suffix)
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
# Cross-compiler init
if cross:
pmb.build.init_compiler(args, depends, cross, 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
if cross == "distcc":
pmb.chroot.distccd.start(args, arch)
if cross == "crossdirect":
pmb.chroot.mount_native_into_foreign(args, suffix)
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 True
def get_gcc_version(args, arch):
"""
Get the GCC version for a specific arch from parsing the right APKINDEX.
We feed this to ccache, so it knows the right GCC version, when
cross-compiling in a foreign arch chroot with distcc. See the "using
ccache with other compiler wrappers" section of their man page:
<https://linux.die.net/man/1/ccache>
:returns: a string like "6.4.0-r5"
"""
return pmb.parse.apkindex.package(args, "gcc-" + arch,
pmb.config.arch_native)["version"]
def get_pkgver(original_pkgver, original_source=False, now=None):
"""
Get the original pkgver when using the original source. Otherwise, get the
pkgver with an appended suffix of current date and time. For example:
_p20180218550502
When appending the suffix, an existing suffix (e.g. _git20171231) gets
replaced.
:param original_pkgver: unmodified pkgver from the package's APKBUILD.
:param original_source: the original source is used instead of overriding
it with --src.
:param now: use a specific date instead of current date (for test cases)
"""
if original_source:
return original_pkgver
# Append current date
no_suffix = original_pkgver.split("_", 1)[0]
now = now if now else datetime.datetime.now()
new_suffix = "_p" + now.strftime("%Y%m%d%H%M%S")
return no_suffix + new_suffix
def override_source(args, apkbuild, pkgver, src, suffix="native"):
"""
Mount local source inside chroot and append new functions (prepare() etc.)
to the APKBUILD to make it use the local source.
"""
if not src:
return
# Mount source in chroot
mount_path = "/mnt/pmbootstrap-source-override/"
mount_path_outside = args.work + "/chroot_" + suffix + mount_path
pmb.helpers.mount.bind(args, src, mount_path_outside, umount=True)
# Delete existing append file
append_path = "/tmp/APKBUILD.append"
append_path_outside = args.work + "/chroot_" + suffix + append_path
if os.path.exists(append_path_outside):
pmb.chroot.root(args, ["rm", append_path], suffix)
# Add src path to pkgdesc, cut it off after max length
pkgdesc = ("[" + src + "] " + apkbuild["pkgdesc"])[:127]
# Appended content
append = """
# ** Overrides below appended by pmbootstrap for --src **
pkgver=\"""" + pkgver + """\"
pkgdesc=\"""" + pkgdesc + """\"
_pmb_src_copy="/tmp/pmbootstrap-local-source-copy"
# Empty $source avoids patching in prepare()
_pmb_source_original="$source"
source=""
sha512sums=""
fetch() {
# Update source copy
msg "Copying source from host system: """ + src + """\"
rsync -a --exclude=".git/" --delete --ignore-errors --force \\
\"""" + mount_path + """\" "$_pmb_src_copy" || true
# Link local source files (e.g. kernel config)
mkdir "$srcdir"
local s
for s in $_pmb_source_original; do
is_remote "$s" || ln -sf "$startdir/$s" "$srcdir/"
done
}
unpack() {
ln -sv "$_pmb_src_copy" "$builddir"
}
"""
# Write and log append file
with open(append_path_outside, "w", encoding="utf-8") as handle:
for line in append.split("\n"):
handle.write(line[13:].replace(" " * 4, "\t") + "\n")
pmb.chroot.user(args, ["cat", append_path], suffix)
# Append it to the APKBUILD
apkbuild_path = "/home/pmos/build/APKBUILD"
shell_cmd = ("cat " + apkbuild_path + " " + append_path + " > " +
append_path + "_")
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
pmb.chroot.user(args, ["sh", "-c", shell_cmd], suffix)
pmb.chroot.user(args, ["mv", append_path + "_", apkbuild_path], suffix)
def mount_pmaports(args, destination, suffix="native"):
"""
Mount pmaports.git in chroot.
:param destination: mount point inside the chroot
"""
outside_destination = args.work + "/chroot_" + suffix + destination
pmb.helpers.mount.bind(args, args.aports, outside_destination, umount=True)
def link_to_git_dir(args, suffix):
"""
Make /home/pmos/build/.git point to the .git dir from pmaports.git, with a
symlink so abuild does not fail (#1841).
abuild expects the current working directory to be a subdirectory of a
cloned git repository (e.g. main/openrc from aports.git). If git is
installed, it will try to get the last git commit from that repository, and
place it in the resulting apk (.PKGINFO) as well as use the date from that
commit as SOURCE_DATE_EPOCH (for reproducible builds).
With that symlink, we actually make it use the last git commit from
pmaports.git for SOURCE_DATE_EPOCH and have that in the resulting apk's
.PKGINFO.
"""
# Mount pmaports.git in chroot, in case the user did not use pmbootstrap to
# clone it (e.g. how we build on sourcehut). Do this here and not at the
# initialization of the chroot, because the pmaports dir may not exist yet
# at that point. Use umount=True, so we don't have an old path mounted
# (some tests change the pmaports dir).
destination = "/mnt/pmaports"
mount_pmaports(args, destination, suffix)
# Create .git symlink
pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/build"], suffix)
pmb.chroot.user(args, ["ln", "-sf", destination + "/.git",
"/home/pmos/build/.git"], suffix)
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 run_abuild(args, apkbuild, arch, strict=False, force=False, cross=None,
suffix="native", src=None):
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
"""
Set up all environment variables and construct the abuild command (all
depending on the cross-compiler method and target architecture), copy
the aport to the chroot and execute abuild.
:param cross: None, "native", "distcc", or "crossdirect"
:param src: override source used to build the package with a local folder
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
:returns: (output, cmd, env), output is the destination apk path relative
to the package folder ("x86_64/hello-1-r2.apk"). cmd and env are
used by the test case, and they are the full abuild command and
the environment variables dict generated in this function.
"""
# Sanity check
if cross == "native" and "!tracedeps" not in apkbuild["options"]:
logging.info("WARNING: Option !tracedeps is not set, but we're"
" cross-compiling in the native chroot. This will"
" probably fail!")
# Pretty log message
pkgver = get_pkgver(apkbuild["pkgver"], src is None)
output = (arch + "/" + apkbuild["pkgname"] + "-" + pkgver +
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
"-r" + apkbuild["pkgrel"] + ".apk")
message = "(" + suffix + ") build " + output
if src:
message += " (source: " + src + ")"
logging.info(message)
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
# Environment variables
env = {"CARCH": arch,
"SUDO_APK": "abuild-apk --no-progress"}
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
if cross == "native":
hostspec = pmb.parse.arch.alpine_to_hostspec(arch)
env["CROSS_COMPILE"] = hostspec + "-"
env["CC"] = hostspec + "-gcc"
if cross == "distcc":
env["CCACHE_PREFIX"] = "distcc"
env["CCACHE_PATH"] = f"/usr/lib/arch-bin-masquerade/{arch}:/usr/bin"
env["CCACHE_COMPILERCHECK"] = "string:" + get_gcc_version(args, arch)
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
env["DISTCC_HOSTS"] = "@127.0.0.1:/home/pmos/.distcc-sshd/distccd"
env["DISTCC_SSH"] = ("ssh -o StrictHostKeyChecking=no -p" +
args.port_distccd)
env["DISTCC_BACKOFF_PERIOD"] = "0"
if not args.distcc_fallback:
env["DISTCC_FALLBACK"] = "0"
if args.verbose:
env["DISTCC_VERBOSE"] = "1"
if cross == "crossdirect":
env["PATH"] = ":".join(["/native/usr/lib/crossdirect/" + arch,
pmb.config.chroot_path])
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
if not args.ccache:
env["CCACHE_DISABLE"] = "1"
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 the abuild command
cmd = ["abuild", "-D", "postmarketOS"]
if strict or "pmb:strict" in apkbuild["options"]:
if not strict:
logging.debug(apkbuild["pkgname"] + ": 'pmb:strict' found in"
" options, building in strict mode")
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
cmd += ["-r"] # install depends with abuild
else:
cmd += ["-d"] # do not install depends with abuild
if force:
cmd += ["-f"]
# Copy the aport to the chroot and build it
pmb.build.copy_to_buildpath(args, apkbuild["pkgname"], suffix)
override_source(args, apkbuild, pkgver, src, suffix)
link_to_git_dir(args, suffix)
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
pmb.chroot.user(args, cmd, suffix, "/home/pmos/build", env=env)
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 (output, cmd, env)
def finish(args, apkbuild, arch, output, strict=False, suffix="native"):
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
"""
Various finishing tasks that need to be done after a build.
"""
# Verify output file
channel = pmb.config.pmaports.read_config(args)["channel"]
path = f"{args.work}/packages/{channel}/{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
if not os.path.exists(path):
raise RuntimeError("Package not found after build: " + path)
# Clear APKINDEX cache (we only parse APKINDEX files once per session and
# cache the result for faster dependency resolving, but after we built a
# package we need to parse it again)
2021-11-09 11:54:07 +00:00
pmb.parse.apkindex.clear_cache(f"{args.work}/packages/{channel}"
f"/{arch}/APKINDEX.tar.gz")
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
# Uninstall build dependencies (strict mode)
if strict or "pmb:strict" in 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
logging.info("(" + suffix + ") uninstall build dependencies")
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
pmb.chroot.user(args, ["abuild", "undeps"], suffix, "/home/pmos/build",
env={"SUDO_APK": "abuild-apk --no-progress"})
# If the build depends contain postmarketos-keys or postmarketos-base,
# abuild will have removed the postmarketOS repository key (pma#1230)
pmb.chroot.init_keys(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
def package(args, pkgname, arch=None, force=False, strict=False,
skip_init_buildenv=False, src=None):
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 a package and its dependencies with Alpine Linux' abuild.
If this function is called multiple times on the same pkgname but first
with force=False and then force=True the force argument will be ignored due
to the package cache.
See the skip_already_built() call below.
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
:param pkgname: package name to be built, as specified in the APKBUILD
:param arch: architecture we're building for (default: native)
:param force: always build, even if not necessary
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
:param strict: avoid building with irrelevant dependencies installed by
letting abuild install and uninstall all dependencies.
:param skip_init_buildenv: can be set to False to avoid initializing the
build environment. Use this when building
something during initialization of the build
environment (e.g. qemu aarch64 bug workaround)
:param src: override source used to build the package with a local folder
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
:returns: None if the build was not necessary
output path relative to the packages folder ("armhf/ab-1-r2.apk")
"""
# Once per session is enough
arch = arch or pmb.config.arch_native
2021-11-09 11:54:07 +00:00
if skip_already_built(pkgname, arch):
return
# Only build when APKBUILD exists
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 = get_apkbuild(args, pkgname, arch)
if not apkbuild:
return
# Detect the build environment (skip unnecessary builds)
if not check_build_for_arch(args, pkgname, arch):
return
suffix = pmb.build.autodetect.suffix(apkbuild, 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
cross = pmb.build.autodetect.crosscompile(args, apkbuild, arch, suffix)
if not init_buildenv(args, apkbuild, arch, strict, force, cross, suffix,
skip_init_buildenv, src):
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
# Build and finish up
(output, cmd, env) = run_abuild(args, apkbuild, arch, strict, force, cross,
suffix, src)
finish(args, apkbuild, arch, output, strict, suffix)
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 output