cross/crossdirect: fakeroot: add helpful error msg (MR 5744)

Alpine's abuild runs build() without fakeroot, and package() with
fakeroot. From the APKBUILD reference page in the Alpine wiki:

> Note: Building in fakeroot will reduce performance for parallel
> builds dramatically. It is for this reason that we split the build
> and package process into two separate functions.

Every now and then we see a package that tries to run a compiler (gcc,
g++, clang, ...) during package() in the APKBUILD. This is a bug in the
APKBUILD / build system of the program we are packaging. All compiling
should be done during build().

Let crossdirect print the following when this happens:

  ============================================================================================
  ERROR: crossdirect was called with: LD_PRELOAD=libfakeroot.so
  This means your package tried to run a compiler during package().
  This is not supported by crossdirect, and usually not a good idea.
  * Try to fix your APKBUILD so it does not run the compiler during package(), only in build()
    * If you're using meson install, try to add '--no-rebuild'
  * If this is not possible, you can work around it by setting options="!pmb:crossdirect"
    (compilation will be slower!)
  ============================================================================================

Instead of:

  ERROR: crossdirect: can't handle LD_PRELOAD: libfakeroot.so
  Please report this at: https://gitlab.com/postmarketOS/pmaports/issues
  As a workaround, you can compile without crossdirect.

In the past I've also tried to add 'strcmp(ldPreload, "libfakeroot.so") == 0'
(pmaports MR 2231), and today I made the same patch. The current code
looks like it would then work by just using libfakeroot.so from the
native chroot, but it does not work. And as mentioned, if we hit this
then we are compiling in package() which is something we should not do
anyway!

Fixes: pmb issue 2039
Related: pma issue 2351, pma MR 5738
This commit is contained in:
Oliver Smith 2024-10-30 21:14:07 +01:00
parent f30cb0d74b
commit c45d7ec0a5
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
2 changed files with 15 additions and 10 deletions

View File

@ -19,8 +19,8 @@
# version is implemented as simple shell wrappers. # version is implemented as simple shell wrappers.
pkgname=crossdirect pkgname=crossdirect
pkgver=5.1.0 pkgver=5.2.0
pkgrel=1 pkgrel=0
pkgdesc="Wrappers to launch native cross compilers in foreign chroots" pkgdesc="Wrappers to launch native cross compilers in foreign chroots"
url="https://postmarketOS.org" url="https://postmarketOS.org"
arch="all" arch="all"
@ -82,7 +82,7 @@ package() {
sha512sums=" sha512sums="
0f4b48f250425dc57f63955fc8b38477d23db793bee367c3fbe03c3d2a559ba576434d07518310db4cae9d90d501af4051b80038b10fae94b980e537fc9374ad cargo.sh 0f4b48f250425dc57f63955fc8b38477d23db793bee367c3fbe03c3d2a559ba576434d07518310db4cae9d90d501af4051b80038b10fae94b980e537fc9374ad cargo.sh
a1af3d2876dc05bb840e4bfb8b6e1c1dcf5b952375a6644dcb9cf659d82ec8bfc4be5d813064057fe9626104a10907ae7072a9d5fd7ac40f3b87e90dbf535eaf crossdirect.c b2e602b7fc95ed403d29f0d754879d5f773c39ee33e726bb10cff17b3c088406dac84f2ca6d8ad563c64370007d98af805d6ee9cd4a06fe3d4c61c0cb90c5c0c crossdirect.c
de2aa6929bbff5db9132673e667f4525b333d062cb1f7a0597dd924de9e5c7215a9f8e2e6263b6fb5ace06f2c4b64f4ebfd0ede9b78add07c2cd08ec8613e98f rustc.sh de2aa6929bbff5db9132673e667f4525b333d062cb1f7a0597dd924de9e5c7215a9f8e2e6263b6fb5ace06f2c4b64f4ebfd0ede9b78add07c2cd08ec8613e98f rustc.sh
ea9bf8db3810d03d0a7395057f3d6e57f7127d87c55deaedc171c255288f5f3cc6fbcc680a5a1b92786cf573875d5dc22521173799fe2639acc97d0715ff905b rust-qemu-linker.sh ea9bf8db3810d03d0a7395057f3d6e57f7127d87c55deaedc171c255288f5f3cc6fbcc680a5a1b92786cf573875d5dc22521173799fe2639acc97d0715ff905b rust-qemu-linker.sh
" "

View File

@ -44,8 +44,7 @@
void exit_userfriendly() void exit_userfriendly()
{ {
fprintf(stderr, "Please report this at: https://gitlab.postmarketos.org/postmarketOS/pmaports/issues\n"); fprintf(stderr, "Please report this at: https://gitlab.postmarketos.org/postmarketOS/pmaports/issues\n");
fprintf(stderr, "As a workaround, you can compile without crossdirect.\n"); fprintf(stderr, "As a workaround, you can compile without crossdirect with options=\"!pmb:crossdirect\".\n");
fprintf(stderr, "See 'pmbootstrap -h' for related options.\n");
exit(1); exit(1);
} }
@ -118,11 +117,17 @@ int main(int argc, char **argv)
NULL }; NULL };
char *ldPreload = getenv("LD_PRELOAD"); char *ldPreload = getenv("LD_PRELOAD");
if (ldPreload) { if (ldPreload) {
if (strcmp(ldPreload, "/usr/lib/libfakeroot.so") == 0) { if (strstr(ldPreload, "libfakeroot.so")) {
env[0] = "LD_PRELOAD=/native/usr/lib/libfakeroot.so"; fprintf(stderr, "============================================================================================\n");
} else { fprintf(stderr, "ERROR: crossdirect was called with: LD_PRELOAD=%s\n", ldPreload);
fprintf(stderr, "ERROR: crossdirect: can't handle LD_PRELOAD: %s\n", ldPreload); fprintf(stderr, "This means your package tried to run a compiler during package().\n");
exit_userfriendly(); fprintf(stderr, "This is not supported by crossdirect, and usually not a good idea.\n");
fprintf(stderr, "* Try to fix your APKBUILD so it does not run the compiler during package(), only in build()\n");
fprintf(stderr, " * If you're using 'meson install', try to add '--no-rebuild'\n");
fprintf(stderr, "* If this is not possible, you can work around it by setting options=\"!pmb:crossdirect\"\n");
fprintf(stderr, " (compilation will be slower!)\n");
fprintf(stderr, "============================================================================================\n");
exit(1);
} }
} }