Skip to content

Commit

Permalink
Handle undefined machine in cpptoolsconfigprovider.ts
Browse files Browse the repository at this point in the history
The machine configuration is usually defined in meson introspection.
Just to be sure, add a check for undefined machine. For instance, if
someone or something has tampered with the build files.
  • Loading branch information
deribaucourt authored and tristan957 committed Mar 9, 2024
1 parent 2a4d408 commit 188355d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/cpptoolsconfigprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export class CpptoolsProvider implements cpptools.CustomConfigurationProvider {
const dependencies = await getMesonDependencies(this.buildDir);
browseConfig = Object.assign(browseConfig, { browsePath: this.getDependenciesIncludeDirs(dependencies) });

let machine = "";
let machine: string | undefined;
const buildOptions = await getMesonBuildOptions(this.buildDir);
for (const option of buildOptions) {
if (option.name === "cpp_std") {
if (option.value != "none") browseConfig = Object.assign({}, browseConfig, { standard: option.value });
machine = option.machine;
} else if (machine === "" && option.name === "c_std") {
} else if (machine === undefined && option.name === "c_std") {
// C++ takes precedence
if (option.value != "none") browseConfig = Object.assign({}, browseConfig, { standard: option.value });
machine = option.machine;
Expand All @@ -59,11 +59,13 @@ export class CpptoolsProvider implements cpptools.CustomConfigurationProvider {

try {
const compilers = await getMesonCompilers(this.buildDir);
const compiler = compilers[machine];
if (compiler && compiler["cpp"]) {
browseConfig = this.setCompilerArgs(compiler, "cpp", browseConfig);
} else if (compiler && compiler["c"]) {
browseConfig = this.setCompilerArgs(compiler, "c", browseConfig);
if (machine !== undefined && compilers[machine] !== undefined) {
const compiler = compilers[machine];
if (compiler && compiler["cpp"]) {
browseConfig = this.setCompilerArgs(compiler, "cpp", browseConfig);
} else if (compiler && compiler["c"]) {
browseConfig = this.setCompilerArgs(compiler, "c", browseConfig);
}
}
} catch (e) {
getOutputChannel().appendLine(
Expand Down

0 comments on commit 188355d

Please sign in to comment.