Skip to content

Commit 076bc50

Browse files
Copilotsnehara99
andcommitted
Extract vendor detection to helper function for consistency
Co-authored-by: snehara99 <[email protected]>
1 parent f995106 commit 076bc50

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

src/kits/kit.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,27 @@ export async function getCompilerVersion(vendor: CompilerVendorEnum, binPath: st
231231
};
232232
}
233233

234+
/**
235+
* Detects the compiler vendor from the compiler binary path.
236+
* @param compilerPath Path to the compiler binary
237+
* @returns The detected vendor or undefined if not detected
238+
*/
239+
function detectVendorFromBinaryPath(compilerPath: string): CompilerVendorEnum | undefined {
240+
const binBasename = path.basename(compilerPath, '.exe').toLowerCase();
241+
// Check for clang-cl first (before clang) to avoid false matches
242+
if (binBasename === 'clang-cl' || binBasename.startsWith('clang-cl-')) {
243+
return 'ClangCl';
244+
}
245+
if (binBasename === 'clang' || binBasename.startsWith('clang-')) {
246+
return 'Clang';
247+
}
248+
if (binBasename === 'gcc' || binBasename.startsWith('gcc-') ||
249+
binBasename.endsWith('-gcc') || binBasename.includes('-gcc-')) {
250+
return 'GCC';
251+
}
252+
return undefined;
253+
}
254+
234255
export async function getKitDetect(kit: Kit): Promise<KitDetect> {
235256
const c_bin = kit?.compilers?.C;
236257
/* Special handling of visualStudio */
@@ -239,9 +260,9 @@ export async function getKitDetect(kit: Kit): Promise<KitDetect> {
239260
if (!vs) {
240261
return kit;
241262
}
242-
// Determine if the compiler is clang-cl based on binary name
243-
const isClangCl = c_bin ? (path.basename(c_bin, '.exe') === 'clang-cl') : false;
244-
const clangVendor: CompilerVendorEnum = isClangCl ? 'ClangCl' : 'Clang';
263+
// Determine if the compiler is clang-cl based on binary name using helper function
264+
const detectedVendor = c_bin ? detectVendorFromBinaryPath(c_bin) : undefined;
265+
const clangVendor: CompilerVendorEnum = detectedVendor === 'ClangCl' ? 'ClangCl' : 'Clang';
245266
let version: CompilerVersion | null = null;
246267
if (c_bin) {
247268
version = await getCompilerVersion(clangVendor, c_bin);
@@ -276,15 +297,7 @@ export async function getKitDetect(kit: Kit): Promise<KitDetect> {
276297
}
277298
// Fallback: detect vendor from compiler binary path if name pattern doesn't match
278299
if (vendor === undefined && c_bin) {
279-
const binBasename = path.basename(c_bin, '.exe').toLowerCase();
280-
if (binBasename === 'clang-cl' || binBasename.startsWith('clang-cl-')) {
281-
vendor = 'ClangCl';
282-
} else if (binBasename === 'clang' || binBasename.startsWith('clang-')) {
283-
vendor = 'Clang';
284-
} else if (binBasename === 'gcc' || binBasename.startsWith('gcc-') ||
285-
binBasename.endsWith('-gcc') || binBasename.includes('-gcc-')) {
286-
vendor = 'GCC';
287-
}
300+
vendor = detectVendorFromBinaryPath(c_bin);
288301
}
289302
if (vendor === undefined) {
290303
return kit;

0 commit comments

Comments
 (0)