2020-03-14 18:51:22 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import glob
|
|
|
|
import os
|
2020-05-19 19:59:49 +00:00
|
|
|
import stat
|
2020-03-14 18:51:22 +00:00
|
|
|
|
|
|
|
expected_directories = [
|
|
|
|
"cross",
|
2020-04-04 10:27:43 +00:00
|
|
|
"device/community",
|
|
|
|
"device/main",
|
2020-03-14 18:51:22 +00:00
|
|
|
"device/testing",
|
2021-01-30 16:02:32 +00:00
|
|
|
"device/unmaintained",
|
2020-03-14 18:51:22 +00:00
|
|
|
"main",
|
|
|
|
"modem",
|
2021-01-13 03:38:11 +00:00
|
|
|
"non-free",
|
2020-08-02 13:25:43 +00:00
|
|
|
"sxmo",
|
2020-03-14 18:51:22 +00:00
|
|
|
"temp",
|
|
|
|
]
|
|
|
|
|
2020-03-21 21:31:57 +00:00
|
|
|
|
2020-03-14 18:51:22 +00:00
|
|
|
# pmbootstrap allows placing APKBUILDs in arbitrarily nested directories.
|
|
|
|
# This test makes sure all of them are in one of the expected locations.
|
|
|
|
def test_directories():
|
|
|
|
apkbuilds = set(glob.iglob("**/APKBUILD", recursive=True))
|
|
|
|
expected = set(f for d in expected_directories for f in glob.iglob(d + "/*/APKBUILD"))
|
|
|
|
assert apkbuilds == expected, "Found APKBUILD in unexpected directory. " \
|
2020-07-07 13:58:58 +00:00
|
|
|
"Note that we moved firmware/* to device/{main,community,testing}/*."
|
2020-03-14 18:51:22 +00:00
|
|
|
|
2020-03-21 21:31:57 +00:00
|
|
|
|
2020-05-19 19:59:49 +00:00
|
|
|
# Ensure no file in pmaports are executable.
|
|
|
|
# see https://gitlab.com/postmarketOS/pmaports/-/issues/593.
|
|
|
|
def test_executable_files():
|
|
|
|
for file in glob.iglob("**/*", recursive=True):
|
|
|
|
if os.path.isdir(file) or os.path.islink(file):
|
|
|
|
continue
|
|
|
|
# still check other less common inode types
|
|
|
|
permissions = os.stat(file).st_mode
|
|
|
|
executable_bits = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
|
|
|
if permissions & executable_bits != 0:
|
|
|
|
raise RuntimeError(f"\"{file}\" is executable. Files in pmaports" +
|
|
|
|
" should not be executables. post-* files" +
|
|
|
|
" don't need to be executable and executables" +
|
|
|
|
" should be installed using `install -D" +
|
|
|
|
"m0755` or a variation thereof.")
|
|
|
|
|
|
|
|
|
2020-03-14 18:51:22 +00:00
|
|
|
# Make sure files are either:
|
|
|
|
# - in root directory (README.md)
|
|
|
|
# - hidden (.gitlab-ci/, device/.shared-patches/)
|
|
|
|
# - or belong to a package (below a directory with APKBUILD)
|
|
|
|
def test_files_belong_to_package():
|
|
|
|
# Walk directories and set package_dir when we find an APKBUILD
|
|
|
|
# This allows matching files in subdirectories to the package directory.
|
|
|
|
package_dir = None
|
|
|
|
for dirpath, dirs, files in os.walk("."):
|
|
|
|
# Skip "hidden" directories
|
|
|
|
dirs[:] = [d for d in dirs if not d.startswith(".")]
|
|
|
|
# Ignore files in root directory
|
|
|
|
if dirpath == '.':
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Switched to another directory?
|
|
|
|
if package_dir and not dirpath.startswith(package_dir + os.sep):
|
|
|
|
package_dir = None
|
|
|
|
|
|
|
|
if 'APKBUILD' in files:
|
|
|
|
assert not package_dir, f"Nested packages: {package_dir} and {dirpath} " \
|
|
|
|
"both contain an APKBUILD"
|
|
|
|
package_dir = dirpath
|
|
|
|
|
|
|
|
assert not files or package_dir, "Found files that do not belong to any package: " \
|
2020-03-21 21:31:57 +00:00
|
|
|
f"{dirpath}/{files}"
|