Skip to content

Commit 534bcc9

Browse files
authored
Fix header files (files groups with no compilerFragments) getting compilerFragments from RC language file groups. (#4655)
* Fix header files getting compileFragments from RC. * Add a unit test case. * Fix linter error.
1 parent 2400d98 commit 534bcc9

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/cpptools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ export class CppConfigurationProvider implements cpptools.CustomConfigurationPro
598598
target.fileGroups?.reverse();
599599
const grps = target.fileGroups || [];
600600
const includePath = [...new Set(util.flatMap(grps, grp => grp.includePath || []))].map(item => item.path);
601-
const compileCommandFragments = [...util.first(grps, grp => grp.compileCommandFragments || [])];
601+
const compileCommandFragments = [...util.first(grps.filter(grp => grp.language !== 'RC'), grp => grp.compileCommandFragments || [])];
602602
const defines = [...new Set(util.flatMap(grps, grp => grp.defines || []))];
603603
const sysroot = target.sysroot;
604604
this.targets.push({ name: target.name, type: target.type });

test/unit-tests/cpptools.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ suite('CppTools tests', () => {
272272
const provider = new CppConfigurationProvider();
273273
const cache = await CMakeCache.fromPath(getTestResourceFilePath('TestCMakeCache.txt'));
274274
const sourceFile1 = path.join(here, 'main.cpp');
275+
const headerFile1 = path.join(here, 'main.h');
276+
const rcFile1 = path.join(here, 'main.rc');
275277
const uri1 = vscode.Uri.file(sourceFile1);
278+
const uri1_h = vscode.Uri.file(headerFile1);
279+
const uri1_rc = vscode.Uri.file(rcFile1);
276280
const codeModel1: codeModel.CodeModelContent = {
277281
configurations: [{
278282
name: "Release",
@@ -289,6 +293,16 @@ suite('CppTools tests', () => {
289293
defines: ['DEFINE1'],
290294
compileCommandFragments: ['-DFRAGMENT1'],
291295
language: 'CXX'
296+
},
297+
{
298+
sources: [headerFile1],
299+
isGenerated: false
300+
},
301+
{
302+
sources: [rcFile1],
303+
isGenerated: false,
304+
compileCommandFragments: ['-DFRAGMENT_RC'],
305+
language: 'RC'
292306
}]
293307
},
294308
{
@@ -347,6 +361,12 @@ suite('CppTools tests', () => {
347361
expect(configurations[0].configuration.compilerFragments).to.contain('-DFRAGMENT1');
348362
expect(configurations[0].configuration.compilerArgs).to.be.empty;
349363

364+
configurations = await provider.provideConfigurations([uri1_h]);
365+
expect(configurations[0].configuration.compilerFragments).to.contain('-DFRAGMENT1');
366+
367+
configurations = await provider.provideConfigurations([uri1_rc]);
368+
expect(configurations[0].configuration.compilerFragments).to.contain('-DFRAGMENT_RC');
369+
350370
provider.updateConfigurationData({ cache, codeModelContent: codeModel1, activeTarget: 'target2', activeBuildTypeVariant: 'Release', folder: here });
351371
configurations = await provider.provideConfigurations([uri1]);
352372
expect(configurations.length).to.eq(1);

0 commit comments

Comments
 (0)