override the locale when querying compiler versions (#1824)

This commit is contained in:
Bob Brown 2021-04-30 10:02:27 -07:00 коммит произвёл GitHub
Родитель 4f2bf2163f
Коммит 8cca2dbe0a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 16 добавлений и 15 удалений

2
.github/workflows/build-vsix.yml поставляемый
Просмотреть файл

@ -40,4 +40,4 @@ jobs:
with:
name: cmake-tools.vsix
path: ./cmake-tools.vsix
if-no-files-found: error
if-no-files-found: error

Просмотреть файл

@ -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;
}
@ -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;

Просмотреть файл

@ -82,6 +82,7 @@ export interface ExecutionOptions {
encoding?: BufferEncoding;
outputEncoding?: string;
useTask?: boolean;
overrideLocale?: boolean;
}
export function buildCmdStr(command: string, args?: string[]): string {
@ -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,