Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetUnixCompilerInfo fails on LANG=de_DE.UTF8 #1856

Open
matthiasbeyer opened this issue Aug 1, 2024 · 1 comment
Open

GetUnixCompilerInfo fails on LANG=de_DE.UTF8 #1856

matthiasbeyer opened this issue Aug 1, 2024 · 1 comment

Comments

@matthiasbeyer
Copy link

matthiasbeyer commented Aug 1, 2024

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
@matthiasbeyer
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant