mono/CppSharp

GetUnixCompilerInfo fails on LANG=de_DE.UTF8

matthiasbeyer opened this issue · 1 comments

private void GetUnixCompilerInfo(string headersPath, out string compiler,
out string longVersion, out string shortVersion)
{
if (!Platform.IsLinux)
{
compiler = "gcc";
// Search for the available GCC versions on the provided headers.
var versions = Directory.EnumerateDirectories(Path.Combine(headersPath,
"usr", "include", "c++"));
if (!versions.Any())
throw new Exception("No valid GCC version found on system include paths");
var gccVersionPath = versions.First();
longVersion = shortVersion = gccVersionPath.Substring(
gccVersionPath.LastIndexOf(Path.DirectorySeparatorChar) + 1);
return;
}
var info = new ProcessStartInfo(Environment.GetEnvironmentVariable("CXX") ?? "gcc", "-v")
{
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false
};
var process = Process.Start(info);
if (process == null)
throw new SystemException("GCC compiler was not found.");
process.WaitForExit();
var output = process.StandardError.ReadToEnd();
var match = Regex.Match(output, "(gcc|clang) version (([0-9]+\\.[0-9]+)\\.[0-9]+)");
if (!match.Success)
throw new SystemException("GCC compiler was not found.");
compiler = match.Groups[1].ToString();
longVersion = match.Groups[2].ToString();
shortVersion = match.Groups[3].ToString();
}

This function fails to find the GCC compiler on my system with my normal LANG=de_DE.UTF8, but succeeds if I export LANG=C before running the relevant code.

Unfortunately the Code running this is proprietary, so I cannot share more about it, but it is literally:

$ ./myCode # fails
$ export LANG=C
$ ./myCode # succeeds

I found the actual issue.

You re-used your error message in the function, so I assumed that the first exception is thrown, when it is actually the second one.

And the regex just does not match, because with german locale, "version" is written "Version" in the compiler output of gcc -v.