diff --git a/pmb/build/_package.py b/pmb/build/_package.py index 3544dd3d..59ddd526 100644 --- a/pmb/build/_package.py +++ b/pmb/build/_package.py @@ -350,6 +350,36 @@ def override_source(args, apkbuild, pkgver, src, suffix="native"): pmb.chroot.user(args, ["mv", append_path + "_", apkbuild_path], suffix) +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). + inside_destination = "/mnt/pmaports" + outside_destination = args.work + "/chroot_" + suffix + inside_destination + pmb.helpers.mount.bind(args, args.aports, outside_destination, umount=True) + + # Create .git symlink + pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/build"], suffix) + pmb.chroot.user(args, ["ln", "-sf", inside_destination + "/.git", + "/home/pmos/build/.git"], suffix) + + def run_abuild(args, apkbuild, arch, strict=False, force=False, cross=None, suffix="native", src=None): """ @@ -419,6 +449,7 @@ def run_abuild(args, apkbuild, arch, strict=False, force=False, cross=None, # 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) pmb.chroot.user(args, cmd, suffix, "/home/pmos/build", env=env) return (output, cmd, env) diff --git a/test/test_aportgen.py b/test/test_aportgen.py index 10ff9e77..f38a420f 100644 --- a/test/test_aportgen.py +++ b/test/test_aportgen.py @@ -19,6 +19,7 @@ along with pmbootstrap. If not, see . import os import sys import pytest +import shutil import filecmp # Import from parent directory @@ -45,7 +46,9 @@ def args(tmpdir, request): def test_aportgen_compare_output(args, tmpdir, monkeypatch): # Fake aports folder in tmpdir - args.aports = str(tmpdir) + tmpdir = str(tmpdir) + shutil.copytree(args.aports + "/.git", tmpdir + "/.git") + args.aports = tmpdir os.mkdir(tmpdir + "/cross") testdata = pmb_src + "/test/testdata/aportgen" @@ -66,7 +69,9 @@ def test_aportgen_compare_output(args, tmpdir, monkeypatch): def test_aportgen_fork_alpine_compare_output(args, tmpdir, monkeypatch): # Fake aports folder in tmpdir - args.aports = str(tmpdir) + tmpdir = str(tmpdir) + shutil.copytree(args.aports + "/.git", tmpdir + "/.git") + args.aports = tmpdir os.mkdir(tmpdir + "/temp") testdata = pmb_src + "/test/testdata/aportgen" args.fork_alpine = True @@ -87,7 +92,9 @@ def test_aportgen_fork_alpine_compare_output(args, tmpdir, monkeypatch): def test_aportgen(args, tmpdir): # Fake aports folder in tmpdir - args.aports = str(tmpdir) + tmpdir = str(tmpdir) + shutil.copytree(args.aports + "/.git", tmpdir + "/.git") + args.aports = tmpdir os.mkdir(tmpdir + "/cross") # Create aportgen folder -> code path where it still exists diff --git a/test/test_aportgen_device_wizard.py b/test/test_aportgen_device_wizard.py index 1e0366a1..91eaabc1 100644 --- a/test/test_aportgen_device_wizard.py +++ b/test/test_aportgen_device_wizard.py @@ -20,6 +20,7 @@ import logging import os import pytest import sys +import shutil # Import from parent directory sys.path.insert(0, os.path.realpath( @@ -40,6 +41,7 @@ def args(tmpdir, request): # Fake aports folder: tmpdir = str(tmpdir) + shutil.copytree(args.aports + "/.git", tmpdir + "/.git") setattr(args, "_aports_real", args.aports) args.aports = tmpdir diff --git a/test/test_build_package.py b/test/test_build_package.py index 5a228d1c..5dca12b2 100644 --- a/test/test_build_package.py +++ b/test/test_build_package.py @@ -385,8 +385,9 @@ def test_build_local_source_high_level(args, tmpdir): shutil.copy(pmb.config.pmb_src + "/test/testdata/build_local_src/APKBUILD", aport) - # aports: Add pmaports.cfg + # aports: Add pmaports.cfg, .git shutil.copy(args.aports + "/pmaports.cfg", aports) + shutil.copytree(args.aports + "/.git", aports + "/.git") # src: Copy hello-world source files src = tmpdir + "/src" diff --git a/test/test_pkgrel_bump.py b/test/test_pkgrel_bump.py index 4a8213a0..9d01c18a 100644 --- a/test/test_pkgrel_bump.py +++ b/test/test_pkgrel_bump.py @@ -24,6 +24,7 @@ This file tests pmb.helper.pkgrel_bump import glob import os import pytest +import shutil import sys # Import from parent directory @@ -57,6 +58,11 @@ def pmbootstrap(args, tmpdir, parameters, zero_exit=True): aports = tmpdir + "/_aports" config = tmpdir + "/_pmbootstrap.cfg" + # Copy .git dir to fake pmaports + dot_git = tmpdir + "/_aports/.git" + if not os.path.exists(dot_git): + shutil.copytree(args.aports + "/.git", dot_git) + try: pmb.helpers.run.user(args, ["./pmbootstrap.py", "--work=" + tmpdir, "--mirror-pmOS=", "--aports=" + aports,