2022-01-02 21:38:21 +00:00
|
|
|
# Copyright 2022 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2018-02-24 21:49:10 +00:00
|
|
|
import pytest
|
|
|
|
import sys
|
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
import pmb_test
|
|
|
|
import pmb_test.const
|
2018-02-24 21:49:10 +00:00
|
|
|
import pmb.parse._apkbuild
|
|
|
|
|
|
|
|
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def args(tmpdir, request):
|
|
|
|
import pmb.parse
|
|
|
|
sys.argv = ["pmbootstrap.py", "init"]
|
|
|
|
args = pmb.parse.arguments()
|
|
|
|
args.log = args.work + "/log_testsuite.txt"
|
|
|
|
pmb.helpers.logging.init(args)
|
2021-09-20 10:00:13 +00:00
|
|
|
request.addfinalizer(pmb.helpers.logging.logfd.close)
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
2021-11-09 11:54:07 +00:00
|
|
|
def test_subpackages():
|
2020-02-20 19:14:38 +00:00
|
|
|
testdata = pmb_test.const.testdata
|
2020-01-27 23:23:09 +00:00
|
|
|
path = testdata + "/apkbuild/APKBUILD.subpackages"
|
2021-11-09 11:52:10 +00:00
|
|
|
apkbuild = pmb.parse.apkbuild(path, check_pkgname=False)
|
2020-01-27 23:23:09 +00:00
|
|
|
|
|
|
|
subpkg = apkbuild["subpackages"]["simple"]
|
|
|
|
assert subpkg["pkgdesc"] == ""
|
|
|
|
# Inherited from parent package
|
|
|
|
assert subpkg["depends"] == ["postmarketos-base"]
|
|
|
|
|
|
|
|
subpkg = apkbuild["subpackages"]["custom"]
|
|
|
|
assert subpkg["pkgdesc"] == "This is one of the custom subpackages"
|
|
|
|
assert subpkg["depends"] == ["postmarketos-base", "glibc"]
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
# Successful extraction
|
2020-02-26 11:13:26 +00:00
|
|
|
path = (testdata + "/init_questions_device/aports/device/testing/"
|
2018-02-24 21:49:10 +00:00
|
|
|
"device-nonfree-firmware/APKBUILD")
|
2021-11-09 11:52:10 +00:00
|
|
|
apkbuild = pmb.parse.apkbuild(path)
|
2021-01-31 18:16:56 +00:00
|
|
|
subpkg = (apkbuild["subpackages"]
|
|
|
|
["device-nonfree-firmware-nonfree-firmware"])
|
2020-01-27 23:23:09 +00:00
|
|
|
assert subpkg["pkgdesc"] == "firmware description"
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
# Can't find the pkgdesc in the function
|
|
|
|
path = testdata + "/apkbuild/APKBUILD.missing-pkgdesc-in-subpackage"
|
2021-11-09 11:52:10 +00:00
|
|
|
apkbuild = pmb.parse.apkbuild(path, check_pkgname=False)
|
2021-01-31 18:16:56 +00:00
|
|
|
subpkg = (apkbuild["subpackages"]
|
|
|
|
["missing-pkgdesc-in-subpackage-subpackage"])
|
2020-01-27 23:23:09 +00:00
|
|
|
assert subpkg["pkgdesc"] == ""
|
|
|
|
|
|
|
|
# Can't find the function
|
|
|
|
assert apkbuild["subpackages"]["invalid-function"] is None
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_kernels(args):
|
|
|
|
# Kernel hardcoded in depends
|
2020-02-20 19:14:38 +00:00
|
|
|
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
func = pmb.parse._apkbuild.kernels
|
|
|
|
device = "lg-mako"
|
|
|
|
assert func(args, device) is None
|
|
|
|
|
|
|
|
# Upstream and downstream kernel
|
|
|
|
device = "sony-amami"
|
|
|
|
ret = {"downstream": "Downstream description",
|
|
|
|
"mainline": "Mainline description"}
|
|
|
|
assert func(args, device) == ret
|
2019-06-26 18:24:24 +00:00
|
|
|
|
2020-01-18 09:53:46 +00:00
|
|
|
# Long kernel name (e.g. two different mainline kernels)
|
|
|
|
device = "wileyfox-crackling"
|
|
|
|
ret = {"mainline": "Mainline kernel (no modem)",
|
|
|
|
"mainline-modem": "Mainline kernel (with modem)",
|
|
|
|
"downstream": "Downstream kernel"}
|
|
|
|
assert func(args, device) == ret
|
|
|
|
|
2019-06-26 18:24:24 +00:00
|
|
|
|
2021-11-09 11:54:07 +00:00
|
|
|
def test_depends_in_depends():
|
2020-02-20 19:14:38 +00:00
|
|
|
path = pmb_test.const.testdata + "/apkbuild/APKBUILD.depends-in-depends"
|
2021-11-09 11:52:10 +00:00
|
|
|
apkbuild = pmb.parse.apkbuild(path, check_pkgname=False)
|
2019-06-26 18:24:24 +00:00
|
|
|
assert apkbuild["depends"] == ["first", "second", "third"]
|
2019-11-30 10:24:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_attributes():
|
|
|
|
# Convenience function for calling the function with a block of text
|
|
|
|
def func(attribute, block):
|
|
|
|
lines = block.split("\n")
|
|
|
|
for i in range(0, len(lines)):
|
|
|
|
lines[i] += "\n"
|
|
|
|
i = 0
|
|
|
|
path = "(testcase in " + __file__ + ")"
|
|
|
|
print("=== parsing attribute '" + attribute + "' in test block:")
|
|
|
|
print(block)
|
|
|
|
print("===")
|
|
|
|
return pmb.parse._apkbuild.parse_attribute(attribute, lines, i, path)
|
|
|
|
|
|
|
|
assert func("depends", "pkgname='test'") == (False, None, 0)
|
|
|
|
|
|
|
|
assert func("pkgname", 'pkgname="test"') == (True, "test", 0)
|
|
|
|
|
|
|
|
assert func("pkgname", "pkgname='test'") == (True, "test", 0)
|
|
|
|
|
|
|
|
assert func("pkgname", "pkgname=test") == (True, "test", 0)
|
|
|
|
|
|
|
|
assert func("pkgname", 'pkgname="test\n"') == (True, "test", 1)
|
|
|
|
|
|
|
|
assert func("pkgname", 'pkgname="\ntest\n"') == (True, "test", 2)
|
|
|
|
|
|
|
|
assert func("pkgname", 'pkgname="test" # random comment\npkgrel=3') == \
|
|
|
|
(True, "test", 0)
|
|
|
|
|
2021-12-12 12:44:43 +00:00
|
|
|
assert func("pkgver", 'pkgver=2.37 # random comment\npkgrel=3') == \
|
|
|
|
(True, "2.37", 0)
|
|
|
|
|
2019-11-30 10:24:35 +00:00
|
|
|
assert func("depends", "depends='\nfirst\nsecond\nthird\n'#") == \
|
|
|
|
(True, "first second third", 4)
|
|
|
|
|
|
|
|
assert func("depends", 'depends="\nfirst\n\tsecond third"') == \
|
|
|
|
(True, "first second third", 2)
|
|
|
|
|
|
|
|
assert func("depends", 'depends=') == (True, "", 0)
|
|
|
|
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
2020-01-06 16:53:23 +00:00
|
|
|
func("depends", 'depends="\nmissing\nend\nquote\nsign')
|
2019-11-30 10:24:35 +00:00
|
|
|
assert str(e.value).startswith("Can't find closing")
|
|
|
|
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func("depends", 'depends="')
|
|
|
|
assert str(e.value).startswith("Can't find closing")
|
2020-01-06 16:55:26 +00:00
|
|
|
|
|
|
|
|
2021-11-09 11:54:07 +00:00
|
|
|
def test_variable_replacements():
|
2020-02-20 19:14:38 +00:00
|
|
|
path = pmb_test.const.testdata + "/apkbuild/APKBUILD.variable-replacements"
|
2021-11-09 11:52:10 +00:00
|
|
|
apkbuild = pmb.parse.apkbuild(path, check_pkgname=False)
|
2020-01-27 23:23:09 +00:00
|
|
|
assert apkbuild["pkgdesc"] == "this should not affect variable replacement"
|
2020-01-06 16:55:26 +00:00
|
|
|
assert apkbuild["url"] == "replacements variable string-replacements"
|
2020-01-27 23:23:09 +00:00
|
|
|
assert list(apkbuild["subpackages"].keys()) == ["replacements", "test"]
|
|
|
|
|
|
|
|
assert apkbuild["subpackages"]["replacements"] is None
|
|
|
|
test_subpkg = apkbuild["subpackages"]["test"]
|
2021-01-31 18:16:56 +00:00
|
|
|
assert test_subpkg["pkgdesc"] == ("this should not affect variable "
|
|
|
|
"replacement")
|
2021-01-30 12:19:22 +00:00
|
|
|
|
|
|
|
|
2021-11-09 11:54:07 +00:00
|
|
|
def test_parse_maintainers():
|
2021-01-30 12:19:22 +00:00
|
|
|
path = pmb_test.const.testdata + "/apkbuild/APKBUILD.lint"
|
|
|
|
maintainers = [
|
|
|
|
"Oliver Smith <ollieparanoid@postmarketos.org>",
|
|
|
|
"Hello World <hello@world>"
|
|
|
|
]
|
|
|
|
|
|
|
|
assert pmb.parse._apkbuild.maintainers(path) == maintainers
|
2021-01-30 12:21:12 +00:00
|
|
|
|
|
|
|
|
2021-11-09 11:54:07 +00:00
|
|
|
def test_parse_unmaintained():
|
2021-01-30 12:21:12 +00:00
|
|
|
path = (f"{pmb_test.const.testdata}/apkbuild"
|
|
|
|
"/APKBUILD.missing-pkgdesc-in-subpackage")
|
|
|
|
assert pmb.parse._apkbuild.unmaintained(path) == "This is broken!"
|