mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 18:25:40 +02:00
[#407] fix CompilerBuiltinsDetector for msys2 on Windows The cc.exe from mingw64 (part of Msys2) on Windows needs the bin folder to be on the PATH to be executed. e.g. 'C:\msys64\mingw64\bin' must be part of the PATH environment variable fixes #407
This commit is contained in:
parent
9aa6fb158d
commit
36110e1251
4 changed files with 41 additions and 10 deletions
|
@ -4,7 +4,7 @@ Bundle-Name: %bundleName
|
||||||
Bundle-Description: %bundleDescription
|
Bundle-Description: %bundleDescription
|
||||||
Bundle-Copyright: %Bundle-Copyright
|
Bundle-Copyright: %Bundle-Copyright
|
||||||
Bundle-SymbolicName: org.eclipse.cdt.jsoncdb.core;singleton:=true
|
Bundle-SymbolicName: org.eclipse.cdt.jsoncdb.core;singleton:=true
|
||||||
Bundle-Version: 1.4.200.qualifier
|
Bundle-Version: 1.4.300.qualifier
|
||||||
Bundle-Vendor: %Bundle-Vendor
|
Bundle-Vendor: %Bundle-Vendor
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-17
|
Bundle-RequiredExecutionEnvironment: JavaSE-17
|
||||||
|
|
|
@ -14,9 +14,11 @@ import java.nio.file.Files;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||||
import org.eclipse.cdt.core.ICommandLauncher;
|
import org.eclipse.cdt.core.ICommandLauncher;
|
||||||
import org.eclipse.cdt.core.resources.IConsole;
|
import org.eclipse.cdt.core.resources.IConsole;
|
||||||
|
@ -104,8 +106,8 @@ public class CompilerBuiltinsDetector {
|
||||||
|
|
||||||
launcher.setProject(project);
|
launcher.setProject(project);
|
||||||
launcher.showCommand(console != null);
|
launcher.showCommand(console != null);
|
||||||
final Process proc = launcher.execute(new Path(command), argList.toArray(new String[argList.size()]), getEnvp(),
|
final Process proc = launcher.execute(new Path(command), argList.toArray(new String[argList.size()]),
|
||||||
new Path(this.buildDirectory.toString()), monitor);
|
getEnvp(project), new Path(this.buildDirectory.toString()), monitor);
|
||||||
if (proc != null) {
|
if (proc != null) {
|
||||||
try {
|
try {
|
||||||
// Close the input of the process since we will never write to it
|
// Close the input of the process since we will never write to it
|
||||||
|
@ -182,20 +184,47 @@ public class CompilerBuiltinsDetector {
|
||||||
* @return String array of environment variables in format "var=value". Does not
|
* @return String array of environment variables in format "var=value". Does not
|
||||||
* return {@code null}.
|
* return {@code null}.
|
||||||
*/
|
*/
|
||||||
private String[] getEnvp() {
|
private String[] getEnvp(IProject project) {
|
||||||
|
var map = new HashMap<String, String>();
|
||||||
|
// The cc.exe from mingw64 (part of Msys2) on Windows needs the bin folder to be on the PATH to be executed.
|
||||||
|
// e.g. 'C:\msys64\mingw64\bin' must be part of the PATH environment variable. That's why we need PATH here:
|
||||||
|
// Fixes CDT #407
|
||||||
|
try {
|
||||||
|
final String path = "PATH"; //$NON-NLS-1$
|
||||||
|
var variables = CCorePlugin.getDefault().getBuildEnvironmentManager()
|
||||||
|
.getVariables(project.getActiveBuildConfig(), true);
|
||||||
|
for (var variable : variables) {
|
||||||
|
if (path.equalsIgnoreCase(variable.getName())) {
|
||||||
|
map.put(path, variable.getValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
Plugin.getDefault().getLog().error(
|
||||||
|
String.format(Messages.CompilerBuiltinsDetector_errmsg_determine_PATH_failed, project.getName()),
|
||||||
|
e);
|
||||||
|
}
|
||||||
// On POSIX (Linux, UNIX) systems reset language variables to default (English)
|
// On POSIX (Linux, UNIX) systems reset language variables to default (English)
|
||||||
// with UTF-8 encoding since GNU compilers can handle only UTF-8 characters.
|
// with UTF-8 encoding since GNU compilers can handle only UTF-8 characters.
|
||||||
// Include paths with locale characters will be handled properly regardless
|
// Include paths with locale characters will be handled properly regardless
|
||||||
// of the language as long as the encoding is set to UTF-8.
|
// of the language as long as the encoding is set to UTF-8.
|
||||||
// English language is set for parser because it relies on English messages
|
// English language is set for parser because it relies on English messages
|
||||||
// in the output of the 'gcc -v'.
|
// in the output of the 'gcc -v'.
|
||||||
String[] strings = {
|
|
||||||
// override for GNU gettext
|
|
||||||
"LANGUAGE" + "=en", //$NON-NLS-1$//$NON-NLS-2$
|
|
||||||
// for other parts of the system libraries
|
|
||||||
"LC_ALL" + "=C.UTF-8" }; //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
|
|
||||||
return strings;
|
// override for GNU gettext
|
||||||
|
map.put("LANGUAGE", "en"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
// for other parts of the system libraries
|
||||||
|
map.put("LC_ALL", "C.UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
|
var envArray = map.entrySet().stream().map(entry -> {
|
||||||
|
var result = entry.getKey() + '=';
|
||||||
|
if (entry.getValue() != null) {
|
||||||
|
result = result + entry.getValue();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}).toArray(String[]::new);
|
||||||
|
|
||||||
|
return envArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Messages extends NLS {
|
||||||
public static String CompilerBuiltinsDetector_msg_detection_finished;
|
public static String CompilerBuiltinsDetector_msg_detection_finished;
|
||||||
public static String CompilerBuiltinsDetector_msg_detection_start;
|
public static String CompilerBuiltinsDetector_msg_detection_start;
|
||||||
public static String CompilerBuiltinsDetector_msg_unexpectedly_still_running;
|
public static String CompilerBuiltinsDetector_msg_unexpectedly_still_running;
|
||||||
|
public static String CompilerBuiltinsDetector_errmsg_determine_PATH_failed;
|
||||||
public static String DetectorConsole_title;
|
public static String DetectorConsole_title;
|
||||||
static {
|
static {
|
||||||
// initialize resource bundle
|
// initialize resource bundle
|
||||||
|
|
|
@ -15,4 +15,5 @@ CompilerBuiltinsDetector_errmsg_command_failed=%1$s exited with status %2$d.
|
||||||
CompilerBuiltinsDetector_msg_detection_finished=Detecting compiler built-ins took %d ms.
|
CompilerBuiltinsDetector_msg_detection_finished=Detecting compiler built-ins took %d ms.
|
||||||
CompilerBuiltinsDetector_msg_detection_start=%1$s Detecting compiler built-ins for project '%2$s'
|
CompilerBuiltinsDetector_msg_detection_start=%1$s Detecting compiler built-ins for project '%2$s'
|
||||||
CompilerBuiltinsDetector_msg_unexpectedly_still_running=%1$s is unexpectedly still running. Some built-ins might not have been captured by the compiler built-ins detector.
|
CompilerBuiltinsDetector_msg_unexpectedly_still_running=%1$s is unexpectedly still running. Some built-ins might not have been captured by the compiler built-ins detector.
|
||||||
|
CompilerBuiltinsDetector_errmsg_determine_PATH_failed=Cannot determine PATH variable for project '%1$s'
|
||||||
DetectorConsole_title=Compiler Built-ins Detection Console
|
DetectorConsole_title=Compiler Built-ins Detection Console
|
||||||
|
|
Loading…
Add table
Reference in a new issue