pmb/build/_package.py: create .git symlink (!1831)
Make /home/pmos/build/.git point to the .git dir from pmaports.git, with a symlink so abuild does not fail. 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. Fixes: #1841
This commit is contained in:
parent
46a65e1bb9
commit
16166874a5
|
@ -350,6 +350,36 @@ def override_source(args, apkbuild, pkgver, src, suffix="native"):
|
||||||
pmb.chroot.user(args, ["mv", append_path + "_", apkbuild_path], suffix)
|
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,
|
def run_abuild(args, apkbuild, arch, strict=False, force=False, cross=None,
|
||||||
suffix="native", src=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
|
# Copy the aport to the chroot and build it
|
||||||
pmb.build.copy_to_buildpath(args, apkbuild["pkgname"], suffix)
|
pmb.build.copy_to_buildpath(args, apkbuild["pkgname"], suffix)
|
||||||
override_source(args, apkbuild, pkgver, src, 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)
|
pmb.chroot.user(args, cmd, suffix, "/home/pmos/build", env=env)
|
||||||
return (output, cmd, env)
|
return (output, cmd, env)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
|
import shutil
|
||||||
import filecmp
|
import filecmp
|
||||||
|
|
||||||
# Import from parent directory
|
# Import from parent directory
|
||||||
|
@ -45,7 +46,9 @@ def args(tmpdir, request):
|
||||||
|
|
||||||
def test_aportgen_compare_output(args, tmpdir, monkeypatch):
|
def test_aportgen_compare_output(args, tmpdir, monkeypatch):
|
||||||
# Fake aports folder in 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")
|
os.mkdir(tmpdir + "/cross")
|
||||||
testdata = pmb_src + "/test/testdata/aportgen"
|
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):
|
def test_aportgen_fork_alpine_compare_output(args, tmpdir, monkeypatch):
|
||||||
# Fake aports folder in 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 + "/temp")
|
os.mkdir(tmpdir + "/temp")
|
||||||
testdata = pmb_src + "/test/testdata/aportgen"
|
testdata = pmb_src + "/test/testdata/aportgen"
|
||||||
args.fork_alpine = True
|
args.fork_alpine = True
|
||||||
|
@ -87,7 +92,9 @@ def test_aportgen_fork_alpine_compare_output(args, tmpdir, monkeypatch):
|
||||||
|
|
||||||
def test_aportgen(args, tmpdir):
|
def test_aportgen(args, tmpdir):
|
||||||
# Fake aports folder in 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")
|
os.mkdir(tmpdir + "/cross")
|
||||||
|
|
||||||
# Create aportgen folder -> code path where it still exists
|
# Create aportgen folder -> code path where it still exists
|
||||||
|
|
|
@ -20,6 +20,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
|
import shutil
|
||||||
|
|
||||||
# Import from parent directory
|
# Import from parent directory
|
||||||
sys.path.insert(0, os.path.realpath(
|
sys.path.insert(0, os.path.realpath(
|
||||||
|
@ -40,6 +41,7 @@ def args(tmpdir, request):
|
||||||
|
|
||||||
# Fake aports folder:
|
# Fake aports folder:
|
||||||
tmpdir = str(tmpdir)
|
tmpdir = str(tmpdir)
|
||||||
|
shutil.copytree(args.aports + "/.git", tmpdir + "/.git")
|
||||||
setattr(args, "_aports_real", args.aports)
|
setattr(args, "_aports_real", args.aports)
|
||||||
args.aports = tmpdir
|
args.aports = tmpdir
|
||||||
|
|
||||||
|
|
|
@ -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",
|
shutil.copy(pmb.config.pmb_src + "/test/testdata/build_local_src/APKBUILD",
|
||||||
aport)
|
aport)
|
||||||
|
|
||||||
# aports: Add pmaports.cfg
|
# aports: Add pmaports.cfg, .git
|
||||||
shutil.copy(args.aports + "/pmaports.cfg", aports)
|
shutil.copy(args.aports + "/pmaports.cfg", aports)
|
||||||
|
shutil.copytree(args.aports + "/.git", aports + "/.git")
|
||||||
|
|
||||||
# src: Copy hello-world source files
|
# src: Copy hello-world source files
|
||||||
src = tmpdir + "/src"
|
src = tmpdir + "/src"
|
||||||
|
|
|
@ -24,6 +24,7 @@ This file tests pmb.helper.pkgrel_bump
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Import from parent directory
|
# Import from parent directory
|
||||||
|
@ -57,6 +58,11 @@ def pmbootstrap(args, tmpdir, parameters, zero_exit=True):
|
||||||
aports = tmpdir + "/_aports"
|
aports = tmpdir + "/_aports"
|
||||||
config = tmpdir + "/_pmbootstrap.cfg"
|
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:
|
try:
|
||||||
pmb.helpers.run.user(args, ["./pmbootstrap.py", "--work=" + tmpdir,
|
pmb.helpers.run.user(args, ["./pmbootstrap.py", "--work=" + tmpdir,
|
||||||
"--mirror-pmOS=", "--aports=" + aports,
|
"--mirror-pmOS=", "--aports=" + aports,
|
||||||
|
|
Loading…
Reference in New Issue