Skip to content

Commit

Permalink
override the locale when querying compiler versions (microsoft#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrow authored Apr 30, 2021
1 parent 4f2bf21 commit 8cca2db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-vsix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
with:
name: cmake-tools.vsix
path: ./cmake-tools.vsix
if-no-files-found: error
if-no-files-found: error
18 changes: 5 additions & 13 deletions src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,18 @@ interface CompilerVersion {

export async function getCompilerVersion(vendor: CompilerVendorEnum, binPath: string): Promise<CompilerVersion|null> {
log.debug(localize('testing.compiler.binary', 'Testing {0} binary: {1}', vendor, binPath));
const exec = await proc.execute(binPath, ['-v']).result;
const exec = await proc.execute(binPath, ['-v'], undefined, { overrideLocale: true }).result;
if (exec.retc !== 0) {
log.debug(localize('bad.compiler.binary', 'Bad {0} binary ("-v" returns non-zero): {1}', vendor, binPath));
return null;
}
let version_re_loc: RegExp;
let version_re_en: RegExp;
const versionWord: string = localize("version.word", "version");
let version_re: RegExp;
let version_match_index;
if (vendor === 'Clang') {
const version_re_str_loc: string = `^(?:Apple LLVM|.*clang) ${versionWord} ([^\\s-]+)(?:[\\s-]|$)`;
const version_re_str_en: string = `^(?:Apple LLVM|.*clang) version ([^\\s-]+)(?:[\\s-]|$)`;
version_re_loc = RegExp(version_re_str_loc, "mgi");
version_re_en = RegExp(version_re_str_en, "mgi");
version_re = /^(?:Apple LLVM|.*clang) version ([^\s-]+)(?:[\s-]|$)/mgi;
version_match_index = 1;
} else {
const version_re_str_loc: string = `^gcc(-| )${versionWord} (.*?) .*`;
const version_re_str_en: string = `^gcc(-| )version (.*?) .*`;
version_re_loc = RegExp(version_re_str_loc, "mgi");
version_re_en = RegExp(version_re_str_en, "mgi");
version_re = /^gcc(-| )version (.*?) .*/mgi;
version_match_index = 2;
}

Expand All @@ -181,7 +173,7 @@ export async function getCompilerVersion(vendor: CompilerVendorEnum, binPath: st
let fullVersion: string = "";
const lines = exec.stderr.trim().split('\n');
for (const line of lines) {
const version_match = version_re_en.exec(line) || version_re_loc.exec(line);
const version_match = version_re.exec(line);
if (version_match !== null && version === '') {
version = version_match[version_match_index];
fullVersion = line;
Expand Down
11 changes: 10 additions & 1 deletion src/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface ExecutionOptions {
encoding?: BufferEncoding;
outputEncoding?: string;
useTask?: boolean;
overrideLocale?: boolean;
}

export function buildCmdStr(command: string, args?: string[]): string {
Expand Down Expand Up @@ -114,7 +115,15 @@ export function execute(command: string,
if (!options) {
options = {};
}
const final_env = util.mergeEnvironment(process.env as EnvironmentVariables, options.environment || {});
const localeOverride: EnvironmentVariables = {
LANG: "C",
LC_ALL: "C"
};
const final_env = util.mergeEnvironment(
process.env as EnvironmentVariables,
options.environment || {},
options.overrideLocale ? localeOverride : {});

const spawn_opts: proc.SpawnOptions = {
env: final_env,
shell: !!options.shell,
Expand Down

0 comments on commit 8cca2db

Please sign in to comment.