[PATCH v2 5/5] devtool: code: Provide a generic C++ configuration

Enguerrand de Ribaucourt
2024-02-19T16:55:42Z

By default, the cpptools VSCode extension will use the host's headers
and flags for linting. This results in a lot of include errors and
misleading definitions. Even though this generic configuration doesn't
include all the depenendencies, it is a proper fallback for recipe
classes we do not accurately cover, with at least the right sysroot.

Additionally, ide-sdk automatically detects and provides a launch.json
configuration for autotools recipes so we should recommend the C++
extensions for them.

Recipes which use C/C++ without a build system are not covered by this
patch.

Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>
---
scripts/lib/devtool/ide_plugins/__init__.py | 3 +++
scripts/lib/devtool/ide_plugins/ide_code.py | 27 +++++++++++++--------
scripts/lib/devtool/ide_sdk.py | 5 ++++
3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/scripts/lib/devtool/ide_plugins/__init__.py b/scripts/lib/devtool/ide_plugins/__init__.py
index 3371b242640..59e90663908 100644
--- a/scripts/lib/devtool/ide_plugins/__init__.py
+++ b/scripts/lib/devtool/ide_plugins/__init__.py
@@ -21,6 +21,7 @@ class BuildTool(Enum):
UNDEFINED = auto()
CMAKE = auto()
MESON = auto()
+ AUTOTOOLS = auto()

@property
def is_c_ccp(self):
@@ -28,6 +29,8 @@ class BuildTool(Enum):
return True
if self is BuildTool.MESON:
return True
+ if self is BuildTool.AUTOTOOLS:
+ return True
return False

diff --git a/scripts/lib/devtool/ide_plugins/ide_code.py b/scripts/lib/devtool/ide_plugins/ide_code.py
index 7b683c74086..0942fde8196 100644
--- a/scripts/lib/devtool/ide_plugins/ide_code.py
+++ b/scripts/lib/devtool/ide_plugins/ide_code.py
@@ -157,31 +157,35 @@ class IdeVSCode(IdeBase):
IdeBase.update_json_file(
self.dot_code_dir(modified_recipe), settings_file, settings_dict)

- def __vscode_extensions_cmake(self, modified_recipe, recommendations):
- if modified_recipe.build_tool is not BuildTool.CMAKE:
+ def __vscode_extensions_generic(self, modified_recipe, recommendations):
+ if not modified_recipe.build_tool.is_c_ccp:
return
recommendations += [
- "twxs.cmake",
- "ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools-themes"
]

+ def __vscode_extensions_cmake(self, modified_recipe, recommendations):
+ if modified_recipe.build_tool is not BuildTool.CMAKE:
+ return
+ recommendations += [
+ "twxs.cmake",
+ "ms-vscode.cmake-tools"
+ ]
+
def __vscode_extensions_meson(self, modified_recipe, recommendations):
if modified_recipe.build_tool is not BuildTool.MESON:
return
recommendations += [
- 'mesonbuild.mesonbuild',
- "ms-vscode.cpptools",
- "ms-vscode.cpptools-extension-pack",
- "ms-vscode.cpptools-themes"
+ 'mesonbuild.mesonbuild'
]

def vscode_extensions(self, modified_recipe):
recommendations = []
self.__vscode_extensions_cmake(modified_recipe, recommendations)
self.__vscode_extensions_meson(modified_recipe, recommendations)
+ self.__vscode_extensions_generic(modified_recipe, recommendations)
extensions_file = 'extensions.json'
IdeBase.update_json_file(
self.dot_code_dir(modified_recipe), extensions_file, {"recommendations": recommendations})
@@ -194,8 +198,11 @@ class IdeVSCode(IdeBase):
properties_dict["configurationProvider"] = "ms-vscode.cmake-tools"
elif modified_recipe.build_tool is BuildTool.MESON:
properties_dict["configurationProvider"] = "mesonbuild.mesonbuild"
- else: # no C/C++ build
- return
+ elif modified_recipe.build_tool.is_c_ccp:
+ # Provide a generic linting configuration
+ # We provide a C++ configuration with the proper sysroot
+ properties_dict["compilerPath"] = os.path.join(modified_recipe.staging_bindir_toolchain, modified_recipe.cxx.split()[0])
+ properties_dict["compilerArgs"] = modified_recipe.cxx.split()[1:]

properties_dicts = {
"configurations": [
diff --git a/scripts/lib/devtool/ide_sdk.py b/scripts/lib/devtool/ide_sdk.py
index f292edbe25c..6313daa8700 100755
--- a/scripts/lib/devtool/ide_sdk.py
+++ b/scripts/lib/devtool/ide_sdk.py
@@ -345,6 +345,7 @@ class RecipeModified:
self.base_libdir = recipe_d.getVar('base_libdir')
self.bblayers = recipe_d.getVar('BBLAYERS').split()
self.bpn = recipe_d.getVar('BPN')
+ self.cxx = recipe_d.getVar('CXX')
self.d = recipe_d.getVar('D')
self.fakerootcmd = recipe_d.getVar('FAKEROOTCMD')
self.fakerootenv = recipe_d.getVar('FAKEROOTENV')
@@ -361,6 +362,8 @@ class RecipeModified:
recipe_d.getVar('RECIPE_SYSROOT'))
self.recipe_sysroot_native = os.path.realpath(
recipe_d.getVar('RECIPE_SYSROOT_NATIVE'))
+ self.staging_bindir_toolchain = os.path.realpath(
+ recipe_d.getVar('STAGING_BINDIR_TOOLCHAIN'))
self.staging_incdir = os.path.realpath(
recipe_d.getVar('STAGING_INCDIR'))
self.strip_cmd = recipe_d.getVar('STRIP')
@@ -380,6 +383,8 @@ class RecipeModified:
self.extra_oemeson = recipe_d.getVar('EXTRA_OEMESON')
self.meson_cross_file = recipe_d.getVar('MESON_CROSS_FILE')
self.build_tool = BuildTool.MESON
+ elif bb.data.inherits_class('autotools', recipe_d):
+ self.build_tool = BuildTool.AUTOTOOLS

# Recipe ID is the identifier for IDE config sections
self.recipe_id = self.bpn + "-" + self.package_arch
--
2.34.1