diff --git a/asu/build.py b/asu/build.py index 96c44681..0cedee8b 100644 --- a/asu/build.py +++ b/asu/build.py @@ -9,8 +9,12 @@ import requests from rq import get_current_job -from .common import (fingerprint_pubkey_usign, get_file_hash, - get_packages_hash, verify_usign) +from .common import ( + fingerprint_pubkey_usign, + get_file_hash, + get_packages_hash, + verify_usign, +) log = logging.getLogger("rq.worker") log.setLevel(logging.DEBUG) @@ -338,6 +342,24 @@ def download_file(filename: str, dest: str = None): if "is too big" in image_build.stderr: report_error("Selected packages exceed device storage") + kernel_build_dir_run = subprocess.run( + ["make", "val.KERNEL_BUILD_DIR"], + text=True, + cwd=cache_workdir, + capture_output=True, + ) + + if kernel_build_dir_run.returncode: + report_error("Couldn't determine KERNEL_BUILD_DIR") + + kernel_build_dir_tmp = Path(kernel_build_dir_run.stdout.strip()) / "tmp" + + if kernel_build_dir_tmp.exists(): + log.info("Removing KDIR_TMP at %s", kernel_build_dir_tmp) + rmtree(kernel_build_dir_tmp) + else: + log.warning("KDIR_TMP missing at %s", kernel_build_dir_tmp) + json_file = Path(req["store_path"] / bin_dir / "profiles.json") if not json_file.is_file(): diff --git a/tests/test_api.py b/tests/test_api.py index ea191313..2f8c0b89 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -518,3 +518,24 @@ def test_api_build_package_to_replace(client, upstream): ) assert response.status == "200 OK" assert response.json.get("request_hash") == "8dd81d51057d322b46aa3739ccf4a8a6" + + +def test_api_build_cleanup(app, upstream): + client = app.test_client() + response = client.post( + "/api/v1/build", + json=dict( + version="TESTVERSION", + target="testtarget/testsubtarget", + profile="testprofile", + packages=["test1", "test2"], + filesystem="ext4", + ), + ) + assert response.status == "200 OK" + assert not ( + app.config["CACHE_PATH"] + / "cache/TESTVERSION/testtarget/testsubtarget" + / "pseudo_kernel_build_dir/tmp/" + / "fake_trash" + ).exists() diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz index 3277025a..254ae645 100644 Binary files a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz and b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz differ diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile index 3cd7d9e1..625d4f9e 100644 --- a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile +++ b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/Makefile @@ -9,3 +9,6 @@ manifest: info: @cat ./openwrt-testtarget-testsubtarget-testprofile.info + +val.KERNEL_BUILD_DIR: + @echo "$$(pwd)/pseudo_kernel_build_dir/" diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/pseudo_kernel_build_dir/tmp/fake_trash b/tests/upstream/snapshots/targets/testtarget/testsubtarget/openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64/pseudo_kernel_build_dir/tmp/fake_trash new file mode 100644 index 00000000..e69de29b diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums index b9edb4d8..35fe96fb 100644 --- a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums +++ b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums @@ -1 +1 @@ -f7a57262cde30d84db51d6db5b1eee16f5c0525e67f01dcbe10a9693e3c88fde *openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz +4e645577d934129a65d0f79cf55d90e1199f5ab90ab27803cefae8badc868599 *openwrt-imagebuilder-testtarget-testsubtarget.Linux-x86_64.tar.xz diff --git a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig index 9edfbf77..6999e851 100644 --- a/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig +++ b/tests/upstream/snapshots/targets/testtarget/testsubtarget/sha256sums.sig @@ -1,2 +1,2 @@ untrusted comment: verify with testkey.pub -RWRqylWEtrAZQ/BrgCkjQaOak7bVi7CWfwKbK/rKK39w4e0l7jL+D23xAZZXS3Qb/x6jwulK3lbuCU61etNGaLE2KxWfk1hY4QM= +RWRqylWEtrAZQwwqVGXn0U/Q3nnrboIdIVK2aW7Q8JMN3pmCzHa8o5MppWUqMhxh/h2Dc/3WUjVtWgvfDGrR0tJJ/Wauy9r7QwM=