pmb.build.other: do not copy leftover abuild dirs

Running abuild on the host directly creates directories in the
aport where it gets built. Interrupting abuild results in those
working-dirs not getting deleted.
We don't want to copy those entries to our builder.

It's only really noticeable if pmbootstrap tries to copy a broken
symlink in src/ and thus fails.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221207205201.22139-1-jane400@bingo-ev.de%3E
This commit is contained in:
Jane Rachinger 2022-12-07 21:52:01 +01:00 committed by Oliver Smith
parent 9d93d34b65
commit 42feaf0d49
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
2 changed files with 61 additions and 1 deletions

View File

@ -28,7 +28,16 @@ def copy_to_buildpath(args, package, suffix="native"):
pmb.chroot.root(args, ["rm", "-rf", "/home/pmos/build"], suffix)
# Copy aport contents with resolved symlinks
pmb.helpers.run.root(args, ["cp", "-rL", aport + "/", build])
pmb.helpers.run.root(args, ["mkdir", "-p", build])
for entry in os.listdir(aport):
# Don't copy those dirs, as those have probably been generated by running `abuild`
# on the host system directly and not cleaning up after itself.
# Those dirs might contain broken symlinks and cp fails resolving them.
if entry in ["src", "pkg"]:
logging.warn(f"WARNING: Not copying {entry}, looks like a leftover from abuild")
continue
pmb.helpers.run.root(args, ["cp", "-rL", f"{aport}/{entry}", f"{build}/{entry}"])
pmb.chroot.root(args, ["chown", "-R", "pmos:pmos",
"/home/pmos/build"], suffix)

View File

@ -436,3 +436,54 @@ def test_build_local_source_high_level(args, tmpdir):
# Clean up: update index, delete temp folder
pmb.build.index_repo(args, pmb.config.arch_native)
pmb.helpers.run.root(args, ["rm", "-r", tmpdir])
def test_build_abuild_leftovers(args, tmpdir):
"""
Test building a package with having abuild leftovers, that will error if
copied:
pmbootstrap build hello-world
"""
# aports: Add deviceinfo (required by pmbootstrap to start)
tmpdir = str(tmpdir)
aports = f"{tmpdir}/aports"
aport = f"{aports}/device/testing/device-{args.device}"
os.makedirs(aport)
path_original = pmb.helpers.pmaports.find(args, f"device-{args.device}")
shutil.copy(f"{path_original}/deviceinfo", aport)
# aports: Add modified hello-world aport (source="", uses $builddir)
test_aport = "main/hello-world"
aport = f"{aports}/{test_aport}"
shutil.copytree(f"{args.aports}/{test_aport}", aport)
# aports: Add pmaports.cfg, .git
shutil.copy(f"{args.aports}/pmaports.cfg", aports)
shutil.copytree(f"{args.aports}/.git", f"{aports}/.git")
# aport: create abuild dir with broken symlink
src = f"{aport}/src"
os.makedirs(src)
os.symlink("/var/cache/distfiles/non-existent.tar.gz",
f"{src}/broken-tarball-symlink.tar.gz")
# Delete all hello-world packages
channel = pmb.config.pmaports.read_config(args)["channel"]
pattern = f"{args.work}/packages/{channel}/*/hello-world-*_p*.apk"
for path in glob.glob(pattern):
pmb.helpers.run.root(args, ["rm", path])
assert len(glob.glob(pattern)) == 0
# Build hello-world package
pmb.helpers.run.user(args, [f"{pmb.config.pmb_src}/pmbootstrap.py",
"--aports", aports, "build", "--src", src,
"hello-world", "--arch", pmb.config.arch_native])
# Verify that the package has been built and delete it
paths = glob.glob(pattern)
assert len(paths) == 1
pmb.helpers.run.root(args, ["rm", paths[0]])
# Clean up: update index, delete temp folder
pmb.build.index_repo(args, pmb.config.arch_native)
pmb.helpers.run.root(args, ["rm", "-r", tmpdir])