Skip to contentSkip to conversation

toolchain-scripts.bbclass: adjust toolchain_create_tree_env_script to better replicate (e)SDK

PATCH New Alexander Kanavin 1 participant 6 messages Jul 22, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 toolchain-scripts.bbclass: adjust toolchain_create_tree_env_script to better replicate (e)SDK

Specifically:
1. Place the environment setup file into $B and not into $TMPDIR,
so that the recipe using the class can itself better decide what to do with the file.

2. Use global, unified sysroots (provided through build-sysroots recipe) and not recipe-specific ones, as this allows flexible on-the-fly management of what libraries are available to build applications, without having to modify any recipes, similar to eSDK 'extensible' part.

This also requires adjustment of the sstate sametune_samegsigs test, as meta-ide-support becomes dependent on $MACHINE (unified sysroots have it in their paths) and needs to be excluded from the test.

3. Add a few missing settings that have been added to SDK environment files.

4. Add a snippet to the environment setup file that also runs the relocation scripts. In regular SDKs this is executed by the SDK installer, in direct SDK we can do it when setting up the environment.

---
 meta/classes/toolchain-scripts.bbclass      | 40 ++++++++++++++++-----
 meta/lib/oeqa/selftest/cases/sstatetests.py |  2 +-
 2 files changed, 32 insertions(+), 10 deletions(-)
meta/classes/toolchain-scripts.bbclass +31 -9
index 1d7c703748..16f1e17607 100644
@@ -63,24 +63,46 @@ toolchain_create_sdk_env_script () {
 	toolchain_shared_env_script
 }
 
-# This function creates an environment-setup-script in the TMPDIR which enables
+# This function creates an environment-setup-script in B which enables
 # a OE-core IDE to integrate with the build tree
 # Caller must ensure CONFIG_SITE is setup
 toolchain_create_tree_env_script () {
-	script=${TMPDIR}/environment-setup-${REAL_MULTIMACH_TARGET_SYS}
+	script=${B}/environment-setup-${REAL_MULTIMACH_TARGET_SYS}
 	rm -f $script
 	touch $script
+	echo 'standalone_sysroot_target="${STAGING_DIR}/${MACHINE}"' >> $script
+	echo 'standalone_sysroot_native="${STAGING_DIR}/${BUILD_ARCH}"' >> $script
 	echo 'orig=`pwd`; cd ${COREBASE}; . ./oe-init-build-env ${TOPDIR}; cd $orig' >> $script
-	echo 'export PATH=${STAGING_DIR_NATIVE}/usr/bin:${STAGING_BINDIR_TOOLCHAIN}:$PATH' >> $script
-	echo 'export PKG_CONFIG_SYSROOT_DIR=${PKG_CONFIG_SYSROOT_DIR}' >> $script
-	echo 'export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}' >> $script
+	echo 'export PATH=$standalone_sysroot_native/${bindir_native}:$standalone_sysroot_native/${bindir_native}/${TARGET_SYS}:$PATH' >> $script
+	echo 'export PKG_CONFIG_SYSROOT_DIR=$standalone_sysroot_target' >> $script
+	echo 'export PKG_CONFIG_PATH=$standalone_sysroot_target'"$libdir"'/pkgconfig:$standalone_sysroot_target'"$prefix"'/share/pkgconfig' >> $script
 	echo 'export CONFIG_SITE="${CONFIG_SITE}"' >> $script
-	echo 'export SDKTARGETSYSROOT=${STAGING_DIR_TARGET}' >> $script
-	echo 'export OECORE_NATIVE_SYSROOT="${STAGING_DIR_NATIVE}"' >> $script
-	echo 'export OECORE_TARGET_SYSROOT="${STAGING_DIR_TARGET}"' >> $script
-	echo 'export OECORE_ACLOCAL_OPTS="-I ${STAGING_DIR_NATIVE}/usr/share/aclocal"' >> $script
+	echo 'export SDKTARGETSYSROOT=$standalone_sysroot_target' >> $script
+	echo 'export OECORE_NATIVE_SYSROOT=$standalone_sysroot_native' >> $script
+	echo 'export OECORE_TARGET_SYSROOT=$standalone_sysroot_target' >> $script
+	echo 'export OECORE_ACLOCAL_OPTS="-I $standalone_sysroot_native/usr/share/aclocal"' >> $script
+	echo 'export OECORE_BASELIB="${baselib}"' >> $script
+	echo 'export OECORE_TARGET_ARCH="${TARGET_ARCH}"' >>$script
+	echo 'export OECORE_TARGET_OS="${TARGET_OS}"' >>$script
 
 	toolchain_shared_env_script
+
+	cat >> $script <<EOF
+
+if [ -d "\$OECORE_NATIVE_SYSROOT/${datadir}/post-relocate-setup.d/" ]; then
+	for s in \$OECORE_NATIVE_SYSROOT/${datadir}/post-relocate-setup.d/*; do
+		if [ ! -x \$s ]; then
+			continue
+		fi
+		\$s "\$1"
+		status=\$?
+		if [ \$status != 0 ]; then
+			echo "post-relocate command \"\$s \$1\" failed with status \$status" >&2
+			exit \$status
+		fi
+	done
+fi
+EOF
 }
 
 toolchain_shared_env_script () {
meta/lib/oeqa/selftest/cases/sstatetests.py +1 -1
index 4749f28ab8..63827f3068 100644
@@ -444,7 +444,7 @@ BB_SIGNATURE_HANDLER = "OEBasicHash"
             f = []
             for root, dirs, files in os.walk(d):
                 for name in files:
-                    if "meta-environment" in root or "cross-canadian" in root:
+                    if "meta-environment" in root or "cross-canadian" in root or 'meta-ide-support' in root:
                         continue
                     if "qemux86copy-" in root or "qemux86-" in root:
                         continue
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/6 meta-ide-support: adjust to provide (e)SDK experience directly in a yocto build

Specifically:
1. Add a few more toolchain items to DEPENDS so they're available in the recipe sysroot.
2. Use deploy mechanism to place the SDK environment setup file and testdata for testing it into the image deploy directory.
3. Add ability to run SDK tests via the testsdk class and task. This also requires providing a testdata json file.
4. Ensure sysroot population always runs, as those items are mean to be picked up by 'bitbake build-sysroots' into the unified sysroot.

---
 meta/recipes-core/meta/meta-ide-support.bb | 26 +++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
meta/recipes-core/meta/meta-ide-support.bb +23 -3
index 39317d50e0..7f349f673d 100644
@@ -2,11 +2,13 @@ SUMMARY = "Integrated Development Environment support"
 DESCRIPTION = "Meta package for ensuring the build directory contains all appropriate toolchain packages for using an IDE"
 LICENSE = "MIT"
 
-DEPENDS = "virtual/libc gdb-cross-${TARGET_ARCH} qemu-native qemu-helper-native unfs3-native cmake-native"
+DEPENDS = "virtual/libc gdb-cross-${TARGET_ARCH} qemu-native qemu-helper-native unfs3-native cmake-native autoconf-native automake-native meson-native intltool-native pkgconfig-native"
 PR = "r3"
 RM_WORK_EXCLUDE += "${PN}"
 
-inherit toolchain-scripts nopackages
+inherit toolchain-scripts nopackages deploy testsdk
+
+TESTSDK_CLASS_NAME = "oeqa.sdk.testmetaidesupport.TestSDK"
 
 do_populate_ide_support () {
   toolchain_create_tree_env_script
@@ -18,4 +20,22 @@ python () {
     d.appendVarFlag("do_populate_ide_support", "file-checksums", " " + " ".join(searched))
 }
 
-addtask populate_ide_support before do_build after do_install
+addtask populate_ide_support before do_deploy after do_install
+
+python do_write_test_data() {
+    from oe.data import export2json
+
+    out_dir = d.getVar('B')
+    testdata_name = os.path.join(out_dir, "%s.testdata.json" % d.getVar('PN'))
+
+    export2json(d, testdata_name)
+}
+addtask write_test_data before do_deploy after do_install
+
+do_deploy () {
+        install ${B}/* ${DEPLOYDIR}
+}
+
+addtask deploy before do_build
+
+do_build[deptask] += "do_prepare_recipe_sysroot"
Signature · 1 line
2.30.2
#2 lore raw

PATCH 3/6 oeqa/sdk: add a test class for running SDK tests directly in a Yocto build

In reply to Alexander Kanavin

This is a simpler version of the same class in testsdk.py, as it does not need to unpack and set up the SDK, and can proceed to the tests straight away.

---
 meta/lib/oeqa/sdk/testmetaidesupport.py | 43 +++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 meta/lib/oeqa/sdk/testmetaidesupport.py
meta/lib/oeqa/sdk/testmetaidesupport.py new file +43 -0
new file mode 100644
index 0000000000..2ff76fd8e0
@@ -0,0 +1,43 @@
+#
+# SPDX-License-Identifier: MIT
+#
+
+class TestSDK(object):
+    def run(self, d):
+        import json
+        import logging
+        from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor
+        from oeqa.utils import make_logger_bitbake_compatible
+
+        pn = d.getVar("PN")
+
+        logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
+
+        sdk_dir = d.expand("${WORKDIR}/testsdk/")
+        bb.utils.remove(sdk_dir, True)
+        bb.utils.mkdirhier(sdk_dir)
+
+        sdk_envs = OESDKTestContextExecutor._get_sdk_environs(d.getVar("DEPLOY_DIR_IMAGE"))
+        tdname = d.expand("${DEPLOY_DIR_IMAGE}/${PN}.testdata.json")
+        test_data = json.load(open(tdname, "r"))
+
+        host_pkg_manifest = {"cmake-native":"", "gcc-cross":"", "gettext-native":"", "meson-native":"", "perl-native":"", "python3-core-native":"", }
+        target_pkg_manifest = {"gtk+3":""}
+
+        for s in sdk_envs:
+            bb.plain("meta-ide-support based SDK testing environment: %s" % s)
+
+            sdk_env = sdk_envs[s]
+
+            tc = OESDKTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
+                sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
+                host_pkg_manifest=host_pkg_manifest)
+
+            tc.loadTests(OESDKTestContextExecutor.default_cases)
+
+            results = tc.runTests()
+            if results:
+                results.logSummary(pn)
+
+            if (not results) or (not results.wasSuccessful()):
+                bb.fatal('%s - FAILED' % (pn,), forcelog=True)
Signature · 1 line
2.30.2
#3 lore raw

PATCH 4/6 oeqa/sdk: allow epoxy/galculator tests to run in esdk and direct yocto builds

In reply to Alexander Kanavin

Other tests already have similar tweaks.

---
 meta/lib/oeqa/sdk/cases/buildepoxy.py      | 3 ++-
 meta/lib/oeqa/sdk/cases/buildgalculator.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
meta/lib/oeqa/sdk/cases/buildepoxy.py +2 -1
index f69f720cd6..ad08b777f2 100644
@@ -16,7 +16,8 @@ class EpoxyTest(OESDKTestCase):
     Test that Meson builds correctly.
     """
     def setUp(self):
-        if not (self.tc.hasHostPackage("nativesdk-meson")):
+        if not (self.tc.hasHostPackage("nativesdk-meson") or
+                self.tc.hasHostPackage("meson-native")):
             raise unittest.SkipTest("EpoxyTest class: SDK doesn't contain Meson")
 
     def test_epoxy(self):
meta/lib/oeqa/sdk/cases/buildgalculator.py +2 -1
index eb3c8ddf39..58ade920c9 100644
@@ -19,7 +19,8 @@ class GalculatorTest(OESDKTestCase):
         if not (self.tc.hasTargetPackage("gtk+3", multilib=True) or \
                 self.tc.hasTargetPackage("libgtk-3.0", multilib=True)):
             raise unittest.SkipTest("GalculatorTest class: SDK don't support gtk+3")
-        if not (self.tc.hasHostPackage("nativesdk-gettext-dev")):
+        if not (self.tc.hasHostPackage("nativesdk-gettext-dev") or
+                self.tc.hasHostPackage("gettext-native")):
             raise unittest.SkipTest("GalculatorTest class: SDK doesn't contain gettext")
 
     def test_galculator(self):
Signature · 1 line
2.30.2
#4 lore raw

PATCH 5/6 meson: provide relocation script and native/cross wrappers also for meson-native

In reply to Alexander Kanavin

When using meson-native directly from bitbake this has no effect and everything works as before; the use case is being able to build meson-driven projects from the 'direct SDK' environment. Build systems like cmake/autotools are entirely driven by environment variables, but meson needs configuration files, and so this replicates how SDKs set things up.

In particular, with this change the libepoxy build test from the SDK test suite is able to pass.

---
 .../meson/meson/meson-wrapper                 |  2 +-
 meta/recipes-devtools/meson/meson_0.62.2.bb   | 34 ++++++++++++++++---
 2 files changed, 30 insertions(+), 6 deletions(-)
meta/recipes-devtools/meson/meson/meson-wrapper +1 -1
index 8fafaad975..c62007f507 100755
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 if [ -z "$OECORE_NATIVE_SYSROOT" ]; then
-    echo "OECORE_NATIVE_SYSROOT not set; are you in a Yocto SDK environment?" >&2
+    exec "meson.real" "$@"
 fi
 
 if [ -z "$SSL_CERT_DIR" ]; then
meta/recipes-devtools/meson/meson_0.62.2.bb +29 -5
index acfc64fd4f..fd91da2d1f 100644
@@ -75,7 +75,7 @@ def generate_native_link_template(d):
 
     return repr(val)
 
-do_install:append:class-nativesdk() {
+install_templates() {
     install -d ${D}${datadir}/meson
 
     cat >${D}${datadir}/meson/meson.native.template <<EOF
@@ -117,11 +117,19 @@ needs_exe_wrapper = true
 sys_root = @OECORE_TARGET_SYSROOT
 
 [host_machine]
-system = '${SDK_OS}'
-cpu_family = '${@meson_cpu_family("SDK_ARCH", d)}'
-cpu = '${SDK_ARCH}'
-endian = '${@meson_endian("SDK", d)}'
+system = '$host_system'
+cpu_family = '$host_cpu_family'
+cpu = '$host_cpu'
+endian = '$host_endian'
 EOF
+}
+
+do_install:append:class-nativesdk() {
+    host_system=${SDK_OS}
+    host_cpu_family=${@meson_cpu_family("SDK_ARCH", d)}
+    host_cpu=${SDK_ARCH}
+    host_endian=${@meson_endian("SDK", d)}
+    install_templates
 
     install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d
     install -m 0755 ${WORKDIR}/meson-setup.py ${D}${SDKPATHNATIVE}/post-relocate-setup.d/
@@ -132,3 +140,19 @@ EOF
 }
 
 FILES:${PN}:append:class-nativesdk = "${datadir}/meson ${SDKPATHNATIVE}"
+
+do_install:append:class-native() {
+    host_system=${HOST_OS}
+    host_cpu_family=${@meson_cpu_family("HOST_ARCH", d)}
+    host_cpu=${HOST_ARCH}
+    host_endian=${@meson_endian("HOST", d)}
+    install_templates
+
+    install -d ${D}${datadir}/post-relocate-setup.d
+    install -m 0755 ${WORKDIR}/meson-setup.py ${D}${datadir}/post-relocate-setup.d/
+
+    # We need to wrap the real meson with a thin wrapper that substitues native/cross files
+    # when running in a direct SDK environment.
+    mv ${D}${bindir}/meson ${D}${bindir}/meson.real
+    install -m 0755 ${WORKDIR}/meson-wrapper ${D}${bindir}/meson
+}
Signature · 1 line
2.30.2
#5 lore raw

PATCH 6/6 selftest/meta_ide: add a test for running SDK tests directly in a yocto build

In reply to Alexander Kanavin

There's been a recent discussion about how we can make the Yocto SDK experience better [1]. One of the ideas was to eliminate the SDK as a separate artefact altogether and simply provide everything that the SDK and eSDKs do directly in a yocto build. This does not mean that people have to 'learn Yocto', but rather that the integrators should provide a well-functioning sstate cache infrastructure (same as with minimal eSDK, really), and a few wrapper scripts for setting up the build and the SDK environment that run layer setup and bitbake behind the scenes.

[1] https://lists.openembedded.org/g/openembedded-architecture/topic/thoughts_on_the_esdk/90990557

So without further ado, here's how you get a 'SDK' without building one:

1. Set up all the needed layers and a yocto build directory.

2. Run:

$ bitbake meta-ide-support
$ bitbake -c populate_sysroot gtk+3
(or any other target or native item that the application developer would need)
$ bitbake populate-sysroots

3. Set up the SDK environment:
. tmp/deploy/images/qemux86-64/environment-setup-core2-64-poky-linux (adjust accordingly)

Et voila! The Unix environment is now set up to use the cross-toolchain from Yocto, exactly as in the SDK. And devtool/bitbake are available to extend it, exactly as in the eSDK.

Theare are numerous benefits here: no need to produce, test, distribute and maintain separate SDK artifacts. No two separate environments for the yocto build and the SDK. Less code paths where things can go wrong. Less awkward, gigantic tarballs. Less SDK update headaches: 'updating the SDK' simply means updating the yocto layers with git fetch or layer management tooling. Built-in SDK extensibility: just run bitbake again to add more things to the sysroot, or add layers if even more things are required.

How is this tested?

Exactly same as the regular SDK:

$ bitbake -c testsdk meta-ide-support

This runs the same toolchain tests from meta/lib/oeqa/sdk/cases as the regular sdk testing does.

---
 meta/lib/oeqa/selftest/cases/meta_ide.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
meta/lib/oeqa/selftest/cases/meta_ide.py +10 -4
index 6f10d30dc9..ce7bba401d 100644
@@ -16,13 +16,14 @@ class MetaIDE(OESelftestTestCase):
     def setUpClass(cls):
         super(MetaIDE, cls).setUpClass()
         bitbake('meta-ide-support')
-        bb_vars = get_bb_vars(['MULTIMACH_TARGET_SYS', 'TMPDIR', 'COREBASE'])
+        bitbake('build-sysroots')
+        bb_vars = get_bb_vars(['MULTIMACH_TARGET_SYS', 'DEPLOY_DIR_IMAGE', 'COREBASE'])
         cls.environment_script = 'environment-setup-%s' % bb_vars['MULTIMACH_TARGET_SYS']
-        cls.tmpdir = bb_vars['TMPDIR']
-        cls.environment_script_path = '%s/%s' % (cls.tmpdir, cls.environment_script)
+        cls.deploydir = bb_vars['DEPLOY_DIR_IMAGE']
+        cls.environment_script_path = '%s/%s' % (cls.deploydir, cls.environment_script)
         cls.corebasedir = bb_vars['COREBASE']
         cls.tmpdir_metaideQA = tempfile.mkdtemp(prefix='metaide')
-        
+
     @classmethod
     def tearDownClass(cls):
         shutil.rmtree(cls.tmpdir_metaideQA, ignore_errors=True)
@@ -49,3 +50,8 @@ class MetaIDE(OESelftestTestCase):
                         msg="Running make failed")
         self.assertEqual(self.project.run_install(), 0,
                         msg="Running make install failed")
+
+    def test_meta_ide_can_run_sdk_tests(self):
+        bitbake('-c populate_sysroot gtk+3')
+        bitbake('build-sysroots')
+        bitbake('-c testsdk meta-ide-support')
Signature · 1 line
2.30.2