Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2016-04-27 20:44:47 +0000
committerDoug Schaefer2016-04-28 15:14:07 +0000
commit7139dc2f1e35fc44b92c8e1baf06933624992731 (patch)
treeb773cb3411d11ad1ddae168c23415b195e131015 /build/org.eclipse.cdt.build.gcc.core
parentb2300cbcfe632078ad6b8c4b4b934106e7abbf97 (diff)
downloadorg.eclipse.cdt-7139dc2f1e35fc44b92c8e1baf06933624992731.tar.gz
org.eclipse.cdt-7139dc2f1e35fc44b92c8e1baf06933624992731.tar.xz
org.eclipse.cdt-7139dc2f1e35fc44b92c8e1baf06933624992731.zip
Modernize Arduino plug-ins. Adjust APIs to suite.
Diffstat (limited to 'build/org.eclipse.cdt.build.gcc.core')
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/plugin.xml13
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java161
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChainType.java28
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/GCCPathToolChainProvider.java97
-rw-r--r--build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java33
5 files changed, 116 insertions, 216 deletions
diff --git a/build/org.eclipse.cdt.build.gcc.core/plugin.xml b/build/org.eclipse.cdt.build.gcc.core/plugin.xml
index 47c2c1028ff..596c7623f67 100644
--- a/build/org.eclipse.cdt.build.gcc.core/plugin.xml
+++ b/build/org.eclipse.cdt.build.gcc.core/plugin.xml
@@ -2,19 +2,14 @@
<?eclipse version="3.4"?>
<plugin>
<extension
- point="org.eclipse.cdt.core.toolChainType">
- <toolChainType
- class="org.eclipse.cdt.build.gcc.core.GCCToolChainType"
- id="org.eclipse.cdt.build.gcc">
- </toolChainType>
- </extension>
- <extension
point="org.eclipse.cdt.core.toolChainProvider">
<provider
- class="org.eclipse.cdt.build.gcc.core.internal.GCCPathToolChainProvider">
+ class="org.eclipse.cdt.build.gcc.core.internal.GCCPathToolChainProvider"
+ id="org.eclipse.cdt.build.gcc.core.gccPathProvider">
</provider>
<provider
- class="org.eclipse.cdt.build.gcc.core.internal.Msys2ToolChainProvider">
+ class="org.eclipse.cdt.build.gcc.core.internal.Msys2ToolChainProvider"
+ id="org.eclipse.cdt.build.gcc.core.msys2Provider">
</provider>
</extension>
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 5d7c5211fc3..38a8de16414 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
@@ -26,7 +26,7 @@ import java.util.regex.Pattern;
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.build.IToolChainProvider;
import org.eclipse.cdt.core.envvar.EnvironmentVariable;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
@@ -41,45 +41,47 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject;
/**
- * The GCC toolchain. Placing it in cdt.core for now.
- *
- * TODO move to it's own plug-in.
- *
- * @since 5.12
+ * The GCC toolchain. This is the base class for all GCC toolchains. It represents GCC as found on
+ * the user's PATH. It can be overriden to change environment variable settings.
*/
public class GCCToolChain extends PlatformObject implements IToolChain {
- private final IToolChainType type;
+ private final IToolChainProvider provider;
private final String name;
- private final 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;
- this.command = command;
- getVersion(path.resolve(command).toString());
- this.name = command + '-' + version;
- this.path = path;
+ private final Path path;
+ private final String prefix;
+ private final IEnvironmentVariable pathVar;
+ private final IEnvironmentVariable[] envVars;
+
+ protected String[] compileCommands;
+
+ public GCCToolChain(IToolChainProvider provider, String name) {
+ this(provider, name, null, null);
+ }
- pathVar = new EnvironmentVariable("PATH", path.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
- File.pathSeparator);
- envVars = new IEnvironmentVariable[] { pathVar };
+ public GCCToolChain(IToolChainProvider provider, String name, Path path) {
+ this(provider, name, path, null);
}
- protected GCCToolChain(IToolChainType type, String name, String command) {
- this.type = type;
+ public GCCToolChain(IToolChainProvider provider, String name, Path path, String prefix) {
+ this.provider = provider;
this.name = name;
- this.command = command;
- // TODO need to pull the other info out of preferences
+ this.path = path;
+ this.prefix = prefix;
+
+ if (path != null) {
+ pathVar = new EnvironmentVariable("PATH", path.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
+ File.pathSeparator);
+ envVars = new IEnvironmentVariable[] { pathVar };
+ } else {
+ pathVar = null;
+ envVars = new IEnvironmentVariable[0];
+ }
}
@Override
- public IToolChainType getType() {
- return type;
+ public IToolChainProvider getProvider() {
+ return provider;
}
@Override
@@ -89,8 +91,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
@Override
public String getProperty(String key) {
- // TODO for now assume it's a local gcc
- // Later use the target, especially to find out arch
+ // this class represents a local toolchain
switch (key) {
case ATTR_OS:
return Platform.getOS();
@@ -100,36 +101,6 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
return null;
}
- private static Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$
- private static Pattern targetPattern = Pattern.compile("Target: (.*)"); //$NON-NLS-1$
-
- private void getVersion(String command) {
- try {
- Process proc = new ProcessBuilder(new String[] { command, "-v" }).redirectErrorStream(true) //$NON-NLS-1$
- .start();
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()))) {
- for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- Matcher versionMatcher = versionPattern.matcher(line);
- if (versionMatcher.matches()) {
- version = line.trim();
- continue;
- }
- Matcher targetMatcher = targetPattern.matcher(line);
- if (targetMatcher.matches()) {
- target = targetMatcher.group(1);
- continue;
- }
- }
- }
- } catch (IOException e) {
- Activator.log(e);
- }
- }
-
- public String getTarget() {
- return target;
- }
-
protected void addDiscoveryOptions(List<String> command) {
command.add("-E"); //$NON-NLS-1$
command.add("-P"); //$NON-NLS-1$
@@ -142,12 +113,12 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
IExtendedScannerInfo baseScannerInfo, IResource resource, URI buildDirectoryURI) {
try {
Path buildDirectory = Paths.get(buildDirectoryURI);
-
+
List<String> commandLine = new ArrayList<>();
if (command.isAbsolute()) {
commandLine.add(command.toString());
} else {
- commandLine.add(path.resolve(command).toString());
+ commandLine.add(getCommandPath(command).toString());
}
if (baseScannerInfo != null && baseScannerInfo.getIncludePaths() != null) {
@@ -160,12 +131,18 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
commandLine.addAll(Arrays.asList(args));
// Change output to stdout
+ boolean haveOut = false;
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$
+ haveOut = true;
break;
}
}
+ if (!haveOut) {
+ commandLine.add("-o"); //$NON-NLS-1$
+ commandLine.add("-"); //$NON-NLS-1$
+ }
// Change source file to a tmp file (needs to be empty)
Path tmpFile = null;
@@ -259,7 +236,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
@Override
public IEnvironmentVariable getVariable(String name) {
- if (pathVar.getName().equals(name)) {
+ if (path != null && name.equals("PATH")) { //$NON-NLS-1$
return pathVar;
}
return null;
@@ -271,30 +248,46 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
}
@Override
- public Path getCommandPath(String command) {
- return path.resolve(command);
+ public Path getCommandPath(Path command) {
+ if (command.isAbsolute()) {
+ return command;
+ }
+
+ if (path != null) {
+ return path.resolve(command);
+ }
+
+ // Look for it in the path environment var
+ String path = System.getenv("PATH"); //$NON-NLS-1$
+ for (String entry : path.split(File.pathSeparator)) {
+ Path entryPath = Paths.get(entry);
+ Path cmdPath = entryPath.resolve(command);
+ if (Files.isExecutable(cmdPath)) {
+ return cmdPath;
+ }
+ }
+
+ return null;
}
@Override
- public IResource[] getResourcesFromCommand(String[] cmd, URI buildDirectoryURI) {
- // Make sure this is our command
- boolean found = false;
- for (String arg : cmd) {
- if (arg.startsWith("-")) { //$NON-NLS-1$
- break;
- }
- Path cmdPath = Paths.get(arg);
- if (cmdPath.getFileName().toString().equals(command)) {
- found = true;
- break;
+ public String[] getCompileCommands() {
+ if (compileCommands == null) {
+ List<String> cmds = new ArrayList<>();
+ for (String cmd : new String[] { "gcc", "g++", "clang", "clang++" }) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ cmd = prefix != null ? cmd : prefix + cmd;
+ Path cmdPath = getCommandPath(Paths.get(cmd));
+ if (cmdPath != null) {
+ cmds.add(cmd);
+ }
}
+ compileCommands = cmds.toArray(new String[compileCommands.length]);
}
-
- if (!found) {
- // not our command
- return null;
- }
-
+ return compileCommands;
+ }
+
+ @Override
+ public IResource[] getResourcesFromCommand(String[] cmd, URI buildDirectoryURI) {
// Start at the back looking for arguments
List<IResource> resources = new ArrayList<>();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
@@ -308,7 +301,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
resources.add(resource);
}
}
-
+
return resources.toArray(new IResource[resources.size()]);
}
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
deleted file mode 100644
index 20f24bbf639..00000000000
--- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChainType.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2015 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;
-
-import org.eclipse.cdt.core.build.IToolChain;
-import org.eclipse.cdt.core.build.IToolChainType;
-
-public class GCCToolChainType implements IToolChainType {
-
- public static final String ID = "org.eclipse.cdt.build.gcc"; //$NON-NLS-1$
-
- @Override
- public String getId() {
- return ID;
- }
-
- @Override
- 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/internal/GCCPathToolChainProvider.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/GCCPathToolChainProvider.java
index 20bbdb62ced..c057e806bda 100644
--- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/GCCPathToolChainProvider.java
+++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/GCCPathToolChainProvider.java
@@ -11,98 +11,53 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
+import java.util.HashSet;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.
*/
public class GCCPathToolChainProvider implements IToolChainProvider {
- private static Pattern gccPattern = Pattern.compile("(.*-)?(gcc|g\\+\\+|clang|clang\\+\\+)(-[0-9].*)?"); //$NON-NLS-1$
+ private static final String ID = "org.eclipse.cdt.build.gcc.core.gccPathProvider"; //$NON-NLS-1$
- @Override
- public Collection<IToolChain> getToolChains() {
- IToolChainManager manager = Activator.getService(IToolChainManager.class);
- IToolChainType type = null;
-
- List<IToolChain> toolChains = new ArrayList<>();
-
- String path = null;
- for (Entry<String, String> entry : System.getenv().entrySet()) {
- if (entry.getKey().equalsIgnoreCase("PATH")) { //$NON-NLS-1$
- path = entry.getValue();
- break;
- }
- }
-
- if (path != null) {
- Map<String, List<String>> installs = new HashMap<>();
-
- for (String dirStr : path.split(File.pathSeparator)) {
- File dir = new File(dirStr);
- 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);
- }
- }
- }
- }
- }
+ private static final Pattern gccPattern = Pattern.compile("(.*-)?(gcc|g\\+\\+|clang|clang\\+\\+)"); //$NON-NLS-1$
- for (Entry<String, List<String>> entry : installs.entrySet()) {
- String version = entry.getKey();
- String searchStr;
- if (version.contains("LLVM")) {
- searchStr = "clang++";
- } else {
- searchStr = "g++";
- }
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ @Override
+ public void init(IToolChainManager manager) {
+ Set<String> versions = new HashSet<>();
- for (String command : entry.getValue()) {
- if (command.contains(searchStr)) {
- if (type == null) {
- type = manager.getToolChainType(GCCToolChainType.ID);
+ String path = System.getenv("PATH"); //$NON-NLS-1$
+ for (String dirStr : path.split(File.pathSeparator)) {
+ File dir = new File(dirStr);
+ if (dir.isDirectory()) {
+ for (String file : dir.list()) {
+ Matcher matcher = gccPattern.matcher(file);
+ if (matcher.matches()) {
+ String prefix = matcher.group(1);
+ String command = dirStr + File.separatorChar + file;
+ String version = getVersion(command);
+ if (version != null && !versions.contains(version)) {
+ versions.add(version);
+ manager.addToolChain(new GCCToolChain(this, version, dir.toPath(), prefix));
}
- Path commandPath = Paths.get(command);
- toolChains.add(
- new GCCToolChain(type, commandPath.getParent(), commandPath.getFileName().toString()));
- break;
}
}
}
}
-
- return toolChains;
}
-
+
private static Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$
private static Pattern targetPattern = Pattern.compile("Target: (.*)"); //$NON-NLS-1$
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
index 7d452f57cfb..263453a0950 100644
--- 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
@@ -9,30 +9,28 @@ 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 {
+ private static final String ID = "org.eclipse.cdt.build.gcc.core.msys2Provider"; //$NON-NLS-1$
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
@Override
- public Collection<IToolChain> getToolChains() {
+ public void init(IToolChainManager manager) {
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$
@@ -40,24 +38,11 @@ public class Msys2ToolChainProvider implements IToolChainProvider {
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()));
+ manager.addToolChain(new GCCToolChain(this, "msys2.x86_64", gccPath.getParent())); //$NON-NLS-1$
}
}
}
-
- if (toolChains != null) {
- return toolChains;
- }
}
- // default
- return Collections.emptyList();
}
}

Back to the top