summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>2024-02-19 17:55:24 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-02-20 12:58:41 +0000
commitfc8e5d7c13f62e987b76971116cf290fd01a0c8f (patch)
treea2de30a8423b33276c4728c5bc3dae6480850cf4
parentc0d340c52e6ff3a09d763fe13ea1dc9b726c6cb9 (diff)
downloadpoky-fc8e5d7c13f62e987b76971116cf290fd01a0c8f.tar.gz
meson: use absolute cross-compiler paths
Among the files generated by meson is compile_commands.json. It is not used by bitbake during the build. However, if the devtool workspace is opened inside an IDE, that IDE can use compile_commands.json to configure linting and code completion. This is notably relied on by the new devtool ide-sdk command. The problem is that the IDE using compile_commands.json does not know the $PATH set-up by bitbake, so it won't find the compiler. This results in linting errors, like missing headers. We can fix this by expliciting the absolute compiler paths in meson.cross. The compile_commands.json specification expressly states: "All paths specified in the command or file fields must be either absolute or relative to this directory." Link: https://clang.llvm.org/docs/JSONCompilationDatabase.html An alternative way to implement this is to directly change CXX inside bitbake.conf to make all recipes use absolute compiler paths.Since this would affect all recipes, so I would like to have the maintainers' opinion on this. It could make sense to use absolute compiler paths for all toolchain binaries, we already do so for the sysroot TOOLCHAIN_OPTIONS. Discussions have been opened with meson/ninja maintainers to implement this at their level: - https://github.com/ninja-build/ninja/issues/2383 - https://github.com/mesonbuild/meson/issues/12834 These tools have even less information on the environment so it makes sense for Yocto to provide the absolute paths. (From OE-Core rev: b4e00248049c2627b05eafa9313a48cf253623fa) Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/meson-routines.bbclass6
-rw-r--r--meta/classes-recipe/meson.bbclass7
2 files changed, 11 insertions, 2 deletions
diff --git a/meta/classes-recipe/meson-routines.bbclass b/meta/classes-recipe/meson-routines.bbclass
index a944a8fff1..9925465ed8 100644
--- a/meta/classes-recipe/meson-routines.bbclass
+++ b/meta/classes-recipe/meson-routines.bbclass
@@ -10,6 +10,12 @@ def meson_array(var, d):
10 items = d.getVar(var).split() 10 items = d.getVar(var).split()
11 return repr(items[0] if len(items) == 1 else items) 11 return repr(items[0] if len(items) == 1 else items)
12 12
13def meson_array_abspath(var, d):
14 import shutil
15 items = d.getVar(var).split()
16 items[0] = shutil.which(items[0]) or items[0]
17 return repr(items[0] if len(items) == 1 else items)
18
13# Map our ARCH values to what Meson expects: 19# Map our ARCH values to what Meson expects:
14# http://mesonbuild.com/Reference-tables.html#cpu-families 20# http://mesonbuild.com/Reference-tables.html#cpu-families
15def meson_cpu_family(var, d): 21def meson_cpu_family(var, d):
diff --git a/meta/classes-recipe/meson.bbclass b/meta/classes-recipe/meson.bbclass
index 03fa2c06eb..31675cf42d 100644
--- a/meta/classes-recipe/meson.bbclass
+++ b/meta/classes-recipe/meson.bbclass
@@ -64,10 +64,13 @@ addtask write_config before do_configure
64do_write_config[vardeps] += "CC CXX AR NM STRIP READELF OBJCOPY CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS EXEWRAPPER_ENABLED" 64do_write_config[vardeps] += "CC CXX AR NM STRIP READELF OBJCOPY CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS EXEWRAPPER_ENABLED"
65do_write_config() { 65do_write_config() {
66 # This needs to be Py to split the args into single-element lists 66 # This needs to be Py to split the args into single-element lists
67 # The generated compile_commands.json file can be used by external IDEs
68 # which do not know the $PATH set-up by bitbake. They need the absolute
69 # compiler paths.
67 cat >${WORKDIR}/meson.cross <<EOF 70 cat >${WORKDIR}/meson.cross <<EOF
68[binaries] 71[binaries]
69c = ${@meson_array('CC', d)} 72c = ${@meson_array_abspath('CC', d)}
70cpp = ${@meson_array('CXX', d)} 73cpp = ${@meson_array_abspath('CXX', d)}
71cython = 'cython3' 74cython = 'cython3'
72ar = ${@meson_array('AR', d)} 75ar = ${@meson_array('AR', d)}
73nm = ${@meson_array('NM', d)} 76nm = ${@meson_array('NM', d)}