CI: common: fixup get_changed_packages() (!1069)

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.
This commit is contained in:
Minecrell 2020-03-14 12:39:32 +01:00 committed by Oliver Smith
parent ae4931816b
commit 0ffb448de4
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -114,20 +114,39 @@ def get_changed_packages_sanity_check(count):
def get_changed_packages(): def get_changed_packages():
files = get_changed_files()
ret = set() ret = set()
for file in files: for file in get_changed_files():
dirname, filename = os.path.split(file)
# Skip files: # Skip files:
# * in the root dir of pmaports (e.g. README.md) # * in the root dir of pmaports (e.g. README.md)
# * path beginning with a dot (e.g. .gitlab-ci/) # * path with a dot (e.g. .gitlab-ci/, device/.shared-patches/)
# * non-existing files (deleted packages) if not dirname or file.startswith(".") or "/." in file:
hidden = file.startswith(".") or "/." in file
if "/" not in file or hidden or not os.path.exists(file):
continue continue
# Add to the ret set (removes duplicated automatically) if filename != "APKBUILD":
# device/testing/device-something/APKBUILD -> device-something # Walk up directories until we (eventually) find the package
ret.add(file.split("/")[-2]) # 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 return ret