]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
devtool: ide-sdk: fix meson compile_commands.json
authorAdrian Freihofer <adrian.freihofer@siemens.com>
Sun, 2 Aug 2026 19:52:52 +0000 (21:52 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 5 Aug 2026 13:38:55 +0000 (14:38 +0100)
The generated meson.cross references the toolchain c/c++ binaries by
bare name (e.g. "aarch64-poky-linux-clang++"), relying on PATH being
set up by the meson wrapper script at build time. Meson stores that
command exactly as configured in compile_commands.json and
meson-info/intro-compilers.json without resolving it to an absolute
path. cpptools (via the mesonbuild extension) resolves compilerPath
using its own process PATH, which does not include the toolchain
directory, and silently falls back to a host compiler, breaking
IntelliSense.

Real builds are unaffected since the wrapper script sets up PATH at
build time, so leave the recipe's meson.cross untouched. Instead,
layer an extra --cross-file on top that only absolutizes the c/cpp
[binaries] entries, reusing the exact same flags as CC/CXX to avoid
any behavior drift. Meson merges multiple machine files, with later
files overriding matching keys from earlier ones.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/devtool/ide_plugins/ide_code.py
scripts/lib/devtool/ide_sdk.py

index 96f007ca91897f7644233f32d59510970e6ff4e3..38f73e355c8dd5ace71b943c2fa2afd83e6ffb19 100644 (file)
@@ -128,6 +128,45 @@ class IdeVSCode(IdeBase):
     def dot_code_dir(self, modified_recipe):
         return os.path.join(modified_recipe.srctree, '.vscode')
 
+    def __gen_meson_absolute_cross_file(self, modified_recipe):
+        """Generate an extra cross file overriding c/cpp binaries with absolute paths.
+
+        The recipe's generated meson.cross references the toolchain binaries
+        (e.g. "aarch64-poky-linux-clang++") by bare name, relying on PATH
+        being set up by the meson wrapper script at build time. Meson stores
+        that command exactly as configured (it never resolves it to an
+        absolute path itself), so it ends up unresolved in
+        compile_commands.json and meson-info/intro-compilers.json. cpptools
+        (via the mesonbuild extension) resolves compilerPath using its own
+        process PATH, which does not include the toolchain directory, and
+        silently falls back to a host compiler for IntelliSense.
+
+        Real builds are unaffected since the wrapper script sets up PATH, so
+        the recipe's meson.cross is left untouched. Instead, an extra
+        --cross-file is layered on top with only the c/cpp [binaries]
+        entries absolutized, reusing the exact same flags as CC/CXX to avoid
+        any behavior drift. Meson merges multiple machine files, with later
+        files overriding matching keys from earlier ones.
+        """
+        def absolutize(cmd):
+            args = cmd.split()
+            args[0] = os.path.join(
+                modified_recipe.staging_bindir_toolchain, args[0])
+            return repr(args)
+
+        lines = ["[binaries]"]
+        if modified_recipe.cc:
+            lines.append("c = %s" % absolutize(modified_recipe.cc))
+        if modified_recipe.cxx:
+            lines.append("cpp = %s" % absolutize(modified_recipe.cxx))
+
+        os.makedirs(modified_recipe.ide_sdk_dir, exist_ok=True)
+        cross_file = os.path.join(
+            modified_recipe.ide_sdk_dir, 'meson-absolute-toolchain.cross')
+        with open(cross_file, 'w') as f:
+            f.write(os.linesep.join(lines) + os.linesep)
+        return ['--cross-file', cross_file]
+
     def __vscode_settings_meson(self, settings_dict, modified_recipe):
         if modified_recipe.build_tool is not BuildTool.MESON:
             return
@@ -135,6 +174,8 @@ class IdeVSCode(IdeBase):
 
         confopts = modified_recipe.mesonopts.split()
         confopts += modified_recipe.meson_cross_file.split()
+        if modified_recipe.meson_cross_file:
+            confopts += self.__gen_meson_absolute_cross_file(modified_recipe)
         confopts += modified_recipe.extra_oemeson.split()
         settings_dict["mesonbuild.configureOptions"] = confopts
         settings_dict["mesonbuild.buildFolder"] = modified_recipe.b
index 940bb8211e58fc0e56154a1031a8b58aa4c26ced..69b002b63564bd3499ef10170f1f96214a8ebe63 100755 (executable)
@@ -478,6 +478,7 @@ class RecipeModified:
         self.bblayers = recipe_d.getVar('BBLAYERS').split()
         self.bitbakepath = recipe_d.getVar('BITBAKEPATH')
         self.bpn = recipe_d.getVar('BPN')
+        self.cc = recipe_d.getVar('CC')
         self.cxx = recipe_d.getVar('CXX')
         self.d = recipe_d.getVar('D')
         self.debug_build = recipe_d.getVar('DEBUG_BUILD')