Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2016-03-31 15:28:28 +0000
committerGerrit Code Review @ Eclipse.org2016-04-14 20:19:37 +0000
commit6e1b9b408de9c7854c9f7434089c920dbad2b9ad (patch)
tree6e6023f16f3b534bdac1bcc3e90be098c308488f /build/org.eclipse.cdt.build.gcc.core/src/org
parentad0d665a196aa7a389d8a5c54edd0286641ed1ae (diff)
downloadorg.eclipse.cdt-6e1b9b408de9c7854c9f7434089c920dbad2b9ad.tar.gz
org.eclipse.cdt-6e1b9b408de9c7854c9f7434089c920dbad2b9ad.tar.xz
org.eclipse.cdt-6e1b9b408de9c7854c9f7434089c920dbad2b9ad.zip
Tighter integration of new build system with cdt.core.
Move the new build system to cdt.core and remove the previous plugins. Hook the new system into scanner info and environment variable manager. Clean up API in preparation for Neon and API lockdown. Hook up Qt to the new APIs. Add discovery of MSYS2's toolchain and Qt and Qt's MinGW toolchain. Change-Id: I85b1a91da4a44e86f0e9da9310f8106c894623e0
Diffstat (limited to 'build/org.eclipse.cdt.build.gcc.core/src/org')
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java274
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChainType.java7
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/GCCPathToolChainProvider.java (renamed from build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCPathToolChainProvider.java)41
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java63
4 files changed, 221 insertions, 164 deletions
diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
index 974aa96a8be..8d16e94a719 100644
--- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
+++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
@@ -8,34 +8,33 @@
package org.eclipse.cdt.build.gcc.core;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.cdt.build.core.CConsoleParser;
-import org.eclipse.cdt.build.core.IToolChain;
-import org.eclipse.cdt.build.core.IToolChainType;
import org.eclipse.cdt.build.gcc.core.internal.Activator;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.IToolChainType;
+import org.eclipse.cdt.core.envvar.EnvironmentVariable;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
+import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.launchbar.core.target.ILaunchTarget;
-import org.eclipse.launchbar.core.target.ILaunchTargetManager;
-import org.osgi.service.prefs.Preferences;
+import org.eclipse.core.runtime.PlatformObject;
/**
* The GCC toolchain. Placing it in cdt.core for now.
@@ -44,19 +43,25 @@ import org.osgi.service.prefs.Preferences;
*
* @since 5.12
*/
-public class GCCToolChain implements IToolChain {
+public class GCCToolChain extends PlatformObject implements IToolChain {
private final IToolChainType type;
private final String name;
- private String command;
private String version;
private String target;
+ private Path path;
+ private IEnvironmentVariable pathVar;
+ private IEnvironmentVariable[] envVars;
public GCCToolChain(IToolChainType type, Path path, String command) {
this.type = type;
getVersion(path.resolve(command).toString());
this.name = command + '-' + version;
- this.command = command;
+ this.path = path;
+
+ pathVar = new EnvironmentVariable("PATH", path.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
+ File.pathSeparator);
+ envVars = new IEnvironmentVariable[] { pathVar };
}
protected GCCToolChain(IToolChainType type, String name) {
@@ -76,8 +81,16 @@ public class GCCToolChain implements IToolChain {
}
@Override
- public String getCommand() {
- return command;
+ public String getProperty(String key) {
+ // TODO for now assume it's a local gcc
+ // Later use the target, especially to find out arch
+ switch (key) {
+ case ATTR_OS:
+ return Platform.getOS();
+ case ATTR_ARCH:
+ return Platform.getOSArch();
+ }
+ return null;
}
private static Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$
@@ -106,13 +119,6 @@ public class GCCToolChain implements IToolChain {
}
}
- @Override
- public void setEnvironment(Map<String, String> env) {
- // TODO Auto-generated method stub
- // The base one could just assume the toolchain is already set up in the
- // user's env
- }
-
protected void addDiscoveryOptions(List<String> command) {
command.add("-E"); //$NON-NLS-1$
command.add("-P"); //$NON-NLS-1$
@@ -121,151 +127,137 @@ public class GCCToolChain implements IToolChain {
}
@Override
- public IExtendedScannerInfo getScannerInfo(String command, List<String> args, List<String> includePaths,
- IResource resource, Path buildDirectory) throws IOException {
- List<String> commandLine = new ArrayList<>();
- commandLine.add(command);
+ public IExtendedScannerInfo getScannerInfo(IBuildConfiguration buildConfig, Path command, List<String> args,
+ List<String> includePaths, IResource resource, Path buildDirectory) {
+ try {
+ List<String> commandLine = new ArrayList<>();
+ if (command.isAbsolute()) {
+ commandLine.add(command.toString());
+ } else {
+ commandLine.add(path.resolve(command).toString());
+ }
- for (String includePath : includePaths) {
- commandLine.add("-I" + includePath); //$NON-NLS-1$
- }
+ for (String includePath : includePaths) {
+ commandLine.add("-I" + includePath); //$NON-NLS-1$
+ }
- addDiscoveryOptions(commandLine);
- commandLine.addAll(args);
+ addDiscoveryOptions(commandLine);
+ commandLine.addAll(args);
- // Change output to stdout
- for (int i = 0; i < commandLine.size() - 1; ++i) {
- if (commandLine.get(i).equals("-o")) { //$NON-NLS-1$
- commandLine.set(i + 1, "-"); //$NON-NLS-1$
- break;
+ // Change output to stdout
+ for (int i = 0; i < commandLine.size() - 1; ++i) {
+ if (commandLine.get(i).equals("-o")) { //$NON-NLS-1$
+ commandLine.set(i + 1, "-"); //$NON-NLS-1$
+ break;
+ }
}
- }
- // Change source file to a tmp file (needs to be empty)
- Path tmpFile = null;
- for (int i = 1; i < commandLine.size(); ++i) {
- if (!commandLine.get(i).startsWith("-")) { //$NON-NLS-1$
- // TODO optimize by dealing with multi arg options like -o
- Path filePath = buildDirectory.resolve(commandLine.get(i));
- IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filePath.toUri());
- if (files.length > 0) {
- // replace it with a temp file
- Path parentPath = filePath.getParent();
- String extension = files[0].getFileExtension();
- if (extension == null) {
- // Not sure if this is a reasonable choice when there's
- // no extension
- extension = ".cpp"; //$NON-NLS-1$
- } else {
- extension = '.' + extension;
+ // Change source file to a tmp file (needs to be empty)
+ Path tmpFile = null;
+ for (int i = 1; i < commandLine.size(); ++i) {
+ if (!commandLine.get(i).startsWith("-")) { //$NON-NLS-1$
+ // TODO optimize by dealing with multi arg options like -o
+ Path filePath = buildDirectory.resolve(commandLine.get(i));
+ IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filePath.toUri());
+ if (files.length > 0) {
+ // replace it with a temp file
+ Path parentPath = filePath.getParent();
+ String extension = files[0].getFileExtension();
+ if (extension == null) {
+ // Not sure if this is a reasonable choice when
+ // there's
+ // no extension
+ extension = ".cpp"; //$NON-NLS-1$
+ } else {
+ extension = '.' + extension;
+ }
+ tmpFile = Files.createTempFile(parentPath, ".sc", extension); //$NON-NLS-1$
+ commandLine.set(i, tmpFile.toString());
}
- tmpFile = Files.createTempFile(parentPath, ".sc", extension); //$NON-NLS-1$
- commandLine.set(i, tmpFile.toString());
}
}
- }
- if (tmpFile == null) {
- // Have to assume there wasn't a source file. Add one in the
- // resource's container
- IPath parentPath = resource instanceof IFile ? resource.getParent().getLocation() : resource.getLocation();
- tmpFile = Files.createTempFile(parentPath.toFile().toPath(), ".sc", ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
- commandLine.add(tmpFile.toString());
- }
-
- Files.createDirectories(buildDirectory);
-
- // Startup the command
- ProcessBuilder processBuilder = new ProcessBuilder(commandLine).directory(buildDirectory.toFile())
- .redirectErrorStream(true);
- setEnvironment(processBuilder.environment());
- Process process = processBuilder.start();
+ if (tmpFile == null) {
+ // Have to assume there wasn't a source file. Add one in the
+ // resource's container
+ IPath parentPath = resource instanceof IFile ? resource.getParent().getLocation()
+ : resource.getLocation();
+ tmpFile = Files.createTempFile(parentPath.toFile().toPath(), ".sc", ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
+ commandLine.add(tmpFile.toString());
+ }
- // Scan for the scanner info
- Map<String, String> symbols = new HashMap<>();
- List<String> includePath = new ArrayList<>();
- Pattern definePattern = Pattern.compile("#define (.*)\\s(.*)"); //$NON-NLS-1$
- boolean inIncludePaths = false;
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
- for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- if (inIncludePaths) {
- if (line.equals("End of search list.")) { //$NON-NLS-1$
- inIncludePaths = false;
- } else {
- includePath.add(line.trim());
- }
- } else if (line.startsWith("#define ")) { //$NON-NLS-1$
- Matcher matcher = definePattern.matcher(line);
- if (matcher.matches()) {
- symbols.put(matcher.group(1), matcher.group(2));
+ Files.createDirectories(buildDirectory);
+
+ // Startup the command
+ ProcessBuilder processBuilder = new ProcessBuilder(commandLine).directory(buildDirectory.toFile())
+ .redirectErrorStream(true);
+ CCorePlugin.getDefault().getBuildEnvironmentManager().setEnvironment(processBuilder.environment(),
+ buildConfig, true);
+ Process process = processBuilder.start();
+
+ // Scan for the scanner info
+ Map<String, String> symbols = new HashMap<>();
+ List<String> includePath = new ArrayList<>();
+ Pattern definePattern = Pattern.compile("#define (.*)\\s(.*)"); //$NON-NLS-1$
+ boolean inIncludePaths = false;
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ if (inIncludePaths) {
+ if (line.equals("End of search list.")) { //$NON-NLS-1$
+ inIncludePaths = false;
+ } else {
+ includePath.add(line.trim());
+ }
+ } else if (line.startsWith("#define ")) { //$NON-NLS-1$
+ Matcher matcher = definePattern.matcher(line);
+ if (matcher.matches()) {
+ symbols.put(matcher.group(1), matcher.group(2));
+ }
+ } else if (line.equals("#include <...> search starts here:")) { //$NON-NLS-1$
+ inIncludePaths = true;
}
- } else if (line.equals("#include <...> search starts here:")) { //$NON-NLS-1$
- inIncludePaths = true;
}
}
- }
- try {
- process.waitFor();
- } catch (InterruptedException e) {
+ try {
+ process.waitFor();
+ } catch (InterruptedException e) {
+ Activator.log(e);
+ }
+ Files.delete(tmpFile);
+
+ return new ExtendedScannerInfo(symbols, includePath.toArray(new String[includePath.size()]));
+ } catch (IOException e) {
Activator.log(e);
+ return null;
}
- Files.delete(tmpFile);
-
- return new ExtendedScannerInfo(symbols, includePath.toArray(new String[includePath.size()]));
}
@Override
- public Collection<CConsoleParser> getConsoleParsers() {
- // ../src/Test.cpp:4:1: error: 'x' was not declared in this scope
- return Arrays.asList(new CConsoleParser("(.*?):(\\d+):(\\d+:)? (fatal )?error: (.*)") { //$NON-NLS-1$
- @Override
- protected int getSeverity(Matcher matcher) {
- return IMarker.SEVERITY_ERROR;
- }
-
- @Override
- protected String getMessage(Matcher matcher) {
- return matcher.group(5);
- }
-
- @Override
- protected int getLineNumber(Matcher matcher) {
- return Integer.parseInt(matcher.group(2));
- }
-
- @Override
- protected String getFileName(Matcher matcher) {
- return matcher.group(1);
- }
-
- @Override
- protected int getLinkOffset(Matcher matcher) {
- return 0;
- }
-
- @Override
- protected int getLinkLength(Matcher matcher) {
- return matcher.group(1).length() + 1 + matcher.group(2).length() + 1 + matcher.group(3).length();
- }
- });
+ public String[] getErrorParserIds() {
+ return new String[] { "org.eclipse.cdt.core.GCCErrorParser", //$NON-NLS-1$
+ "org.eclipse.cdt.core.GASErrorParser", //$NON-NLS-1$
+ "org.eclipse.cdt.core.GLDErrorParser", //$NON-NLS-1$
+ "org.eclipse.cdt.core.GmakeErrorParser", //$NON-NLS-1$
+ "org.eclipse.cdt.core.CWDLocator" //$NON-NLS-1$
+ };
}
@Override
- public boolean supports(ILaunchTarget target) {
- if (target.getTypeId().equals(ILaunchTargetManager.localLaunchTargetTypeId)) {
- switch (Platform.getOS()) {
- case Platform.OS_MACOSX:
- return this.target.contains("apple-darwin"); //$NON-NLS-1$
- }
- return true;
+ public IEnvironmentVariable getVariable(String name) {
+ if (pathVar.getName().equals(name)) {
+ return pathVar;
}
- return false;
+ return null;
}
@Override
- public void save(Preferences properties) {
- // TODO Auto-generated method stub
-
+ public IEnvironmentVariable[] getVariables() {
+ return envVars;
}
+ @Override
+ public Path getCommandPath(String command) {
+ return path.resolve(command);
+ }
+
}
diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChainType.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChainType.java
index f9298f4443b..20f24bbf639 100644
--- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChainType.java
+++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChainType.java
@@ -7,9 +7,8 @@
*******************************************************************************/
package org.eclipse.cdt.build.gcc.core;
-import org.eclipse.cdt.build.core.IToolChain;
-import org.eclipse.cdt.build.core.IToolChainType;
-import org.osgi.service.prefs.Preferences;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.IToolChainType;
public class GCCToolChainType implements IToolChainType {
@@ -21,7 +20,7 @@ public class GCCToolChainType implements IToolChainType {
}
@Override
- public IToolChain getToolChain(String name, Preferences properties) {
+ public IToolChain getToolChain(String name) {
// TODO Auto-generated method stub
return null;
}
diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCPathToolChainProvider.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/GCCPathToolChainProvider.java
index 1e8ba8622f7..38e530fe318 100644
--- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCPathToolChainProvider.java
+++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/GCCPathToolChainProvider.java
@@ -5,7 +5,7 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
-package org.eclipse.cdt.build.gcc.core;
+package org.eclipse.cdt.build.gcc.core.internal;
import java.io.BufferedReader;
import java.io.File;
@@ -22,11 +22,12 @@ import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.cdt.build.core.IToolChain;
-import org.eclipse.cdt.build.core.IToolChainManager;
-import org.eclipse.cdt.build.core.IToolChainProvider;
-import org.eclipse.cdt.build.core.IToolChainType;
-import org.eclipse.cdt.build.gcc.core.internal.Activator;
+import org.eclipse.cdt.build.gcc.core.GCCToolChain;
+import org.eclipse.cdt.build.gcc.core.GCCToolChainType;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.IToolChainManager;
+import org.eclipse.cdt.core.build.IToolChainProvider;
+import org.eclipse.cdt.core.build.IToolChainType;
/**
* Finds gcc and clang on the path.
@@ -55,20 +56,22 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
for (String dirStr : path.split(File.pathSeparator)) {
File dir = new File(dirStr);
- for (String file : dir.list()) {
- Matcher matcher = gccPattern.matcher(file);
- if (matcher.matches()) {
- String prefix = matcher.group(1);
- String suffix = matcher.group(3);
- String command = dirStr + File.separatorChar + file;
- String version = getVersion(command);
- if (version != null) {
- List<String> commands = installs.get(version);
- if (commands == null) {
- commands = new ArrayList<>();
- installs.put(version, commands);
+ if (dir.isDirectory()) {
+ for (String file : dir.list()) {
+ Matcher matcher = gccPattern.matcher(file);
+ if (matcher.matches()) {
+ String prefix = matcher.group(1);
+ String suffix = matcher.group(3);
+ String command = dirStr + File.separatorChar + file;
+ String version = getVersion(command);
+ if (version != null) {
+ List<String> commands = installs.get(version);
+ if (commands == null) {
+ commands = new ArrayList<>();
+ installs.put(version, commands);
+ }
+ commands.add(command);
}
- commands.add(command);
}
}
}
diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java
new file mode 100644
index 00000000000..7d452f57cfb
--- /dev/null
+++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.build.gcc.core.internal;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.cdt.build.gcc.core.GCCToolChain;
+import org.eclipse.cdt.build.gcc.core.GCCToolChainType;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.IToolChainManager;
+import org.eclipse.cdt.core.build.IToolChainProvider;
+import org.eclipse.cdt.core.build.IToolChainType;
+import org.eclipse.cdt.utils.WindowsRegistry;
+import org.eclipse.core.runtime.Platform;
+
+public class Msys2ToolChainProvider implements IToolChainProvider {
+
+ @Override
+ public Collection<IToolChain> getToolChains() {
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ WindowsRegistry registry = WindowsRegistry.getRegistry();
+ String uninstallKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; //$NON-NLS-1$
+ String subkey;
+ List<IToolChain> toolChains = null;
+ IToolChainType type = null;
+ for (int i = 0; (subkey = registry.getCurrentUserKeyName(uninstallKey, i)) != null; i++) {
+ String compKey = uninstallKey + '\\' + subkey;
+ String displayName = registry.getCurrentUserValue(compKey, "DisplayName"); //$NON-NLS-1$
+ if ("MSYS2 64bit".equals(displayName)) { //$NON-NLS-1$
+ String installLocation = registry.getCurrentUserValue(compKey, "InstallLocation"); //$NON-NLS-1$
+ Path gccPath = Paths.get(installLocation + "\\mingw64\\bin\\gcc.exe"); //$NON-NLS-1$
+ if (Files.exists(gccPath)) {
+ if (toolChains == null) {
+ toolChains = new ArrayList<>();
+ }
+ if (type == null) {
+ type = Activator.getService(IToolChainManager.class).getToolChainType(GCCToolChainType.ID);
+ }
+ toolChains.add(
+ new GCCToolChain(type, gccPath.getParent(), gccPath.getFileName().toString()));
+ }
+ }
+ }
+
+ if (toolChains != null) {
+ return toolChains;
+ }
+ }
+ // default
+ return Collections.emptyList();
+ }
+
+}

Back to the top