From 746e244c33465568ba28582a5965e84069962d65 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Wed, 30 May 2012 14:20:29 -0400 Subject: [PATCH] [sd90] Handle compiler specs inspection for setups with non-english locale --- .../AbstractBuiltinSpecsDetector.java | 31 ++++++++++++++++++- .../cdt/internal/core/BuildRunnerHelper.java | 4 +-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java index d4aebe96fb7..e90b22987e8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java @@ -16,6 +16,8 @@ import java.io.OutputStream; import java.net.URI; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; @@ -84,6 +86,9 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ + private static final String ENV_LANGUAGE = "LANGUAGE"; //$NON-NLS-1$ + private static final String ENV_LC_ALL = "LC_ALL"; //$NON-NLS-1$ + private static final int MONITOR_SCALE = 100; private static final int TICKS_REMOVE_MARKERS = 1 * MONITOR_SCALE; private static final int TICKS_RUN_FOR_ONE_LANGUAGE = 10 * MONITOR_SCALE; @@ -533,7 +538,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } } - String[] envp = BuildRunnerHelper.getEnvp(currentCfgDescription); + String[] envp = getEnvp(); // Using GMAKE_ERROR_PARSER_ID as it can handle generated error messages ErrorParserManager epm = new ErrorParserManager(currentProject, buildDirURI, markerGenerator, new String[] {GMAKE_ERROR_PARSER_ID}); @@ -567,6 +572,30 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } } + /** + * Get array of environment variables in format "var=value". + */ + private String[] getEnvp() { + // On POSIX (Linux, UNIX) systems reset language variables to default (English) + // with UTF-8 encoding since GNU compilers can handle only UTF-8 characters. + // Include paths with locale characters will be handled properly regardless + // of the language as long as the encoding is set to UTF-8. + // Default language is set for parser because it relies on English messages + // in the output of the 'gcc -v' command. + + List envp = new ArrayList(Arrays.asList(BuildRunnerHelper.getEnvp(currentCfgDescription))); + for (Iterator iterator = envp.iterator(); iterator.hasNext();) { + String var = iterator.next(); + if (var.startsWith(ENV_LANGUAGE + '=') || var.startsWith(ENV_LC_ALL + '=')) { + iterator.remove(); + } + } + envp.add(ENV_LANGUAGE + "=C"); // override for GNU gettext //$NON-NLS-1$ + envp.add(ENV_LC_ALL + "=C.UTF-8"); // for other parts of the system libraries //$NON-NLS-1$ + + return envp.toArray(new String[envp.size()]); + } + protected int runProgramForLanguage(String languageId, String command, String[] envp, URI workingDirectoryURI, OutputStream consoleOut, OutputStream consoleErr, IProgressMonitor monitor) throws CoreException, IOException { return buildRunnerHelper.build(monitor); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/BuildRunnerHelper.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/BuildRunnerHelper.java index ec9e248bd70..970b36d7d9b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/BuildRunnerHelper.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/BuildRunnerHelper.java @@ -501,8 +501,8 @@ public class BuildRunnerHelper implements Closeable { * Get environment variables from configuration as array of "var=value" suitable * for using as "envp" with Runtime.exec(String[] cmdarray, String[] envp, File dir) * - * @param cfgDescription - configuration description - * @return String array of environment variables in format "var=value" + * @param cfgDescription - configuration description. + * @return String array of environment variables in format "var=value". Does not return {@code null}. */ public static String[] getEnvp(ICConfigurationDescription cfgDescription) { IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager();