Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2016-08-25 19:52:40 +0000
committerGerrit Code Review @ Eclipse.org2016-08-25 20:49:28 +0000
commit50bc082f8413b14cd7f5c5c6b72b493c6e43539e (patch)
tree37d90e309b5620586687398bd01cdd75978da3f8 /build/org.eclipse.cdt.cmake.core
parent6cbe4a684917c9b7d04d23b9313bede705150b95 (diff)
downloadorg.eclipse.cdt-50bc082f8413b14cd7f5c5c6b72b493c6e43539e.tar.gz
org.eclipse.cdt-50bc082f8413b14cd7f5c5c6b72b493c6e43539e.tar.xz
org.eclipse.cdt-50bc082f8413b14cd7f5c5c6b72b493c6e43539e.zip
Bug 174176 - Hook up CMake build to LaunchBar to select toolchain files
Use launch target os and cpu arch properties to pick toolchains and toolchain files. UI to add toolchain files. And build support. Also some clean up of Qt as I found bugs. Change-Id: Icd1da43460b5954eea15e95ed8ec27850fc4e54e
Diffstat (limited to 'build/org.eclipse.cdt.cmake.core')
-rw-r--r--build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF3
-rw-r--r--build/org.eclipse.cdt.cmake.core/plugin.xml8
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainFile.java13
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainManager.java33
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java4
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java73
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java41
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchConfigurationDelegate.java79
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchConfigurationProvider.java (renamed from build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalLaunchConfigurationProvider.java)36
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java37
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainFile.java52
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java146
12 files changed, 472 insertions, 53 deletions
diff --git a/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF
index 2cf8671247f..3a0eb13fc66 100644
--- a/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF
+++ b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.launchbar.core;bundle-version="2.0.0",
org.eclipse.cdt.core;bundle-version="5.12.0",
org.eclipse.tools.templates.freemarker;bundle-version="1.0.0";visibility:=reexport,
- com.google.gson
+ com.google.gson,
+ org.eclipse.remote.core;bundle-version="2.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.cmake.core
diff --git a/build/org.eclipse.cdt.cmake.core/plugin.xml b/build/org.eclipse.cdt.cmake.core/plugin.xml
index 32a9f20cc16..14b2864eb46 100644
--- a/build/org.eclipse.cdt.cmake.core/plugin.xml
+++ b/build/org.eclipse.cdt.cmake.core/plugin.xml
@@ -28,7 +28,7 @@
</enablement>
</descriptorType>
<configProvider
- class="org.eclipse.cdt.cmake.core.internal.CMakeLocalLaunchConfigurationProvider"
+ class="org.eclipse.cdt.cmake.core.internal.CMakeLaunchConfigurationProvider"
descriptorType="org.eclipse.cdt.cmake.core.descriptorType"
priority="10">
</configProvider>
@@ -36,10 +36,10 @@
<extension
point="org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
- delegate="org.eclipse.cdt.cmake.core.internal.CMakeLocalRunLaunchConfigDelegate"
- id="org.eclipse.cdt.cmake.core.localLunchConfigurationType"
+ delegate="org.eclipse.cdt.cmake.core.internal.CMakeLaunchConfigurationDelegate"
+ id="org.eclipse.cdt.cmake.core.launchConfigurationType"
modes="run"
- name="CMake Local Application"
+ name="CMake Application"
public="true">
</launchConfigurationType>
</extension>
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainFile.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainFile.java
new file mode 100644
index 00000000000..e10371a469f
--- /dev/null
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainFile.java
@@ -0,0 +1,13 @@
+package org.eclipse.cdt.cmake.core;
+
+import java.nio.file.Path;
+
+public interface ICMakeToolChainFile {
+
+ Path getPath();
+
+ String getProperty(String key);
+
+ void setProperty(String key, String value);
+
+}
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainManager.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainManager.java
new file mode 100644
index 00000000000..d7879a932c3
--- /dev/null
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeToolChainManager.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.cmake.core;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Manages toolchain files for CMake.
+ *
+ * @noimplement
+ */
+public interface ICMakeToolChainManager {
+
+ ICMakeToolChainFile newToolChainFile(Path path);
+
+ void addToolChainFile(ICMakeToolChainFile file);
+
+ void removeToolChainFile(ICMakeToolChainFile file);
+
+ ICMakeToolChainFile getToolChainFile(Path path);
+
+ Collection<ICMakeToolChainFile> getToolChainsFileMatching(Map<String, String> properties);
+
+ Collection<ICMakeToolChainFile> getToolChainFiles();
+
+}
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java
index 0f78429c888..cbd7032ac80 100644
--- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java
@@ -7,6 +7,7 @@
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
+import org.eclipse.cdt.cmake.core.ICMakeToolChainManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
@@ -18,11 +19,14 @@ public class Activator extends Plugin {
private static Activator plugin;
+ @Override
public void start(BundleContext bundleContext) throws Exception {
super.start(bundleContext);
Activator.plugin = this;
+ bundleContext.registerService(ICMakeToolChainManager.class, new CMakeToolChainManager(), null);
}
+ @Override
public void stop(BundleContext bundleContext) throws Exception {
super.stop(bundleContext);
Activator.plugin = null;
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java
index a1a4f7b2e92..6efa8bf43ae 100644
--- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015, 2016 QNX Software Systems and others.
+// * Copyright (c) 2015, 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
@@ -12,10 +12,14 @@ import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
+import org.eclipse.cdt.cmake.core.ICMakeToolChainManager;
import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.IConsoleParser;
@@ -28,17 +32,52 @@ 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.Platform;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
import com.google.gson.Gson;
public class CMakeBuildConfiguration extends CBuildConfiguration {
+ private static final String TOOLCHAIN_FILE = "cdt.cmake.toolchainfile"; //$NON-NLS-1$
+
+ private ICMakeToolChainFile toolChainFile;
+
public CMakeBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
super(config, name);
+
+ Preferences settings = getSettings();
+ String pathStr = settings.get(TOOLCHAIN_FILE, ""); //$NON-NLS-1$
+ if (!pathStr.isEmpty()) {
+ Path path = Paths.get(pathStr);
+ ICMakeToolChainManager manager = Activator.getService(ICMakeToolChainManager.class);
+ toolChainFile = manager.getToolChainFile(path);
+ }
}
public CMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
+ this(config, name, toolChain, null);
+ }
+
+ public CMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
+ ICMakeToolChainFile toolChainFile) {
super(config, name, toolChain);
+ this.toolChainFile = toolChainFile;
+
+ if (toolChainFile != null) {
+ Preferences settings = getSettings();
+ settings.put(TOOLCHAIN_FILE, toolChainFile.getPath().toString());
+ try {
+ settings.flush();
+ } catch (BackingStoreException e) {
+ Activator.log(e);
+ }
+ }
+ }
+
+ public ICMakeToolChainFile getToolChainFile() {
+ return toolChainFile;
}
@Override
@@ -52,12 +91,35 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
Path buildDir = getBuildDirectory();
+ outStream.write(String.format("Building in: %s\n", buildDir.toString()));
+
if (!Files.exists(buildDir.resolve("Makefile"))) { //$NON-NLS-1$
- // TODO assuming cmake is in the path here, probably need a
- // preference in case it isn't.
- List<String> command = Arrays.asList("/usr/local/bin/cmake", //$NON-NLS-1$
- "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", new File(project.getLocationURI()).getAbsolutePath()); //$NON-NLS-1$
+ List<String> command = new ArrayList<>();
+
+ // TODO assuming cmake is in the path here, probably need a preference in case it isn't.
+ Path cmakePath = CBuildConfiguration.getCommandFromPath(Paths.get("cmake")); //$NON-NLS-1$
+ if (cmakePath == null) {
+ if (!Platform.getOS().equals(Platform.OS_WIN32)) {
+ cmakePath = Paths.get("/usr/local/bin/cmake"); //$NON-NLS-1$
+ } else {
+ cmakePath = Paths.get("cmake"); //$NON-NLS-1$
+ }
+ }
+ command.add(cmakePath.toString());
+
+ command.add("-G"); //$NON-NLS-1$
+ // TODO ninja?
+ command.add("Unix Makefiles"); //$NON-NLS-1$
+
+ if (toolChainFile != null) {
+ command.add("-DCMAKE_TOOLCHAIN_FILE=" + toolChainFile.getPath().toString()); //$NON-NLS-1$
+ }
+
+ command.add("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"); //$NON-NLS-1$
+ command.add(new File(project.getLocationURI()).getAbsolutePath());
+
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
+ setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
watchProcess(process, new IConsoleParser[0], console);
@@ -68,6 +130,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
// TODO need to figure out which builder to call. Hardcoding to make for now.
List<String> command = Arrays.asList("make"); //$NON-NLS-1$
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
+ setBuildEnvironment(processBuilder.environment());
Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
watchProcess(process, new IConsoleParser[] { epm }, console);
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java
index 51f6d313f22..9a2dcfe82c2 100644
--- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java
@@ -7,21 +7,31 @@
*******************************************************************************/
package org.eclipse.cdt.cmake.core.internal;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
+import org.eclipse.cdt.cmake.core.ICMakeToolChainManager;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.core.resources.IBuildConfiguration;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProvider {
public static final String ID = "org.eclipse.cdt.cmake.core.provider"; //$NON-NLS-1$
+ private ICMakeToolChainManager manager = Activator.getService(ICMakeToolChainManager.class);
+ private IToolChainManager tcManager = Activator.getService(IToolChainManager.class);
+ private ICBuildConfigurationManager configManager = Activator.getService(ICBuildConfigurationManager.class);
+
@Override
public String getId() {
return ID;
@@ -61,4 +71,35 @@ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProv
}
}
+ public CMakeBuildConfiguration getCBuildConfiguration(IProject project, Map<String, String> properties,
+ String launchMode, IProgressMonitor monitor) throws CoreException {
+ for (IBuildConfiguration config : project.getBuildConfigs()) {
+ ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
+ if (cconfig != null) {
+ CMakeBuildConfiguration cmakeConfig = cconfig.getAdapter(CMakeBuildConfiguration.class);
+ if (cmakeConfig != null && cmakeConfig.getToolChain().matches(properties)) {
+ return cmakeConfig;
+ }
+ }
+ }
+
+ Collection<IToolChain> tcs = tcManager.getToolChainsMatching(properties);
+ if (tcs.isEmpty()) {
+ return null;
+ }
+ IToolChain toolChain = tcs.iterator().next();
+
+ ICMakeToolChainFile file = null;
+ Collection<ICMakeToolChainFile> files = manager.getToolChainsFileMatching(properties);
+ if (!files.isEmpty()) {
+ file = files.iterator().next();
+ }
+
+ String configName = "cmake." + toolChain.getId(); //$NON-NLS-1$
+ IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, monitor);
+ CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, configName, toolChain, file);
+ configManager.addBuildConfiguration(config, cmakeConfig);
+ return cmakeConfig;
+ }
+
}
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchConfigurationDelegate.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchConfigurationDelegate.java
new file mode 100644
index 00000000000..f698335c046
--- /dev/null
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchConfigurationDelegate.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.cmake.core.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
+import org.eclipse.launchbar.core.target.ILaunchTarget;
+import org.eclipse.launchbar.core.target.launch.LaunchConfigurationTargetedDelegate;
+
+public class CMakeLaunchConfigurationDelegate extends LaunchConfigurationTargetedDelegate
+ implements ILaunchConfigurationDelegate {
+
+ public static final String TYPE_ID = "org.eclipse.cdt.cmake.core.launchConfigurationType"; //$NON-NLS-1$
+
+ private ICBuildConfigurationManager configManager = Activator.getService(ICBuildConfigurationManager.class);
+
+ private IProject getProject(ILaunchConfiguration configuration) throws CoreException {
+ return configuration.getMappedResources()[0].getProject();
+ }
+
+ @Override
+ public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, ILaunchTarget target,
+ IProgressMonitor monitor) throws CoreException {
+ // Set active build config based on target
+ CMakeBuildConfigurationProvider provider = (CMakeBuildConfigurationProvider) configManager
+ .getProvider(CMakeBuildConfigurationProvider.ID);
+
+ Map<String, String> properties = new HashMap<>();
+ String os = target.getAttribute(ILaunchTarget.ATTR_OS, ""); //$NON-NLS-1$
+ if (!os.isEmpty()) {
+ properties.put(IToolChain.ATTR_OS, os);
+ }
+ String arch = target.getAttribute(ILaunchTarget.ATTR_ARCH, ""); //$NON-NLS-1$
+ if (!arch.isEmpty()) {
+ properties.put(IToolChain.ATTR_ARCH, arch);
+ }
+
+ IProject project = getProject(configuration);
+ CMakeBuildConfiguration config = provider.getCBuildConfiguration(project, properties, mode, monitor);
+ if (config != null) {
+ IProjectDescription desc = project.getDescription();
+ desc.setActiveBuildConfig(config.getBuildConfiguration().getName());
+ project.setDescription(desc, monitor);
+ }
+
+ return superBuildForLaunch(configuration, mode, monitor);
+ }
+
+ @Override
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
+ throws CoreException {
+ // TODO need to find the binary and launch it.
+ // Though, more likely, need to have launch configs per binary.
+ }
+
+ @Override
+ protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
+ // 1. Extract project from configuration
+ // TODO dependencies too.
+ IProject project = getProject(configuration);
+ return new IProject[] { project };
+ }
+
+}
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalLaunchConfigurationProvider.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchConfigurationProvider.java
index 55d40734a0c..ffc81526676 100644
--- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalLaunchConfigurationProvider.java
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchConfigurationProvider.java
@@ -11,6 +11,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.cdt.cmake.core.ICMakeToolChainManager;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -23,25 +26,46 @@ import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
-public class CMakeLocalLaunchConfigurationProvider extends AbstractLaunchConfigProvider {
+public class CMakeLaunchConfigurationProvider extends AbstractLaunchConfigProvider {
+
+ private final ICMakeToolChainManager manager = Activator.getService(ICMakeToolChainManager.class);
+ private final IToolChainManager tcManager = Activator.getService(IToolChainManager.class);
private Map<IProject, ILaunchConfiguration> configs = new HashMap<>();
@Override
public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
- return ILaunchTargetManager.localLaunchTargetTypeId.equals(target.getTypeId());
+ if (ILaunchTargetManager.localLaunchTargetTypeId.equals(target.getTypeId())) {
+ return true;
+ }
+
+ String os = target.getAttribute(ILaunchTarget.ATTR_OS, ""); //$NON-NLS-1$
+ if (os.isEmpty()) {
+ return false;
+ }
+
+ String arch = target.getAttribute(ILaunchTarget.ATTR_ARCH, ""); //$NON-NLS-1$
+ if (arch.isEmpty()) {
+ return false;
+ }
+
+ Map<String, String> properties = new HashMap<>();
+ properties.put(IToolChain.ATTR_OS, os);
+ properties.put(IToolChain.ATTR_ARCH, arch);
+ if (manager.getToolChainsFileMatching(properties).isEmpty()) {
+ return false;
+ }
+
+ return !tcManager.getToolChainsMatching(properties).isEmpty();
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target)
throws CoreException {
return DebugPlugin.getDefault().getLaunchManager()
- .getLaunchConfigurationType(CMakeLocalRunLaunchConfigDelegate.TYPE_ID);
+ .getLaunchConfigurationType(CMakeLaunchConfigurationDelegate.TYPE_ID);
}
- // TODO the rest here is the same as the Qt provider. Opportunity to create
- // a common super class
-
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
throws CoreException {
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java
deleted file mode 100644
index 2bb8db73679..00000000000
--- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java
+++ /dev/null
@@ -1,37 +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.cmake.core.internal;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
-import org.eclipse.launchbar.core.target.launch.LaunchConfigurationTargetedDelegate;
-
-public class CMakeLocalRunLaunchConfigDelegate extends LaunchConfigurationTargetedDelegate
- implements ILaunchConfigurationDelegate {
-
- public static final String TYPE_ID = "org.eclipse.cdt.cmake.core.localLunchConfigurationType"; //$NON-NLS-1$
-
- @Override
- public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
- throws CoreException {
- // TODO need to find the binary and launch it.
- }
-
- @Override
- protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
- // 1. Extract project from configuration
- // TODO dependencies too.
- IProject project = configuration.getMappedResources()[0].getProject();
- return new IProject[] { project };
- }
-
-}
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainFile.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainFile.java
new file mode 100644
index 00000000000..5e97996a5c2
--- /dev/null
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainFile.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.cmake.core.internal;
+
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
+
+public class CMakeToolChainFile implements ICMakeToolChainFile {
+
+ String n;
+ private final Path path;
+
+ final Map<String, String> properties = new HashMap<>();
+
+ public CMakeToolChainFile(String n, Path path) {
+ this.n = n;
+ this.path = path;
+ }
+
+ @Override
+ public Path getPath() {
+ return path;
+ }
+
+ @Override
+ public String getProperty(String key) {
+ return properties.get(key);
+ }
+
+ @Override
+ public void setProperty(String key, String value) {
+ properties.put(key, value);
+ }
+
+ boolean matches(Map<String, String> properties) {
+ for (Map.Entry<String, String> property : properties.entrySet()) {
+ if (!property.getValue().equals(getProperty(property.getKey()))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java
new file mode 100644
index 00000000000..4ac5b957d12
--- /dev/null
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeToolChainManager.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * 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.cmake.core.internal;
+
+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.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
+import org.eclipse.cdt.cmake.core.ICMakeToolChainManager;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+public class CMakeToolChainManager implements ICMakeToolChainManager {
+
+ private Map<Path, ICMakeToolChainFile> files;
+
+ private static final String N = "n"; //$NON-NLS-1$
+ private static final String PATH = "__path"; //$NON-NLS-1$
+
+ private Preferences getPreferences() {
+ return InstanceScope.INSTANCE.getNode(Activator.getId()).node("cmakeToolchains"); //$NON-NLS-1$
+ }
+
+ private void init() {
+ if (files == null) {
+ files = new HashMap<>();
+
+ Preferences prefs = getPreferences();
+ try {
+ for (String childName : prefs.childrenNames()) {
+ Preferences tcNode = prefs.node(childName);
+ String path = tcNode.get(PATH, "/"); //$NON-NLS-1$
+ ICMakeToolChainFile file = new CMakeToolChainFile(childName, Paths.get(path));
+ for (String key : tcNode.keys()) {
+ String value = tcNode.get(key, ""); //$NON-NLS-1$
+ if (!value.isEmpty()) {
+ file.setProperty(key, value);
+ }
+ }
+ files.put(file.getPath(), file);
+ }
+ } catch (BackingStoreException e) {
+ Activator.log(e);
+ }
+
+ // TODO discovery
+ }
+ }
+
+ @Override
+ public ICMakeToolChainFile newToolChainFile(Path path) {
+ return new CMakeToolChainFile(null, path);
+ }
+
+ @Override
+ public void addToolChainFile(ICMakeToolChainFile file) {
+ init();
+ files.put(file.getPath(), file);
+
+ // save it
+
+ CMakeToolChainFile realFile = (CMakeToolChainFile) file;
+ Preferences prefs = getPreferences();
+ String n = realFile.n;
+ if (n == null) {
+ n = prefs.get(N, "0"); //$NON-NLS-1$
+ realFile.n = n;
+ }
+ prefs.put(N, Integer.toString(Integer.parseInt(n) + 1));
+
+ Preferences tcNode = prefs.node(n);
+ tcNode.put(PATH, file.getPath().toString());
+ for (Entry<String, String> entry : realFile.properties.entrySet()) {
+ tcNode.put(entry.getKey(), entry.getValue());
+ }
+
+ try {
+ prefs.flush();
+ } catch (BackingStoreException e) {
+ Activator.log(e);
+ }
+ }
+
+ @Override
+ public void removeToolChainFile(ICMakeToolChainFile file) {
+ init();
+ files.remove(file.getPath());
+
+ String n = ((CMakeToolChainFile) file).n;
+ if (n != null) {
+ Preferences prefs = getPreferences();
+ Preferences tcNode = prefs.node(n);
+ try {
+ tcNode.removeNode();
+ prefs.flush();
+ } catch (BackingStoreException e) {
+ Activator.log(e);
+ }
+ }
+ }
+
+ @Override
+ public ICMakeToolChainFile getToolChainFile(Path path) {
+ init();
+ return files.get(path);
+ }
+
+ @Override
+ public Collection<ICMakeToolChainFile> getToolChainFiles() {
+ init();
+ return Collections.unmodifiableCollection(files.values());
+ }
+
+ @Override
+ public Collection<ICMakeToolChainFile> getToolChainsFileMatching(Map<String, String> properties) {
+ List<ICMakeToolChainFile> matches = new ArrayList<>();
+ for (ICMakeToolChainFile file : getToolChainFiles()) {
+ boolean match = true;
+ for (Entry<String, String> entry : properties.entrySet()) {
+ if (!entry.getValue().equals(file.getProperty(entry.getKey()))) {
+ match = false;
+ break;
+ }
+ }
+
+ if (match) {
+ matches.add(file);
+ }
+ }
+ return matches;
+ }
+
+}

Back to the top