Skip to content

Commit

Permalink
clang-format/tidy version comparisons fail for some builds (#12813)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrow authored Oct 7, 2024
1 parent 3324ea8 commit c2baddd
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export class CppSettings extends Settings {
if (cachedClangPath !== undefined) {
return cachedClangPath;
}
const clangStr: string = isFormat ? this.clangFormatStr : this.clangTidyStr;
const clangName: string = isFormat ? this.clangFormatName : this.clangTidyName;
const setCachedClangPath: (path: string) => void = isFormat ? setCachedClangFormatPath : setCachedClangTidyPath;
const whichPath: string | null = which.sync(clangName, { nothrow: true });
Expand All @@ -290,29 +289,24 @@ export class CppSettings extends Settings {
return undefined;
} else {
// Attempt to invoke both our own version of clang-* to see if we can successfully execute it, and to get its version.
let clangVersion: string;
let bundledVersion: string;
try {
const exePath: string = getExtensionFilePath(`./LLVM/bin/${clangName}`);
const output: string[] = execSync(quote([exePath, '--version'])).toString().split(" ");
if (output.length < 3 || output[0] !== clangStr || output[1] !== "version" || !semver.valid(output[2])) {
if (output.length === 3) {
return path;
}
const versionIndex: number = output.findIndex((value: string) => value === "version");
if (versionIndex < 0 || versionIndex + 1 >= output.length || !semver.valid(output[versionIndex + 1].trim())) {
return path;
}
const bundledPath: string = getExtensionFilePath(`./LLVM/bin/${clangName}`);
const output: string = execSync(quote([bundledPath, '--version'])).toString();
bundledVersion = output.match(/(\d+\.\d+\.\d+)/)?.[1] ?? "";
if (!semver.valid(bundledVersion)) {
return path;
}
clangVersion = output[2];
} catch (e) {
// Unable to invoke our own clang-*. Use the system installed clang-*.
return path;
}

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

0 comments on commit c2baddd

Please sign in to comment.