Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDoug Schaefer2019-07-04 14:55:42 +0000
committerDoug Schaefer2019-07-05 14:43:56 +0000
commitb953649c095baf883a0512513a68c44faf1767e1 (patch)
tree40f1e5919ee344374e3bb706b22ce91452595f0b /core
parentb1702ff7530d1db571a2aeb59924bef1ff3ce9a2 (diff)
downloadorg.eclipse.cdt-b953649c095baf883a0512513a68c44faf1767e1.tar.gz
org.eclipse.cdt-b953649c095baf883a0512513a68c44faf1767e1.tar.xz
org.eclipse.cdt-b953649c095baf883a0512513a68c44faf1767e1.zip
Bug 548980 - Track launch target connects and add error builds
We need a way to alert the user that we are unable to find a toolchain that maps to the current target. An ErrorBuildConfiguration is created that simply prints out an error message at build time to handle this. We then set one of these as the active build config in the tracker with the appropriate message. We also add a target listener so that when a target becomes OK_STATUS, we run the tracker again to see if we have the right active build config for that target. Some targets can only determine some of their attributes when connected. Hook up the IToolChain matches so we're using it in the toolchain manager. This allows toolchains to do more complicated matching of the properties. Change-Id: Icaff85117e8147cd2793f2915fa75ce33673ab52
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ErrorBuildConfiguration.java149
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChain.java9
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java8
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java2
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainManager.java12
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties2
6 files changed, 167 insertions, 15 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ErrorBuildConfiguration.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ErrorBuildConfiguration.java
new file mode 100644
index 00000000000..fa83980f92e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ErrorBuildConfiguration.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2019 QNX Software Systems and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.cdt.core.build;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
+import org.eclipse.cdt.core.resources.IConsole;
+import org.eclipse.cdt.internal.core.build.Messages;
+import org.eclipse.core.resources.IBuildConfiguration;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.PlatformObject;
+
+/**
+ * A Build configuration that simply spits out an error message on the console at build and clean time.
+ * Used to signify that we're not sure how to build this project in it's current state.
+ *
+ * TODO leaving most of the implementation as default. I don't think any of these methods get called when
+ * we're in this error state but we'll keep an eye open for NPE's and bad behavior.
+ */
+public class ErrorBuildConfiguration extends PlatformObject implements ICBuildConfiguration, ICBuildConfiguration2 {
+
+ private final IBuildConfiguration config;
+ private String errorMessage;
+
+ public static final String NAME = "!"; //$NON-NLS-1$
+
+ private static class Provider implements ICBuildConfigurationProvider {
+ @Override
+ public String getId() {
+ return "buildError"; //$NON-NLS-1$
+ }
+
+ @Override
+ public ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name)
+ throws CoreException {
+ return new ErrorBuildConfiguration(config, Messages.ErrorBuildConfiguration_What);
+ }
+ }
+
+ public static final Provider PROVIDER = new Provider();
+
+ public ErrorBuildConfiguration(IBuildConfiguration config, String errorMessage) {
+ this.errorMessage = errorMessage;
+ this.config = config;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ @Override
+ public IProject[] build(int kind, Map<String, String> args, IConsole console, IProgressMonitor monitor)
+ throws CoreException {
+ try {
+ console.getErrorStream().write(errorMessage);
+ } catch (IOException e) {
+ throw new CoreException(
+ CCorePlugin.createStatus(Messages.ErrorBuildConfiguration_ErrorWritingToConsole, e));
+ }
+ return null;
+ }
+
+ @Override
+ public void clean(IConsole console, IProgressMonitor monitor) throws CoreException {
+ try {
+ console.getErrorStream().write(errorMessage);
+ } catch (IOException e) {
+ throw new CoreException(
+ CCorePlugin.createStatus(Messages.ErrorBuildConfiguration_ErrorWritingToConsole, e));
+ }
+ }
+
+ @Override
+ public IScannerInfo getScannerInformation(IResource resource) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setActive() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public URI getBuildDirectoryURI() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IBuildConfiguration getBuildConfiguration() throws CoreException {
+ return config;
+ }
+
+ @Override
+ public IToolChain getToolChain() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getBinaryParserId() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IEnvironmentVariable getVariable(String name) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public IEnvironmentVariable[] getVariables() throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChain.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChain.java
index a4caf4a7b68..163fd89d0ad 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChain.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/IToolChain.java
@@ -263,11 +263,18 @@ public interface IToolChain extends IAdaptable {
}
/**
+ * Determine if this toolchain supports targets with the given set of properties.
+ *
+ * @param properties the set of properties to test against
+ * @return does this toolchain support these properties
+ *
* @since 6.1
*/
default boolean matches(Map<String, String> properties) {
for (Map.Entry<String, String> property : properties.entrySet()) {
- if (!property.getValue().equals(getProperty(property.getKey()))) {
+ String tcValue = getProperty(property.getKey());
+ // If toolchain doesn't have this property, it doesn't care
+ if (tcValue != null && !property.getValue().equals(tcValue)) {
return false;
}
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java
index 572324f91cf..ee279adc33f 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java
@@ -308,9 +308,11 @@ public class CBuildConfigurationManager
// First see if we have one
for (IBuildConfiguration config : project.getBuildConfigs()) {
ICBuildConfiguration cconfig = getBuildConfiguration(config);
- if (cconfig != null && cconfig.getToolChain().equals(toolChain)
- && launchMode.equals(cconfig.getLaunchMode())) {
- return cconfig;
+ if (cconfig != null) {
+ IToolChain tc = cconfig.getToolChain();
+ if (tc != null && tc.equals(toolChain) && launchMode.equals(cconfig.getLaunchMode())) {
+ return cconfig;
+ }
}
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java
index 4176fe34302..5378540f548 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/Messages.java
@@ -24,6 +24,8 @@ public class Messages extends NLS {
public static String CBuilder_NotConfiguredCorrectly2;
public static String CBuildConfiguration_CommandNotFound;
public static String CBuildConfiguration_BuildComplete;
+ public static String ErrorBuildConfiguration_What;
+ public static String ErrorBuildConfiguration_ErrorWritingToConsole;
public static String StandardBuildConfiguration_0;
public static String StandardBuildConfiguration_1;
public static String StandardBuildConfiguration_Failure;
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainManager.java
index c13682b6a30..45fb3edd663 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainManager.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/ToolChainManager.java
@@ -192,17 +192,7 @@ public class ToolChainManager implements IToolChainManager {
List<IToolChain> tcs = new ArrayList<>();
if (orderedToolChains != null) {
for (IToolChain toolChain : orderedToolChains.toArray(new IToolChain[0])) {
- boolean matches = true;
- for (Map.Entry<String, String> property : properties.entrySet()) {
- String tcProperty = toolChain.getProperty(property.getKey());
- if (tcProperty != null) {
- if (!property.getValue().equals(tcProperty)) {
- matches = false;
- break;
- }
- }
- }
- if (matches) {
+ if (toolChain.matches(properties)) {
tcs.add(toolChain);
}
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties
index 87e2672b232..6473f66a22a 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/messages.properties
@@ -21,3 +21,5 @@ CBuildConfiguration_CreateJob=Create Build Folder
CBuildConfiguration_Location=line %d, external location: %s
CBuildConfiguration_ToolchainMissing=Toolchain is missing for build configuration
CBuildConfiguration_RunningScannerInfo=Calculating scanner info for %s
+ErrorBuildConfiguration_What=Unknown initialization error
+ErrorBuildConfiguration_ErrorWritingToConsole=Error writing to console

Back to the top