Skip to content

Commit c2baddd

Browse files
authored
clang-format/tidy version comparisons fail for some builds (#12813)
1 parent 3324ea8 commit c2baddd

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Extension/src/LanguageServer/settings.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ export class CppSettings extends Settings {
277277
if (cachedClangPath !== undefined) {
278278
return cachedClangPath;
279279
}
280-
const clangStr: string = isFormat ? this.clangFormatStr : this.clangTidyStr;
281280
const clangName: string = isFormat ? this.clangFormatName : this.clangTidyName;
282281
const setCachedClangPath: (path: string) => void = isFormat ? setCachedClangFormatPath : setCachedClangTidyPath;
283282
const whichPath: string | null = which.sync(clangName, { nothrow: true });
@@ -290,29 +289,24 @@ export class CppSettings extends Settings {
290289
return undefined;
291290
} else {
292291
// Attempt to invoke both our own version of clang-* to see if we can successfully execute it, and to get its version.
293-
let clangVersion: string;
292+
let bundledVersion: string;
294293
try {
295-
const exePath: string = getExtensionFilePath(`./LLVM/bin/${clangName}`);
296-
const output: string[] = execSync(quote([exePath, '--version'])).toString().split(" ");
297-
if (output.length < 3 || output[0] !== clangStr || output[1] !== "version" || !semver.valid(output[2])) {
298-
if (output.length === 3) {
299-
return path;
300-
}
301-
const versionIndex: number = output.findIndex((value: string) => value === "version");
302-
if (versionIndex < 0 || versionIndex + 1 >= output.length || !semver.valid(output[versionIndex + 1].trim())) {
303-
return path;
304-
}
294+
const bundledPath: string = getExtensionFilePath(`./LLVM/bin/${clangName}`);
295+
const output: string = execSync(quote([bundledPath, '--version'])).toString();
296+
bundledVersion = output.match(/(\d+\.\d+\.\d+)/)?.[1] ?? "";
297+
if (!semver.valid(bundledVersion)) {
298+
return path;
305299
}
306-
clangVersion = output[2];
307300
} catch (e) {
308301
// Unable to invoke our own clang-*. Use the system installed clang-*.
309302
return path;
310303
}
311304

312305
// Invoke the version on the system to compare versions. Use ours if it's more recent.
313306
try {
314-
const output: string[] = execSync(`"${path}" --version`).toString().split(" ");
315-
if (output.length < 3 || output[0] !== clangStr || output[1] !== "version" || semver.ltr(output[2], clangVersion)) {
307+
const output: string = execSync(`"${path}" --version`).toString();
308+
const userVersion = output.match(/(\d+\.\d+\.\d+)/)?.[1] ?? "";
309+
if (semver.ltr(userVersion, bundledVersion)) {
316310
path = "";
317311
setCachedClangPath(path);
318312
}

0 commit comments

Comments
 (0)