Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDoug Schaefer2015-09-25 21:01:37 +0000
committerGerrit Code Review @ Eclipse.org2015-09-28 17:24:41 +0000
commit64bf3c4f69e00d4246552505d67521ce2167178c (patch)
treec25a42b9c579136a03be4c3e3eb896b040f70c9a /core
parent7ba4959cf4293cbd17726f22b49d89c6bc444b04 (diff)
downloadorg.eclipse.cdt-64bf3c4f69e00d4246552505d67521ce2167178c.tar.gz
org.eclipse.cdt-64bf3c4f69e00d4246552505d67521ce2167178c.tar.xz
org.eclipse.cdt-64bf3c4f69e00d4246552505d67521ce2167178c.zip
Starting to put Qt onto the new build system and launch.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/build/GCCTests.java17
-rw-r--r--core/org.eclipse.cdt.core/.classpath4
-rw-r--r--core/org.eclipse.cdt.core/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--core/org.eclipse.cdt.core/META-INF/MANIFEST.MF3
-rw-r--r--core/org.eclipse.cdt.core/build.properties6
-rw-r--r--core/org.eclipse.cdt.core/plugin.xml18
-rw-r--r--core/org.eclipse.cdt.core/schema/ToolChainFactory.exsd (renamed from core/org.eclipse.cdt.core/schema/ToolChain.exsd)21
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java37
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChain.java114
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChainManager.java127
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainFactory.java22
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/gcc/GCCToolChain.java (renamed from core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/GCCToolChain.java)114
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/gcc/GCCToolChainFactory.java121
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ScannerInfoData.java13
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainScannerInfo.java31
15 files changed, 451 insertions, 203 deletions
diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/build/GCCTests.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/build/GCCTests.java
new file mode 100644
index 0000000000..dfdfbe9eb6
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/build/GCCTests.java
@@ -0,0 +1,17 @@
+package org.eclipse.cdt.core.internal.build;
+
+import java.io.IOException;
+
+import org.eclipse.cdt.core.build.gcc.GCCToolChainFactory;
+import org.junit.Test;
+
+public class GCCTests {
+
+ @Test
+ public void tryGCCDiscovery() throws IOException {
+ long start = System.currentTimeMillis();
+ new GCCToolChainFactory().discover();
+ System.out.println("Time: " + (System.currentTimeMillis() - start));
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/.classpath b/core/org.eclipse.cdt.core/.classpath
index 560b724373..8672427f77 100644
--- a/core/org.eclipse.cdt.core/.classpath
+++ b/core/org.eclipse.cdt.core/.classpath
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="model"/>
<classpathentry kind="src" path="browser"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="utils"/>
<classpathentry kind="src" path="parser"/>
<classpathentry kind="src" path="templateengine"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/core/org.eclipse.cdt.core/.settings/org.eclipse.jdt.core.prefs b/core/org.eclipse.cdt.core/.settings/org.eclipse.jdt.core.prefs
index 11e273c7ae..6244889867 100644
--- a/core/org.eclipse.cdt.core/.settings/org.eclipse.jdt.core.prefs
+++ b/core/org.eclipse.cdt.core/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -77,7 +77,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index bd44f8fcfd..43cabd3e52 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.browser,
org.eclipse.cdt.core.build,
+ org.eclipse.cdt.core.build.gcc,
org.eclipse.cdt.core.cdtvariables,
org.eclipse.cdt.core.dom,
org.eclipse.cdt.core.dom.ast,
@@ -130,4 +131,4 @@ Require-Bundle: org.eclipse.cdt.core.native;bundle-version="[5.7.0,6.0.0)";visib
com.ibm.icu;bundle-version="4.4.2",
com.google.gson;bundle-version="2.2.4"
Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/core/org.eclipse.cdt.core/build.properties b/core/org.eclipse.cdt.core/build.properties
index dbbe7f7419..49e306809f 100644
--- a/core/org.eclipse.cdt.core/build.properties
+++ b/core/org.eclipse.cdt.core/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2014 IBM Corporation and others.
+# Copyright (c) 2003, 2015 IBM Corporation 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
@@ -30,7 +30,3 @@ source.. = src/,\
browser/,\
templateengine/,\
utils/
-
-jre.compilation.profile=JavaSE-1.7
-javacSource=1.7
-javacTarget=1.7
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index f258d41eec..dd0c96dd82 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -683,7 +683,7 @@
<extension-point id="LanguageSettingsProvider" name="%LanguageSettingsProvider.name" schema="schema/LanguageSettingsProvider.exsd"/>
<extension-point id="UNCPathConverter" name="%uncPathConverter.name" schema="schema/UNCPathConverter.exsd"/>
<extension-point id="ProblemMarkerFilter" name="%problemMarkerFilter.name" schema="schema/ProblemMarkerFilter.exsd"/>
- <extension-point id="ToolChain" name="ToolChain" schema="schema/ToolChain.exsd"/>
+ <extension-point id="ToolChainFactory" name="Tool Chain Factory" schema="schema/ToolChainFactory.exsd"/>
<extension
point="org.eclipse.cdt.core.templateProcessTypes">
@@ -858,20 +858,10 @@
</filterMatcher>
</extension>
<extension
- point="org.eclipse.cdt.core.ToolChain">
- <toolChain
- adaptor="org.eclipse.cdt.core.build.GCCToolChain"
- id="org.eclipse.cdt.core.gcc">
- </toolChain>
- </extension>
- <extension
- point="org.eclipse.core.runtime.adapters">
+ point="org.eclipse.cdt.core.ToolChainFactory">
<factory
- adaptableType="org.eclipse.cdt.core.build.CBuildConfiguration"
- class="org.eclipse.cdt.core.build.GCCToolChain$Factory">
- <adapter
- type="org.eclipse.cdt.core.build.GCCToolChain">
- </adapter>
+ class="org.eclipse.cdt.core.build.gcc.GCCToolChainFactory"
+ family="GCC">
</factory>
</extension>
diff --git a/core/org.eclipse.cdt.core/schema/ToolChain.exsd b/core/org.eclipse.cdt.core/schema/ToolChainFactory.exsd
index c421b87247..bc18ce610a 100644
--- a/core/org.eclipse.cdt.core/schema/ToolChain.exsd
+++ b/core/org.eclipse.cdt.core/schema/ToolChainFactory.exsd
@@ -3,7 +3,7 @@
<schema targetNamespace="org.eclipse.cdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
- <meta.schema plugin="org.eclipse.cdt.core" id="ToolChain" name="ToolChain"/>
+ <meta.schema plugin="org.eclipse.cdt.core" id="ToolChainFactory" name="Tool Chain Factory"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
@@ -18,7 +18,7 @@
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
- <element ref="toolChain"/>
+ <element ref="factory"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
@@ -47,27 +47,22 @@
</complexType>
</element>
- <element name="toolChain">
- <annotation>
- <documentation>
- A toolchain that implements the CToolChain interface and identified with the id attribute.
- </documentation>
- </annotation>
+ <element name="factory">
<complexType>
- <attribute name="id" type="string" use="required">
+ <attribute name="family" type="string" use="required">
<annotation>
<documentation>
- id for the toolchain.
+
</documentation>
</annotation>
</attribute>
- <attribute name="adaptor" type="string" use="required">
+ <attribute name="class" type="string" use="required">
<annotation>
<documentation>
- The adaptor class for the toolchain. This is passed to getAdaptor on the CBuildConfiguration object.
+
</documentation>
<appInfo>
- <meta.attribute kind="java" basedOn="org.eclipse.cdt.core.build.CToolChain:"/>
+ <meta.attribute kind="java" basedOn=":org.eclipse.cdt.core.build.IToolChainFactory"/>
</appInfo>
</annotation>
</attribute>
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java
index 62034ee006..ff28c16cbb 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java
@@ -8,7 +8,11 @@
package org.eclipse.cdt.core.build;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.internal.core.build.ScannerInfoData;
+import org.eclipse.cdt.internal.core.build.ToolChainScannerInfo;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
@@ -39,6 +43,7 @@ public abstract class CBuildConfiguration extends PlatformObject {
private final IBuildConfiguration config;
private CToolChain toolChain;
+ private ScannerInfoData scannerInfoData;
protected CBuildConfiguration(IBuildConfiguration config) {
this.config = config;
@@ -97,23 +102,17 @@ public abstract class CBuildConfiguration extends PlatformObject {
return null;
}
- public synchronized void setToolChain(String id) throws CoreException {
- CToolChain newtc = getToolChain(id);
- if (newtc == null) {
- throw new CoreException(
- new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "unknown toolchain: " + id)); //$NON-NLS-1$
- }
+ public synchronized void setToolChain(CToolChain toolChain) throws CoreException {
+ this.toolChain = toolChain;
IEclipsePreferences settings = getSettings();
- settings.put(TOOLCHAIN, id);
+ settings.put(TOOLCHAIN, toolChain.getId());
try {
settings.flush();
} catch (BackingStoreException e) {
throw new CoreException(
new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "saving toolchain id", e)); //$NON-NLS-1$
}
-
- toolChain = newtc;
}
public CToolChain getToolChain() throws CoreException {
@@ -130,12 +129,26 @@ public abstract class CBuildConfiguration extends PlatformObject {
}
public IScannerInfo getScannerInfo(IResource resource) throws CoreException {
- // By default, get it from the toolchain.
- CToolChain toolChain = getToolChain();
- return toolChain != null ? toolChain.getScannerInfo(resource) : null;
+ return getScannerInfoData().getScannerInfo(resource);
+ }
+
+ public void putScannerInfo(ILanguage language, ExtendedScannerInfo info) {
+ getScannerInfoData().putScannerInfo(language, info);
+ }
+
+ public void putScannerInfo(IResource resource, ToolChainScannerInfo info) {
+ getScannerInfoData().putScannerInfo(resource, info);
+ }
+
+ private ScannerInfoData getScannerInfoData() {
+ if (scannerInfoData == null) {
+ scannerInfoData = ScannerInfoData.load(this);
+ }
+ return scannerInfoData;
}
public void clearScannerInfo() throws CoreException {
+ scannerInfoData = null;
}
public CConsoleParser[] getConsoleParsers() throws CoreException {
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChain.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChain.java
index f027cb4249..4bc6182a1b 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChain.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChain.java
@@ -10,14 +10,12 @@ package org.eclipse.cdt.core.build;
import java.util.List;
import java.util.Map;
-import org.eclipse.cdt.core.model.ILanguage;
-import org.eclipse.cdt.core.parser.IScannerInfo;
-import org.eclipse.cdt.internal.core.build.ScannerInfoData;
-import org.eclipse.cdt.internal.core.build.ToolChainScannerInfo;
+import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject;
+import org.osgi.service.prefs.Preferences;
/**
* Root class for CDT toolchains.
@@ -26,12 +24,38 @@ import org.eclipse.core.runtime.PlatformObject;
*/
public abstract class CToolChain extends PlatformObject {
- private final CBuildConfiguration config;
+ public static final String FAMILY = "family"; //$NON-NLS-1$
+ private static final String NAME = "name"; //$NON-NLS-1$
- private ScannerInfoData scannerInfo;
+ private String id;
+ private String name;
- protected CToolChain(CBuildConfiguration config) {
- this.config = config;
+ protected CToolChain(String id, Preferences settings) {
+ this.id = id;
+ this.name = settings.get(NAME, "<Unknown>"); //$NON-NLS-1$
+ }
+
+ protected CToolChain(String name) {
+ this.name = name;
+ }
+
+ public abstract String getFamily();
+
+ public String getId() {
+ return id;
+ }
+
+ void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void save(Preferences settings) {
+ settings.put(FAMILY, getFamily());
+ settings.put(NAME, name);
}
public static String[] splitCommand(String command) {
@@ -39,8 +63,13 @@ public abstract class CToolChain extends PlatformObject {
return command.replace("\"", "").split("\\s+"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- public CBuildConfiguration getBuildConfiguration() {
- return config;
+ public static String[] fixPaths(String[] command) {
+ for (int i = 0; i < command.length; ++i) {
+ if (command[i].indexOf('\\') >= 0) {
+ command[i] = command[i].replace('\\', '/');
+ }
+ }
+ return command;
}
/**
@@ -53,71 +82,40 @@ public abstract class CToolChain extends PlatformObject {
}
/**
- * Scan the commandLine and save the scanner info for the resource being
- * built, or if perProject is true, for all resources in the project. The
- * buildFolder to help find the resource is where the command ran.
+ * Find the file mentioned in the command line.
*
* @param buildFolder
* @param commandLine
- * @throws CoreException
+ * @return the file in the command line or null if can't be found.
*/
- public void scanBuildOutput(IFolder buildFolder, String commandLine, boolean perProject)
- throws CoreException {
- // default, nothing
- }
-
- protected void putScannerInfo(IResource resource, Map<String, String> definedSymbols,
- List<String> includePaths, List<String> macroFiles, List<String> includeFiles,
- List<String> localIncludePath) throws CoreException {
- if (scannerInfo == null) {
- loadScannerInfo();
- }
- scannerInfo.putScannerInfo(resource, new ToolChainScannerInfo(definedSymbols, includePaths,
- macroFiles, includeFiles, localIncludePath));
- }
-
- protected void putScannerInfo(ILanguage language, Map<String, String> definedSymbols,
- List<String> includePaths, List<String> macroFiles, List<String> includeFiles,
- List<String> localIncludePath) throws CoreException {
- if (scannerInfo == null) {
- loadScannerInfo();
- }
- scannerInfo.putScannerInfo(language, new ToolChainScannerInfo(definedSymbols, includePaths,
- macroFiles, includeFiles, localIncludePath));
+ public IFile getResource(IFolder buildFolder, String[] commandLine) {
+ // default, not found
+ return null;
}
- private void loadScannerInfo() {
- if (scannerInfo == null) {
- scannerInfo = ScannerInfoData.load(this);
- }
+ public IFile getResource(IFolder buildFolder, String commandLine) {
+ return getResource(buildFolder, splitCommand(commandLine));
}
/**
- * Return the scanner info for the given resource.
+ * Calculate the scanner info from the given command line
*
- * @param resource
- * @return scanner info for the resource
+ * @param buildFolder
+ * @param commandLine
+ * @return scanner info, or null if can't be calculated
* @throws CoreException
*/
- public IScannerInfo getScannerInfo(IResource resource) throws CoreException {
- loadScannerInfo();
- return scannerInfo.getScannerInfo(resource);
- }
-
- public void clearScannerInfo() throws CoreException {
- if (scannerInfo == null) {
- scannerInfo = new ScannerInfoData();
- scannerInfo.queueSave();
- } else {
- scannerInfo.clear();
- }
+ public ExtendedScannerInfo getScannerInfo(IFolder buildFolder, List<String> commandLine)
+ throws CoreException {
+ // default, null
+ return null;
}
/**
* Return the console parsers to be used when this toolchain is being used
* for a build.
*
- * @return console parsers
+ * @return console parsers, or null if there aren't any
*/
public CConsoleParser[] getConsoleParsers() {
return null;
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChainManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChainManager.java
new file mode 100644
index 0000000000..4ea9fe4c0b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CToolChainManager.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * 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.core.build;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * Manager that manages the list of toolchains available.
+ *
+ * @since 5.12
+ */
+public class CToolChainManager {
+
+ private static final String TOOLCHAINS = "toolchains"; //$NON-NLS-1$
+
+ public static final CToolChainManager instance = new CToolChainManager();
+
+ private Map<String, IConfigurationElement> toolChainFamilies = new HashMap<>();
+ private Map<String, CToolChain> toolChains = new HashMap<>();
+
+ private CToolChainManager() {
+ new Job("Load toolchains") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ // Load up the families
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint point = registry
+ .getExtensionPoint("org.eclipse.cdt.core.ToolChainFactory"); //$NON-NLS-1$
+ for (IExtension extension : point.getExtensions()) {
+ for (IConfigurationElement element : extension.getConfigurationElements()) {
+ String family = element.getAttribute(CToolChain.FAMILY);
+ if (family != null) {
+ toolChainFamilies.put(family, element);
+ }
+ }
+ }
+
+ // Load up the toolchains
+ Preferences toolChainsPref = getToolChainSettings();
+ for (String toolChainId : toolChainsPref.childrenNames()) {
+ Preferences toolChainPref = toolChainsPref.node(toolChainId);
+ String family = toolChainPref.get(CToolChain.FAMILY, ""); //$NON-NLS-1$
+ if (!family.isEmpty()) {
+ IConfigurationElement element = toolChainFamilies.get(family);
+ if (element != null) {
+ IToolChainFactory factory = (IToolChainFactory) element
+ .createExecutableExtension("class"); //$NON-NLS-1$
+ CToolChain toolChain = factory.createToolChain(toolChainId, toolChainPref);
+ toolChains.put(toolChain.getName(), toolChain);
+ }
+ }
+ }
+ return Status.OK_STATUS;
+ } catch (BackingStoreException e) {
+ return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "loading toolchains", e);
+ } catch (CoreException e) {
+ return e.getStatus();
+ }
+ }
+ }.schedule();
+ }
+
+ private Preferences getToolChainSettings() {
+ return ConfigurationScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).node(TOOLCHAINS);
+ }
+
+ Preferences getSettings(String id) {
+ return getToolChainSettings().node(id);
+ }
+
+ public Collection<CToolChain> getToolChains() {
+ return toolChains.values();
+ }
+
+ public void addToolChain(CToolChain toolChain) throws CoreException {
+ // First find an open id for the toolchain
+ String id = null;
+ for (int i = 0; i < toolChains.size(); ++i) {
+ String istr = String.valueOf(i);
+ if (toolChains.containsKey(istr)) {
+ id = istr;
+ break;
+ }
+ }
+
+ if (id == null) {
+ id = String.valueOf(toolChains.size());
+ }
+
+ toolChain.setId(id);
+ toolChains.put(id, toolChain);
+
+ // save
+ try {
+ Preferences toolChainsPref = getToolChainSettings();
+ toolChain.save(toolChainsPref.node(id));
+ toolChainsPref.flush();
+ } catch (BackingStoreException e) {
+ throw new CoreException(
+ new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "saving toolchain " + id, e));
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainFactory.java
new file mode 100644
index 0000000000..ff310c718a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChainFactory.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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.core.build;
+
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * @since 5.12
+ */
+public interface IToolChainFactory {
+
+ CToolChain createToolChain(String id, Preferences settings);
+
+ default void discover() {
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/GCCToolChain.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/gcc/GCCToolChain.java
index fcda887c2d..5eefd9fbbd 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/GCCToolChain.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/gcc/GCCToolChain.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.core.build;
+package org.eclipse.cdt.core.build.gcc;
import java.io.BufferedReader;
import java.io.File;
@@ -22,19 +22,17 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.build.CConsoleParser;
+import org.eclipse.cdt.core.build.CToolChain;
import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ILanguage;
-import org.eclipse.cdt.core.model.LanguageManager;
+import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.content.IContentType;
+import org.osgi.service.prefs.Preferences;
/**
* The GCC toolchain. Placing it in cdt.core for now.
@@ -45,68 +43,60 @@ import org.eclipse.core.runtime.content.IContentType;
*/
public class GCCToolChain extends CToolChain {
- public static final String ID = "org.eclipse.cdt.core.gcc"; //$NON-NLS-1$
+ public GCCToolChain(String id, Preferences settings) {
+ super(id, settings);
+ }
+
+ public GCCToolChain(String name) {
+ super(name);
+ }
- public GCCToolChain(CBuildConfiguration config) {
- super(config);
+ @Override
+ public String getFamily() {
+ return "GCC"; //$NON-NLS-1$
}
- private static Map<CBuildConfiguration, GCCToolChain> cache = new HashMap<>();
-
- public static class Factory implements IAdapterFactory {
- @SuppressWarnings("unchecked")
- @Override
- public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
- if (adapterType.equals(GCCToolChain.class) && adaptableObject instanceof CBuildConfiguration) {
- CBuildConfiguration config = (CBuildConfiguration) adaptableObject;
- GCCToolChain toolChain = cache.get(config);
- if (toolChain == null) {
- toolChain = new GCCToolChain(config);
- cache.put(config, toolChain);
+ @Override
+ public IFile getResource(IFolder buildFolder, String[] commandLine) {
+ for (String arg : commandLine) {
+ if (!arg.startsWith("-")) { //$NON-NLS-1$
+ // TODO optimize by dealing with multi arg options like -o
+ IFile file = buildFolder.getFile(arg);
+ if (file.exists() && CoreModel.isTranslationUnit(file)) {
+ return file;
}
- return (T) toolChain;
}
- return null;
}
- @Override
- public Class<?>[] getAdapterList() {
- return new Class<?>[] { GCCToolChain.class };
- }
+ return null;
}
@Override
- public void scanBuildOutput(IFolder buildFolder, String commandLine, boolean perProject)
- throws CoreException {
+ public ExtendedScannerInfo getScannerInfo(IFolder buildFolder, List<String> cmd) throws CoreException {
try {
- if (Platform.getOS().equals(Platform.OS_WIN32)) {
- // Need to flip over the slashes on Windows
- commandLine = commandLine.replace('\\', '/');
- }
- String[] command = splitCommand(commandLine);
+ String[] commandLine = cmd.toArray(new String[cmd.size()]);
// Change output to stdout
- for (int i = 0; i < command.length - 1; ++i) {
- if (command[i].equals("-o")) { //$NON-NLS-1$
- command[i + 1] = "-"; //$NON-NLS-1$
+ for (int i = 0; i < commandLine.length - 1; ++i) {
+ if (commandLine[i].equals("-o")) { //$NON-NLS-1$
+ commandLine[i + 1] = "-"; //$NON-NLS-1$
break;
}
}
// Change source file to a tmp file (needs to be empty)
Path tmpFile = null;
- IFile file = null;
- for (int i = 1; i < command.length; ++i) {
- if (!command[i].startsWith("-")) { //$NON-NLS-1$
+ for (int i = 1; i < commandLine.length; ++i) {
+ if (!commandLine[i].startsWith("-")) { //$NON-NLS-1$
// TODO optimize by dealing with multi arg options like -o
- IFile f = buildFolder.getFile(command[i]);
- if (f.exists() && CoreModel.isTranslationUnit(f)) {
+ IFile file = buildFolder.getFile(commandLine[i]);
+ if (file.exists() && CoreModel.isTranslationUnit(file)) {
// replace it with a temp file
- Path parentPath = new File(((IFolder) f.getParent()).getLocationURI()).toPath();
+ Path parentPath = new File(((IFolder) file.getParent()).getLocationURI()).toPath();
int n = 0;
while (true) {
- tmpFile = parentPath.resolve(".sc" + n + "." + f.getFileExtension()); //$NON-NLS-1$ //$NON-NLS-2$
- command[i] = tmpFile.toString();
+ tmpFile = parentPath.resolve(".sc" + n + "." + file.getFileExtension()); //$NON-NLS-1$ //$NON-NLS-2$
+ commandLine[i] = tmpFile.toString();
try {
Files.createFile(tmpFile);
break;
@@ -115,26 +105,20 @@ public class GCCToolChain extends CToolChain {
++n;
}
}
- file = f;
break;
}
}
}
- if (file == null) {
- // can't do much without the source file
- CCorePlugin.log("No source file for scanner discovery"); //$NON-NLS-1$
- return;
- }
-
// Add in the magic potion: -E -P -v -dD
- String[] fullCmd = new String[command.length + 4];
- fullCmd[0] = command[0];
+ String[] fullCmd = new String[commandLine.length + 4];
+ fullCmd[0] = commandLine[0];
fullCmd[1] = "-E"; //$NON-NLS-1$
fullCmd[2] = "-P"; //$NON-NLS-1$
fullCmd[3] = "-v"; //$NON-NLS-1$
fullCmd[4] = "-dD"; //$NON-NLS-1$
- System.arraycopy(command, 1, fullCmd, 5, command.length - 1);
+ System.arraycopy(commandLine, 1, fullCmd, 5, commandLine.length - 1);
+ fixPaths(fullCmd);
File buildDir = new File(buildFolder.getLocationURI());
Files.createDirectories(buildDir.toPath());
@@ -170,23 +154,9 @@ public class GCCToolChain extends CToolChain {
}
}
- if (perProject) {
- IProject project = buildFolder.getProject();
- IContentType contentType = CCorePlugin.getContentType(project, file.getName());
- if (contentType != null) {
- ILanguage language = LanguageManager.getInstance().getLanguage(contentType, project);
- putScannerInfo(language, symbols, includePath, null, null, null);
- }
- } else {
- putScannerInfo(file, symbols, includePath, null, null, null);
- }
-
- if (tmpFile != null) {
- Files.delete(tmpFile);
- }
+ return new ExtendedScannerInfo(symbols, includePath.toArray(new String[includePath.size()]));
} catch (IOException e) {
- throw new CoreException(
- new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Scanning build output", e)); //$NON-NLS-1$
+ throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "scanner info", e)); //$NON-NLS-1$
}
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/gcc/GCCToolChainFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/gcc/GCCToolChainFactory.java
new file mode 100644
index 0000000000..0309a44acc
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/gcc/GCCToolChainFactory.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * 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.core.build.gcc;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.cdt.core.build.CToolChain;
+import org.eclipse.cdt.core.build.IToolChainFactory;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * @since 5.12
+ */
+public class GCCToolChainFactory implements IToolChainFactory {
+
+ private static Pattern gccPattern = Pattern.compile("(.*-)?(gcc|g\\+\\+|clang|clang\\+\\+)(-[0-9].*)?"); //$NON-NLS-1$
+
+ /**
+ * Discover gcc installs that exist on the path.
+ */
+ @Override
+ public void discover() {
+ 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);
+ 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);
+ }
+ }
+ }
+ }
+
+ for (Entry<String, List<String>> entry : installs.entrySet()) {
+ System.out.println(entry.getKey());
+ for (String command : entry.getValue()) {
+ System.out.println("\t" + command);
+ }
+ }
+ }
+ }
+
+ private static Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$
+ private static Pattern targetPattern = Pattern.compile("Target: (.*)"); //$NON-NLS-1$
+
+ private String getVersion(String command) {
+ try {
+ Process proc = new ProcessBuilder(new String[] { command, "-v" }).redirectErrorStream(true) //$NON-NLS-1$
+ .start();
+ String version = null;
+ String target = null;
+ 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;
+ }
+ }
+ }
+ if (version != null) {
+ if (target != null) {
+ return version + " " + target; // $NON-NLS-1$
+ } else {
+ return version;
+ }
+ } else {
+ return null;
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public CToolChain createToolChain(String id, Preferences settings) {
+ return new GCCToolChain(id, settings);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ScannerInfoData.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ScannerInfoData.java
index a9e2083a7b..7da5ae3797 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ScannerInfoData.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ScannerInfoData.java
@@ -21,9 +21,9 @@ import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.build.CBuildConfiguration;
-import org.eclipse.cdt.core.build.CToolChain;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.LanguageManager;
+import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -33,6 +33,10 @@ import org.eclipse.core.runtime.content.IContentType;
import com.google.gson.Gson;
+/**
+ * Class representing scanner info data for a project as stored in the metadata
+ * area.
+ */
public class ScannerInfoData {
private Set<ToolChainScannerInfo> perResourceInfo;
@@ -117,17 +121,16 @@ public class ScannerInfoData {
queueSave();
}
- public void putScannerInfo(ILanguage language, ToolChainScannerInfo info) {
+ public void putScannerInfo(ILanguage language, ExtendedScannerInfo info) {
if (perLanguageInfo == null) {
perLanguageInfo = new HashMap<>();
}
- perLanguageInfo.put(language.getId(), info);
+ perLanguageInfo.put(language.getId(), new ToolChainScannerInfo(info));
queueSave();
}
- public static ScannerInfoData load(CToolChain toolChain) {
+ public static ScannerInfoData load(CBuildConfiguration config) {
IPath stateLoc = Platform.getStateLocation(CCorePlugin.getDefault().getBundle());
- CBuildConfiguration config = toolChain.getBuildConfiguration();
IPath scannerInfoPath = stateLoc.append(config.getProject().getName())
.append(config.getName() + ".scInfo"); //$NON-NLS-1$
File scannerInfoFile = scannerInfoPath.toFile();
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainScannerInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainScannerInfo.java
index 0ee5c726d4..050991bcf2 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainScannerInfo.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainScannerInfo.java
@@ -10,7 +10,6 @@ package org.eclipse.cdt.internal.core.build;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,31 +19,27 @@ import org.eclipse.core.resources.IResource;
public class ToolChainScannerInfo {
private Map<String, String> definedSymbols;
- private List<String> includePaths;
- private List<String> macroFiles;
- private List<String> includeFiles;
- private List<String> localIncludePath;
+ private String[] includePaths;
+ private String[] macroFiles;
+ private String[] includeFiles;
+ private String[] localIncludePath;
private Set<String> resourcePaths;
private transient IScannerInfo scannerInfo;
- public ToolChainScannerInfo(Map<String, String> definedSymbols, List<String> includePaths,
- List<String> macroFiles, List<String> includeFiles, List<String> localIncludePath) {
- this.definedSymbols = definedSymbols;
- this.includePaths = includePaths;
- this.macroFiles = macroFiles;
- this.includeFiles = includeFiles;
- this.localIncludePath = localIncludePath;
+ public ToolChainScannerInfo(ExtendedScannerInfo scannerInfo) {
+ this.scannerInfo = scannerInfo;
+ this.definedSymbols = scannerInfo.getDefinedSymbols();
+ this.includePaths = scannerInfo.getIncludePaths();
+ this.macroFiles = scannerInfo.getMacroFiles();
+ this.includeFiles = scannerInfo.getIncludeFiles();
+ this.localIncludePath = scannerInfo.getLocalIncludePath();
}
public IScannerInfo getScannerInfo() {
if (scannerInfo == null) {
- scannerInfo = new ExtendedScannerInfo(definedSymbols,
- includePaths != null ? includePaths.toArray(new String[includePaths.size()]) : null,
- macroFiles != null ? macroFiles.toArray(new String[includePaths.size()]) : null,
- includeFiles != null ? includeFiles.toArray(new String[includePaths.size()]) : null,
- localIncludePath != null ? localIncludePath.toArray(new String[includePaths.size()])
- : null);
+ scannerInfo = new ExtendedScannerInfo(definedSymbols, includePaths, macroFiles, includeFiles,
+ localIncludePath);
}
return scannerInfo;
}

Back to the top