From 0ffb448de459a223cc8bb4d804a8899fdab39cd7 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Sat, 14 Mar 2020 12:39:32 +0100 Subject: [PATCH] CI: common: fixup get_changed_packages() (!1069) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the moment the function does not handle all cases correctly. For example, it cannot say which package was changed when a file in a subdirectory of a package was changed. This is used e.g. in device-samsung-golden: device-samsung-golden ├── APKBUILD ├── deviceinfo ├── downstream │   ├── init-usb-hook.sh │   ├── module-config.conf │   └── modules-load.conf └── kwin.sh At the moment, changing a file under "downstream" would attempt building a "downstream" package, instead of device-samsung-golden. Refactor the function a bit to walk up the directory hierarchy, until we find an APKBUILD. --- .gitlab-ci/common.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci/common.py b/.gitlab-ci/common.py index 9400d6ed1..69c149bfb 100755 --- a/.gitlab-ci/common.py +++ b/.gitlab-ci/common.py @@ -114,20 +114,39 @@ def get_changed_packages_sanity_check(count): def get_changed_packages(): - files = get_changed_files() ret = set() - for file in files: + for file in get_changed_files(): + dirname, filename = os.path.split(file) + # Skip files: # * in the root dir of pmaports (e.g. README.md) - # * path beginning with a dot (e.g. .gitlab-ci/) - # * non-existing files (deleted packages) - hidden = file.startswith(".") or "/." in file - if "/" not in file or hidden or not os.path.exists(file): + # * path with a dot (e.g. .gitlab-ci/, device/.shared-patches/) + if not dirname or file.startswith(".") or "/." in file: continue - # Add to the ret set (removes duplicated automatically) - # device/testing/device-something/APKBUILD -> device-something - ret.add(file.split("/")[-2]) + if filename != "APKBUILD": + # Walk up directories until we (eventually) find the package + # the file belongs to (could be in a subdirectory of a package) + while dirname and not os.path.exists(os.path.join(dirname, "APKBUILD")): + dirname = os.path.dirname(dirname) + + # Unable to find APKBUILD the file belong to + if not dirname: + # ... maybe the package was deleted entirely? + if not os.path.exists(file): + continue + + # Weird, file does not belong to any package? + # Here we just warn, there is an extra check + # to make sure that files are organized properly. + print(f"WARNING: Changed file {file} does not belong to any package") + continue + + elif not os.path.exists(file): + continue # APKBUILD was deleted + + ret.add(os.path.basename(dirname)) + return ret