diff options
Diffstat (limited to 'meta/lib/oeqa/sdk/cases/meson.py')
-rw-r--r-- | meta/lib/oeqa/sdk/cases/meson.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/meta/lib/oeqa/sdk/cases/meson.py b/meta/lib/oeqa/sdk/cases/meson.py new file mode 100644 index 0000000000..a809ca3a53 --- /dev/null +++ b/meta/lib/oeqa/sdk/cases/meson.py | |||
@@ -0,0 +1,72 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | |||
7 | import json | ||
8 | import os | ||
9 | import subprocess | ||
10 | import tempfile | ||
11 | import unittest | ||
12 | |||
13 | from oeqa.sdk.case import OESDKTestCase | ||
14 | from oeqa.sdkext.context import OESDKExtTestContext | ||
15 | from oeqa.utils.subprocesstweak import errors_have_output | ||
16 | errors_have_output() | ||
17 | |||
18 | class MesonTestBase(OESDKTestCase): | ||
19 | def setUp(self): | ||
20 | libc = self.td.get("TCLIBC") | ||
21 | if libc in [ 'newlib' ]: | ||
22 | raise unittest.SkipTest("MesonTest class: SDK doesn't contain a supported C library") | ||
23 | |||
24 | if isinstance(self.tc, OESDKExtTestContext): | ||
25 | self.skipTest(f"{self.id()} does not support eSDK (https://bugzilla.yoctoproject.org/show_bug.cgi?id=15854)") | ||
26 | |||
27 | self.ensure_host_package("meson") | ||
28 | self.ensure_host_package("pkgconfig") | ||
29 | |||
30 | def build_meson(self, sourcedir, builddir, installdir=None, options=""): | ||
31 | """ | ||
32 | Given a source tree in sourcedir, configure it to build in builddir with | ||
33 | the specified options, and if installdir is set also install. | ||
34 | """ | ||
35 | log = self._run(f"meson setup --warnlevel 1 {builddir} {sourcedir} {options}") | ||
36 | |||
37 | # Check that Meson thinks we're doing a cross build and not a native | ||
38 | self.assertIn("Build type: cross build", log) | ||
39 | |||
40 | # Check that the cross-compiler used is the one we set. | ||
41 | data = json.loads(self._run(f"meson introspect --compilers {builddir}")) | ||
42 | self.assertIn(self.td.get("CC").split()[0], data["host"]["c"]["exelist"]) | ||
43 | |||
44 | # Check that the target architectures was set correctly. | ||
45 | data = json.loads(self._run(f"meson introspect --machines {builddir}")) | ||
46 | self.assertEqual(data["host"]["cpu"], self.td["HOST_ARCH"]) | ||
47 | |||
48 | self._run(f"meson compile -C {builddir} -v") | ||
49 | |||
50 | if installdir: | ||
51 | self._run(f"meson install -C {builddir} --destdir {installdir}") | ||
52 | |||
53 | class MesonTest(MesonTestBase): | ||
54 | """ | ||
55 | Test that Meson builds correctly. | ||
56 | """ | ||
57 | |||
58 | def test_epoxy(self): | ||
59 | with tempfile.TemporaryDirectory(prefix="epoxy", dir=self.tc.sdk_dir) as testdir: | ||
60 | tarball = self.fetch(testdir, self.td["DL_DIR"], "https://github.com/anholt/libepoxy/releases/download/1.5.3/libepoxy-1.5.3.tar.xz") | ||
61 | |||
62 | sourcedir = os.path.join(testdir, "libepoxy-1.5.3") | ||
63 | builddir = os.path.join(testdir, "build") | ||
64 | installdir = os.path.join(testdir, "install") | ||
65 | |||
66 | subprocess.check_output(["tar", "xf", tarball, "-C", testdir], stderr=subprocess.STDOUT) | ||
67 | self.assertTrue(os.path.isdir(sourcedir)) | ||
68 | |||
69 | os.makedirs(builddir) | ||
70 | self.build_meson(sourcedir, builddir, installdir, "-Degl=no -Dglx=no -Dx11=false") | ||
71 | self.assertTrue(os.path.isdir(installdir)) | ||
72 | self.check_elf(os.path.join(installdir, "usr", "local", "lib", "libepoxy.so")) | ||