Cache which packages have been built (#972)
Fixes #968: Dependency calculation took a long time for `postmarketos-ui-plasma-mobile`
This commit is contained in:
parent
ddabc69b8d
commit
96eaf481d1
|
@ -30,6 +30,23 @@ import pmb.parse
|
||||||
import pmb.parse.arch
|
import pmb.parse.arch
|
||||||
|
|
||||||
|
|
||||||
|
def skip_already_built(args, 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 args.cache["built"]:
|
||||||
|
args.cache["built"][arch] = []
|
||||||
|
if pkgname in args.cache["built"][arch]:
|
||||||
|
logging.verbose(pkgname + ": already checked this session,"
|
||||||
|
" no need to build it or its dependencies")
|
||||||
|
return True
|
||||||
|
args.cache["built"][arch].append(pkgname)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_apkbuild(args, pkgname, arch):
|
def get_apkbuild(args, pkgname, arch):
|
||||||
"""
|
"""
|
||||||
Find the APKBUILD path for pkgname. When there is none, try to find it in
|
Find the APKBUILD path for pkgname. When there is none, try to find it in
|
||||||
|
@ -276,8 +293,12 @@ def package(args, pkgname, arch=None, force=False, buildinfo=False,
|
||||||
:returns: None if the build was not necessary
|
:returns: None if the build was not necessary
|
||||||
output path relative to the packages folder ("armhf/ab-1-r2.apk")
|
output path relative to the packages folder ("armhf/ab-1-r2.apk")
|
||||||
"""
|
"""
|
||||||
# Only build when APKBUILD exists
|
# Once per session is enough
|
||||||
arch = arch or args.arch_native
|
arch = arch or args.arch_native
|
||||||
|
if skip_already_built(args, pkgname, arch):
|
||||||
|
return
|
||||||
|
|
||||||
|
# Only build when APKBUILD exists
|
||||||
apkbuild = get_apkbuild(args, pkgname, arch)
|
apkbuild = get_apkbuild(args, pkgname, arch)
|
||||||
if not apkbuild:
|
if not apkbuild:
|
||||||
return
|
return
|
||||||
|
|
|
@ -347,6 +347,7 @@ def arguments():
|
||||||
"apk_min_version_checked": [],
|
"apk_min_version_checked": [],
|
||||||
"apk_repository_list_updated": [],
|
"apk_repository_list_updated": [],
|
||||||
"aports_files_out_of_sync_with_git": None,
|
"aports_files_out_of_sync_with_git": None,
|
||||||
|
"built": {},
|
||||||
"find_aport": {}})
|
"find_aport": {}})
|
||||||
|
|
||||||
# Add and verify the deviceinfo (only after initialization)
|
# Add and verify the deviceinfo (only after initialization)
|
||||||
|
|
|
@ -75,6 +75,14 @@ def args_patched(monkeypatch, argv):
|
||||||
return pmb.parse.arguments()
|
return pmb.parse.arguments()
|
||||||
|
|
||||||
|
|
||||||
|
def test_skip_already_built(args):
|
||||||
|
func = pmb.build._package.skip_already_built
|
||||||
|
assert args.cache["built"] == {}
|
||||||
|
assert func(args, "test-package", "armhf") is False
|
||||||
|
assert args.cache["built"] == {"armhf": ["test-package"]}
|
||||||
|
assert func(args, "test-package", "armhf") is True
|
||||||
|
|
||||||
|
|
||||||
def test_get_apkbuild(args):
|
def test_get_apkbuild(args):
|
||||||
func = pmb.build._package.get_apkbuild
|
func = pmb.build._package.get_apkbuild
|
||||||
|
|
||||||
|
@ -256,9 +264,11 @@ def test_package(args):
|
||||||
assert pmb.build.package(args, "hello-world", force=True)
|
assert pmb.build.package(args, "hello-world", force=True)
|
||||||
|
|
||||||
# Package exists
|
# Package exists
|
||||||
|
args.cache["built"] = {}
|
||||||
assert pmb.build.package(args, "hello-world") is None
|
assert pmb.build.package(args, "hello-world") is None
|
||||||
|
|
||||||
# Force building again
|
# Force building again
|
||||||
|
args.cache["built"] = {}
|
||||||
assert pmb.build.package(args, "hello-world", force=True)
|
assert pmb.build.package(args, "hello-world", force=True)
|
||||||
|
|
||||||
# Build for another architecture
|
# Build for another architecture
|
||||||
|
@ -293,6 +303,7 @@ def test_build_depends_high_level(args, monkeypatch):
|
||||||
# Remove hello-world
|
# Remove hello-world
|
||||||
pmb.helpers.run.root(args, ["rm", output_hello_outside])
|
pmb.helpers.run.root(args, ["rm", output_hello_outside])
|
||||||
pmb.build.index_repo(args, args.arch_native)
|
pmb.build.index_repo(args, args.arch_native)
|
||||||
|
args.cache["built"] = {}
|
||||||
|
|
||||||
# Ask to build the wrapper. It should not build the wrapper (it exists, not
|
# Ask to build the wrapper. It should not build the wrapper (it exists, not
|
||||||
# using force), but build/update its missing dependency "hello-world"
|
# using force), but build/update its missing dependency "hello-world"
|
||||||
|
|
|
@ -65,6 +65,7 @@ def test_challenge_build(args):
|
||||||
apk_path + ".buildinfo.json"])
|
apk_path + ".buildinfo.json"])
|
||||||
|
|
||||||
# Challenge, output changes into a file
|
# Challenge, output changes into a file
|
||||||
|
args.cache["built"] = {}
|
||||||
setattr(args, "output_repo_changes", args.work + "/chroot_native/tmp/"
|
setattr(args, "output_repo_changes", args.work + "/chroot_native/tmp/"
|
||||||
"test_challenge_build_output.txt")
|
"test_challenge_build_output.txt")
|
||||||
pmb.challenge.build(args, args.work + "/chroot_native/" + temp_path + "/" +
|
pmb.challenge.build(args, args.work + "/chroot_native/" + temp_path + "/" +
|
||||||
|
|
Loading…
Reference in New Issue