summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.cmake.managedbuilder/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.cmake.managedbuilder/src')
-rw-r--r--plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/Activator.java50
-rw-r--r--plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java281
-rw-r--r--plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.java57
-rw-r--r--plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.properties29
-rw-r--r--plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java186
-rw-r--r--plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/ConsoleUtility.java49
-rw-r--r--plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java118
7 files changed, 770 insertions, 0 deletions
diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/Activator.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/Activator.java
new file mode 100644
index 0000000..6d4e28f
--- /dev/null
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/Activator.java
@@ -0,0 +1,50 @@
1/*******************************************************************************
2 * Copyright (c) 2013 BMW Car IT GmbH.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * BMW Car IT - initial API and implementation
10 *******************************************************************************/
11package org.yocto.cmake.managedbuilder;
12
13import org.eclipse.core.runtime.Plugin;
14import org.osgi.framework.BundleContext;
15
16public class Activator extends Plugin {
17
18 /** The plug-in ID. */
19 public static final String PLUGIN_ID = "org.yocto.cmake.managedbuilder"; //$NON-NLS-1$
20
21 /** The shared activator instance. */
22 private static Activator plugin;
23
24 /*
25 * (non-Javadoc)
26 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
27 */
28 @Override
29 public void start(BundleContext context) throws Exception {
30 super.start(context);
31 plugin = this;
32 }
33
34 /*
35 * (non-Javadoc)
36 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
37 */
38 @Override
39 public void stop(BundleContext context) throws Exception {
40 plugin = null;
41 super.stop(context);
42 }
43
44 /**
45 * @return the shared instance of the Activator
46 */
47 public static Activator getDefault() {
48 return plugin;
49 }
50}
diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java
new file mode 100644
index 0000000..b77ae9e
--- /dev/null
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java
@@ -0,0 +1,281 @@
1/*******************************************************************************
2 * Copyright (c) 2013 BMW Car IT GmbH.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * BMW Car IT - initial API and implementation
10 *******************************************************************************/
11package org.yocto.cmake.managedbuilder;
12
13import java.io.ByteArrayInputStream;
14import java.io.InputStream;
15
16import org.eclipse.cdt.managedbuilder.core.IBuilder;
17import org.eclipse.cdt.managedbuilder.core.IConfiguration;
18import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
19import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
20import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
21import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator2;
22import org.eclipse.core.resources.IFile;
23import org.eclipse.core.resources.IProject;
24import org.eclipse.core.resources.IResource;
25import org.eclipse.core.resources.IResourceDelta;
26import org.eclipse.core.runtime.CoreException;
27import org.eclipse.core.runtime.IPath;
28import org.eclipse.core.runtime.IProgressMonitor;
29import org.eclipse.core.runtime.IStatus;
30import org.eclipse.core.runtime.MultiStatus;
31import org.eclipse.core.runtime.jobs.Job;
32import org.yocto.cmake.managedbuilder.job.ExecuteConfigureJob;
33import org.yocto.sdk.ide.utils.YoctoSDKUtils;
34
35public class YoctoCMakeMakefileGenerator implements IManagedBuilderMakefileGenerator2 {
36
37 private static final String TOOLCHAINCMAKE_FILE_NAME = "toolchain.cmake"; //$NON-NLS-1$
38 private static final String MAKEFILE_NAME = "Makefile"; //$NON-NLS-1$
39 private static final String CMAKE_FILE_NAME = "CMakeLists.txt"; //$NON-NLS-1$
40 private static final String CMAKECACHE_FILE_NAME = "CMakeCache.txt"; //$NON-NLS-1$
41
42 private IProject project;
43 private int lastBuildInfoChecksum = 0;
44 private IConfiguration configuration;
45 private IProgressMonitor monitor;
46 private IPath buildDir = null;
47
48 @Override
49 public String getMakefileName() {
50 return MAKEFILE_NAME;
51 }
52
53 @Override
54 public IPath getBuildWorkingDir() {
55 IPath buildWorkingDir = null;
56
57 if (buildDir != null) {
58 buildWorkingDir = buildDir.removeFirstSegments(1);
59 }
60
61 return buildWorkingDir;
62 }
63
64 @Override
65 public boolean isGeneratedResource(IResource resource) {
66 return false;
67 }
68
69 @Override
70 public void initialize(IProject project, IManagedBuildInfo info,
71 IProgressMonitor monitor) {
72 this.project = project;
73 this.configuration = info.getDefaultConfiguration();
74 this.monitor = monitor;
75
76 if (info.getDefaultConfiguration() != null) {
77 buildDir = project.getFolder(info.getConfigurationName()).getFullPath();
78 }
79 }
80
81 @Override
82 public void initialize(int buildKind, IConfiguration configuration, IBuilder builder,
83 IProgressMonitor monitor) {
84 this.project = configuration.getOwner().getProject();
85 this.configuration = configuration;
86 this.monitor = monitor;
87 this.buildDir = project.getFolder(configuration.getName()).getFullPath();
88 }
89
90 @Override
91 public void generateDependencies() throws CoreException {
92 // nothing to do here
93 }
94
95 @Override
96 public void regenerateDependencies(boolean force) throws CoreException {
97 generateDependencies();
98 }
99
100 @Override
101 public MultiStatus generateMakefiles(IResourceDelta delta)
102 throws CoreException {
103 int currentBuildInfoChecksum = ManagedBuildManager.getBuildInfo(project).hashCode();
104
105 IFile cmakeFile = project.getFile(CMAKE_FILE_NAME);
106 IResourceDelta cmakeDelta = delta.findMember(cmakeFile.getProjectRelativePath());
107 IResourceDelta[] deltas = delta
108 .getAffectedChildren(IResourceDelta.ADDED | IResourceDelta.REMOVED);
109
110 if (deltas.length > 0 || cmakeDelta != null || currentBuildInfoChecksum != lastBuildInfoChecksum) {
111 lastBuildInfoChecksum = currentBuildInfoChecksum;
112 return regenerateMakefiles();
113 } else {
114 // CMake is not needed to run prior to building
115 // just return that makefile generation is completed
116 return new MultiStatus(
117 ManagedBuilderCorePlugin.getUniqueIdentifier(), IStatus.OK,
118 new String(YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.ok.makefilesStillValid")), null); //$NON-NLS-1$
119 }
120 }
121
122 @Override
123 public MultiStatus regenerateMakefiles() throws CoreException {
124 String taskName =
125 YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.configure.creatingMakefiles"); //$NON-NLS-1$
126 monitor.beginTask(taskName, 20);
127
128 IFile cmakeFile = project.getFile(CMAKE_FILE_NAME);
129 if (!cmakeFile.exists()) {
130 return new MultiStatus(ManagedBuilderCorePlugin.getUniqueIdentifier(), IStatus.CANCEL,
131 new String(YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.cancel.missingCMakeList")), null); //$NON-NLS-1$
132 }
133
134 // Retrieve Build directory
135 IPath workingDir = getBuildWorkingDir();
136 IPath location = project.getLocation().append(workingDir);
137 monitor.worked(1);
138
139 // Create build directory if it doesn't exist
140 if (!location.toFile().exists()) {
141 monitor.subTask(
142 YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.creatingBuildDirectory")); //$NON-NLS-1$
143 location.toFile().mkdirs();
144 } else {
145 monitor.subTask(
146 YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.removingCacheFiles")); //$NON-NLS-1$
147 IFile cmakeCache = project.getFile(workingDir.append(CMAKECACHE_FILE_NAME));
148 cmakeCache.delete(true, monitor);
149 }
150 monitor.setTaskName(taskName);
151
152 createToolchainCMakeFile(workingDir);
153
154 // Create the Makefiles by executing cmake
155 ExecuteConfigureJob job =
156 new ExecuteConfigureJob(
157 YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.configureJob.name"), //$NON-NLS-1$
158 project, configuration, location);
159 job.setPriority(Job.BUILD);
160 job.setUser(false);
161
162 job.schedule();
163 try {
164 job.join();
165 monitor.done();
166 return new MultiStatus(
167 Activator.PLUGIN_ID, job.getResult().getSeverity(),
168 job.getResult().getMessage(), null);
169 } catch (InterruptedException e) {
170 return new MultiStatus(
171 Activator.PLUGIN_ID,
172 IStatus.ERROR, new String(
173 YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.error.makeFileGenerationFailed")), null); //$NON-NLS-1$
174 }
175 }
176
177 private String createCMakeSetStatement(String variable, String value, String cacheOption) {
178 String setStatement = "set("; //$NON-NLS-1$
179 setStatement += variable + " " + value; //$NON-NLS-1$
180 if(cacheOption != null && !cacheOption.equals("")) { //$NON-NLS-1$
181 setStatement += " " + cacheOption; //$NON-NLS-1$
182 }
183 setStatement += ")\n"; //$NON-NLS-1$
184 return setStatement;
185 }
186
187 // Considered poky's cmake.bbclass for this method
188 private void createToolchainCMakeFile(IPath workingDir) {
189 String toolchainCMakeFileContentAsString = "# CMake system name must be something like \"Linux\".\n" + //$NON-NLS-1$
190 "# This is important for cross-compiling.\n"; //$NON-NLS-1$
191
192 String targetArchValue = YoctoSDKUtils.getEnvValue(project, "TARGET_ARCH"); //$NON-NLS-1$
193 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_SYSTEM_PROCESSOR", targetArchValue, null); //$NON-NLS-1$
194
195 String oeCMakeCCompilerValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_COMPILER"); //$NON-NLS-1$
196 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_COMPILER", oeCMakeCCompilerValue, null); //$NON-NLS-1$
197
198 String oeCMakeCXXCompilerValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_COMPILER"); //$NON-NLS-1$
199 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_COMPILER", oeCMakeCXXCompilerValue, null); //$NON-NLS-1$
200
201 String oeCMakeCFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_FLAGS"); //$NON-NLS-1$
202 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_FLAGS", //$NON-NLS-1$
203 "\"" + oeCMakeCFlagsValue + "\"", "CACHE STRING \"CFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
204
205 String oeCMakeCXXFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_FLAGS"); //$NON-NLS-1$
206 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_FLAGS", //$NON-NLS-1$
207 "\"" + oeCMakeCXXFlagsValue + "\"", "CACHE STRING \"CXXFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
208
209 String oeCMakeCFlagsReleaseValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_FLAGS_RELEASE"); //$NON-NLS-1$
210 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_FLAGS_RELEASE", //$NON-NLS-1$
211 "\"" + oeCMakeCFlagsReleaseValue + "\"", "CACHE STRING \"CFLAGS for release\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
212
213 String oeCMakeCXXFlagsReleaseValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_FLAGS_RELEASE"); //$NON-NLS-1$
214 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_FLAGS_RELEASE", //$NON-NLS-1$
215 "\"" + oeCMakeCXXFlagsReleaseValue + "\"", "CACHE STRING \"CXXFLAGS for release\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
216
217 String oeCMakeCLinkFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_LINK_FLAGS"); //$NON-NLS-1$
218 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_LINK_FLAGS", //$NON-NLS-1$
219 "\"" + oeCMakeCLinkFlagsValue + "\"", "CACHE STRING \"LDFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
220
221 String oeCMakeCXXLinkFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_LINK_FLAGS"); //$NON-NLS-1$
222 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_LINK_FLAGS", //$NON-NLS-1$
223 "\"" + oeCMakeCXXLinkFlagsValue + "\"", "CACHE STRING \"LDFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
224
225 toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
226 toolchainCMakeFileContentAsString += "# only search in the paths provided so cmake doesnt pick\n"; //$NON-NLS-1$
227 toolchainCMakeFileContentAsString += "# up libraries and tools from the native build machine\n"; //$NON-NLS-1$
228
229 String findRootPathValue = YoctoSDKUtils.getEnvValue(project, "STAGING_DIR_HOST"); //$NON-NLS-1$
230 findRootPathValue += " "; //$NON-NLS-1$
231 findRootPathValue += YoctoSDKUtils.getEnvValue(project, "STAGING_DIR_NATIVE"); //$NON-NLS-1$
232 findRootPathValue += " "; //$NON-NLS-1$
233 findRootPathValue += YoctoSDKUtils.getEnvValue(project, "CROSS_DIR"); //$NON-NLS-1$
234 findRootPathValue += " "; //$NON-NLS-1$
235 findRootPathValue += YoctoSDKUtils.getEnvValue(project, "OECMAKE_PERLNATIVE_DIR"); //$NON-NLS-1$
236 findRootPathValue += " "; //$NON-NLS-1$
237 findRootPathValue += YoctoSDKUtils.getEnvValue(project, "OECMAKE_EXTRA_ROOT_PATH"); //$NON-NLS-1$
238 findRootPathValue += " "; //$NON-NLS-1$
239 findRootPathValue += YoctoSDKUtils.getEnvValue(project, "EXTERNAL_TOOLCHAIN"); //$NON-NLS-1$
240 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH", findRootPathValue, null); //$NON-NLS-1$
241
242 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", "ONLY", null); //$NON-NLS-1$ //$NON-NLS-2$
243 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", "ONLY", null); //$NON-NLS-1$ //$NON-NLS-2$
244 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", "ONLY", null); //$NON-NLS-1$ //$NON-NLS-2$
245 toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
246
247 toolchainCMakeFileContentAsString += "# Use qt.conf settings\n"; //$NON-NLS-1$
248 toolchainCMakeFileContentAsString += createCMakeSetStatement("ENV{QT_CONF_PATH}", "qt.conf", null); //$NON-NLS-1$ //$NON-NLS-2$
249 toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
250
251 toolchainCMakeFileContentAsString += "# We need to set the rpath to the correct directory as cmake does not provide any\n"; //$NON-NLS-1$
252 toolchainCMakeFileContentAsString += "# directory as rpath by default\n"; //$NON-NLS-1$
253
254 String oeCMakeRPathValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_RPATH"); //$NON-NLS-1$
255 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_INSTALL_RPATH", oeCMakeRPathValue, null); //$NON-NLS-1$
256
257 toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
258 toolchainCMakeFileContentAsString += "# Use native cmake modules\n"; //$NON-NLS-1$
259
260 String stagingDatadirValue = YoctoSDKUtils.getEnvValue(project, "STAGING_DATADIR"); //$NON-NLS-1$
261 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_MODULE_PATH", //$NON-NLS-1$
262 stagingDatadirValue + "/cmake/Modules/", null); //$NON-NLS-1$
263
264 toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$
265 toolchainCMakeFileContentAsString += "# add for non /usr/lib libdir, e.g. /usr/lib64\n"; //$NON-NLS-1$
266 toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_LIBRARY_PATH", //$NON-NLS-1$
267 "${libdir} ${base_libdir}", null); //$NON-NLS-1$
268
269 InputStream toolchainCMakeFileContent = new ByteArrayInputStream(toolchainCMakeFileContentAsString.getBytes());
270
271 IFile toolchainCMakeFile = project.getFile(TOOLCHAINCMAKE_FILE_NAME);
272 try {
273 if (toolchainCMakeFile.exists()) {
274 toolchainCMakeFile.delete(true, monitor);
275 }
276 toolchainCMakeFile.create(toolchainCMakeFileContent, true, monitor);
277 } catch (CoreException e) {
278 e.printStackTrace();
279 }
280 }
281}
diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.java
new file mode 100644
index 0000000..1bd8b46
--- /dev/null
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.java
@@ -0,0 +1,57 @@
1/*******************************************************************************
2 * Copyright (c) 2010 Intel Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel - initial API and implementation
10 *******************************************************************************/
11package org.yocto.cmake.managedbuilder;
12
13import java.text.MessageFormat;
14import java.util.MissingResourceException;
15import java.util.ResourceBundle;
16
17public class YoctoCMakeMessages {
18
19 private static final String RESOURCE_BUNDLE= YoctoCMakeMessages.class.getName();
20 private static ResourceBundle fgResourceBundle;
21 static {
22 try {
23 fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
24 } catch (MissingResourceException x) {
25 fgResourceBundle = null;
26 }
27 }
28
29 private YoctoCMakeMessages() {
30 }
31
32 public static String getString(String key) {
33 try {
34 return fgResourceBundle.getString(key);
35 } catch (MissingResourceException e) {
36 return '!' + key + '!';
37 } catch (NullPointerException e) {
38 return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$
39 }
40 }
41
42 /**
43 * Gets a string from the resource bundle and formats it with the argument
44 *
45 * @param key the string used to get the bundle value, must not be null
46 */
47 public static String getFormattedString(String key, Object arg) {
48 return MessageFormat.format(getString(key), new Object[] { arg });
49 }
50
51 /**
52 * Gets a string from the resource bundle and formats it with arguments
53 */
54 public static String getFormattedString(String key, Object[] args) {
55 return MessageFormat.format(getString(key), args);
56 }
57}
diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.properties b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.properties
new file mode 100644
index 0000000..55773ac
--- /dev/null
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.properties
@@ -0,0 +1,29 @@
1#/*******************************************************************************
2# * Copyright (c) 2013 BMW Car IT GmbH.
3# * All rights reserved. This program and the accompanying materials
4# * are made available under the terms of the Eclipse Public License v1.0
5# * which accompanies this distribution, and is available at
6# * http://www.eclipse.org/legal/epl-v10.html
7# *
8# * Contributors:
9# * BMW Car IT - initial implementation
10# *******************************************************************************/
11
12# Job
13ExecuteConfigureJob.runConfigure=Running configure
14ExecuteConfigureJob.consoleName=Configure using CMake [{0}]
15ExecuteConfigureJob.buildingMakefile=Building Makefile
16ExecuteConfigureJob.warning.aborted=Build of project has been aborted
17ExecuteConfigureJob.error.couldNotStart=Build of project could not be started
18ExecuteConfigureJob.error.buildFailed=Build of project failed
19ExecuteConfigureJob.cmakeWarning.dialogTitle=Unable to run command "cmake"
20ExecuteConfigureJob.cmakeWarning.dialogMessage=Please make sure that cmake is installed properly on this machine.
21
22# File generator
23YoctoCMakeMakefileGenerator.configureJob.name=Configuring project
24YoctoCMakeMakefileGenerator.configure.creatingMakefiles=Generating Makefiles using CMake
25YoctoCMakeMakefileGenerator.cancel.missingCMakeList=CMakeLists.txt file is missing
26YoctoCMakeMakefileGenerator.creatingBuildDirectory=Creating build directory
27YoctoCMakeMakefileGenerator.error.makeFileGenerationFailed=Makefile generation failed during configuration process
28YoctoCMakeMakefileGenerator.ok.makefilesStillValid=Makefiles are still valid.
29YoctoCMakeMakefileGenerator.removingCacheFiles=Removing cache files
diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java
new file mode 100644
index 0000000..354d930
--- /dev/null
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java
@@ -0,0 +1,186 @@
1/*******************************************************************************
2 * Copyright (c) 2013 BMW Car IT GmbH.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * BMW Car IT - initial API and implementation
10 *******************************************************************************/
11package org.yocto.cmake.managedbuilder.job;
12
13import java.io.IOException;
14import java.util.Arrays;
15import java.util.HashMap;
16import java.util.LinkedList;
17import java.util.Map;
18
19import org.eclipse.cdt.core.CCorePlugin;
20import org.eclipse.cdt.core.envvar.IContributedEnvironment;
21import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
22import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
23import org.eclipse.cdt.core.model.CoreModel;
24import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
25import org.eclipse.cdt.core.settings.model.ICProjectDescription;
26import org.eclipse.cdt.managedbuilder.core.BuildException;
27import org.eclipse.cdt.managedbuilder.core.IConfiguration;
28import org.eclipse.cdt.managedbuilder.core.ITool;
29import org.eclipse.core.resources.IProject;
30import org.eclipse.core.runtime.IPath;
31import org.eclipse.core.runtime.IProgressMonitor;
32import org.eclipse.core.runtime.IStatus;
33import org.eclipse.core.runtime.Status;
34import org.eclipse.core.runtime.jobs.Job;
35import org.eclipse.jface.dialogs.MessageDialog;
36import org.eclipse.swt.widgets.Display;
37import org.eclipse.ui.console.IOConsoleOutputStream;
38import org.yocto.cmake.managedbuilder.Activator;
39import org.yocto.cmake.managedbuilder.YoctoCMakeMessages;
40import org.yocto.cmake.managedbuilder.util.ConsoleUtility;
41import org.yocto.cmake.managedbuilder.util.SystemProcess;
42
43
44public class ExecuteConfigureJob extends Job {
45 private SystemProcess configureProcess;
46 private LinkedList<String> configureCommand;
47 private IProject project;
48 private IConfiguration configuration;
49 private IPath location;
50
51
52 public ExecuteConfigureJob(String name,
53 IProject project, IConfiguration configuration, IPath location) {
54 super(name);
55 this.project = project;
56 this.configuration = configuration;
57 this.location = location;
58 createCommands();
59 createProcesses();
60 }
61
62 protected void createCommands() {
63 configureCommand = new LinkedList<String>();
64
65 ITool[] configure = configuration
66 .getToolsBySuperClassId("org.yocto.cmake.managedbuilder.cmakeconfigure.gnu.exe"); //$NON-NLS-1$
67
68 addCommand(configure[0]);
69
70 try {
71 addFlags(configure[0]);
72 } catch (BuildException e) {
73 // ignore this exception
74 }
75 }
76
77 private void addCommand(ITool configure) {
78 String command = configuration.getToolCommand(configure);
79 configureCommand.add(command);
80 }
81
82 private void addFlags(ITool configure) throws BuildException {
83 String[] flags = configure.getToolCommandFlags(
84 project.getLocation(), location);
85 for (String flag : flags) {
86 if (flag.contains(" ")) { //$NON-NLS-1$
87 String[] separatedFlags = flag.trim().split(" "); //$NON-NLS-1$
88 configureCommand.addAll(Arrays.asList(separatedFlags));
89 } else {
90 configureCommand.add(flag);
91 }
92 }
93 }
94
95 protected void createProcesses() {
96 configureProcess =
97 new SystemProcess(configureCommand, location.toFile(), getEnvVariablesAsMap(project));
98 }
99
100 private Map<String,String> getEnvVariablesAsMap (IProject project) {
101 Map<String, String> result = new HashMap<String, String>();
102
103 ICProjectDescription cpdesc = CoreModel.getDefault().getProjectDescription(project, true);
104 ICConfigurationDescription ccdesc = cpdesc.getActiveConfiguration();
105 IEnvironmentVariableManager manager = CCorePlugin.getDefault().getBuildEnvironmentManager();
106 IContributedEnvironment env = manager.getContributedEnvironment();
107
108 for(IEnvironmentVariable var : env.getVariables(ccdesc)) {
109 result.put(var.getName(), var.getValue());
110 }
111
112 return result;
113 }
114
115 /* (non-Javadoc)
116 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
117 */
118 @Override
119 protected IStatus run(IProgressMonitor monitor) {
120 monitor.beginTask(
121 YoctoCMakeMessages.getString("ExecuteConfigureJob.runConfigure"), 20); //$NON-NLS-1$
122
123 IOConsoleOutputStream cos =
124 ConsoleUtility.getConsoleOutput(YoctoCMakeMessages.getFormattedString("ExecuteConfigureJob.consoleName", //$NON-NLS-1$
125 project.getName()));
126 monitor.worked(1);
127
128 try {
129 return buildProject(monitor, cos);
130 } catch (IOException e) {
131 if(e.getMessage().startsWith("Cannot run program \"cmake\"")) { //$NON-NLS-1$
132 Display.getDefault().asyncExec(new Runnable() {
133 @Override
134 public void run() {
135 MessageDialog.openWarning(null,
136 YoctoCMakeMessages.getString("ExecuteConfigureJob.cmakeWarning.dialogTitle"), //$NON-NLS-1$
137 YoctoCMakeMessages.getString("ExecuteConfigureJob.cmakeWarning.dialogMessage")); //$NON-NLS-1$
138 }
139 });
140 return Status.OK_STATUS;
141 } else {
142 return new Status(Status.ERROR,
143 Activator.PLUGIN_ID, Status.OK,
144 YoctoCMakeMessages.getString("ExecuteConfigureJob.error.couldNotStart"), e); //$NON-NLS-1$
145 }
146 } catch (InterruptedException e) {
147 return new Status(Status.WARNING,
148 Activator.PLUGIN_ID,
149 YoctoCMakeMessages.getString("ExecuteConfigureJob.warning.aborted")); //$NON-NLS-1$
150 } finally {
151 try {
152 cos.close();
153 } catch (IOException e) {
154 cos = null;
155 }
156 }
157 }
158
159 private IStatus buildProject(IProgressMonitor monitor,
160 IOConsoleOutputStream cos) throws IOException, InterruptedException {
161 monitor.subTask(
162 YoctoCMakeMessages.getString("ExecuteConfigureJob.buildingMakefile")); //$NON-NLS-1$
163 configureProcess.start(cos);
164 int exitValue = configureProcess.waitForResultAndStop();
165 monitor.worked(15);
166
167 if (exitValue != 0) {
168 return new Status(Status.ERROR, Activator.PLUGIN_ID,
169 YoctoCMakeMessages.getString("ExecuteConfigureJob.error.buildFailed") + " " + exitValue); //$NON-NLS-1$ //$NON-NLS-2$
170 }
171
172 return Status.OK_STATUS;
173 }
174
175 /* (non-Javadoc)
176 * @see org.eclipse.core.runtime.jobs.Job#canceling()
177 */
178 /**
179 * Cancels the job and interrupts the system process.
180 * {@inheritDoc}
181 */
182 @Override
183 protected void canceling() {
184 configureProcess.interrupt();
185 }
186}
diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/ConsoleUtility.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/ConsoleUtility.java
new file mode 100644
index 0000000..9fb31e5
--- /dev/null
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/ConsoleUtility.java
@@ -0,0 +1,49 @@
1/*******************************************************************************
2 * Copyright (c) 2013 BMW Car IT GmbH.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * BMW Car IT - initial API and implementation
10 *******************************************************************************/
11package org.yocto.cmake.managedbuilder.util;
12
13import org.eclipse.ui.console.ConsolePlugin;
14import org.eclipse.ui.console.IConsole;
15import org.eclipse.ui.console.IOConsoleOutputStream;
16import org.eclipse.ui.console.MessageConsole;
17
18
19public class ConsoleUtility {
20
21 public static IOConsoleOutputStream getConsoleOutput(String consoleName) {
22 return getConsole(consoleName).newOutputStream();
23 }
24
25 public static MessageConsole getConsole(String consoleName) {
26 MessageConsole foundConsole = findConsole(consoleName);
27 if (foundConsole != null) {
28 foundConsole.clearConsole();
29 } else {
30 foundConsole = new MessageConsole(consoleName, null);
31 ConsolePlugin.getDefault().
32 getConsoleManager().addConsoles(new IConsole[] { foundConsole });
33 }
34
35 return foundConsole;
36 }
37
38 public static MessageConsole findConsole(String consoleName) {
39 IConsole[] consoles =
40 ConsolePlugin.getDefault().getConsoleManager().getConsoles();
41 for (IConsole console : consoles) {
42 if (console.getName().equals(consoleName)) {
43 return (MessageConsole) console;
44 }
45 }
46
47 return null;
48 }
49}
diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java
new file mode 100644
index 0000000..9ca6e60
--- /dev/null
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java
@@ -0,0 +1,118 @@
1/*******************************************************************************
2 * Copyright (c) 2013 BMW Car IT GmbH.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * BMW Car IT - initial API and implementation
10 *******************************************************************************/
11package org.yocto.cmake.managedbuilder.util;
12
13import java.io.File;
14import java.io.IOException;
15import java.io.InputStream;
16import java.io.OutputStream;
17import java.util.LinkedList;
18import java.util.Map;
19
20public class SystemProcess {
21
22 private LinkedList<String> command = new LinkedList<String>();
23 private File workingDirectory;
24 private ProcessBuilder builder;
25 private Process process;
26 private StreamPipe outputRedirector;
27
28 public SystemProcess(LinkedList<String> command) {
29 this(command, null);
30 }
31
32 public SystemProcess(LinkedList<String> command, File directory) {
33 this(command, directory, null);
34 }
35
36 public SystemProcess(LinkedList<String> command, File directory, Map<String, String> additionalEnvironmentVariables) {
37 super();
38 this.command = command;
39 if (directory != null) {
40 this.workingDirectory = directory;
41 }
42 setUpProcessBuilder(additionalEnvironmentVariables);
43 }
44
45 private void setUpProcessBuilder(Map<String, String> additionalEnvironmentVariables) {
46 builder = new ProcessBuilder(command);
47 if (workingDirectory != null) {
48 builder.directory(workingDirectory);
49 }
50 builder.redirectErrorStream(true);
51
52 if(additionalEnvironmentVariables != null && !additionalEnvironmentVariables.isEmpty()) {
53 builder.environment().putAll(additionalEnvironmentVariables);
54 }
55 }
56
57 public void start(OutputStream out) throws IOException {
58 if (builder != null) {
59 process = builder.start();
60 outputRedirector = redirectOutput(process, out);
61 }
62 }
63
64 public int waitForResultAndStop() throws InterruptedException {
65 if (process == null) {
66 return -1;
67 }
68
69 process.waitFor();
70 outputRedirector.interrupt();
71
72 return process.exitValue();
73 }
74
75 public void interrupt() {
76 process.destroy();
77 }
78
79 private StreamPipe redirectOutput(Process process, OutputStream out) {
80 InputStream in = process.getInputStream();
81 StreamPipe stdoutPipe = new StreamPipe(in, out);
82 stdoutPipe.start();
83
84 return stdoutPipe;
85 }
86
87
88 private class StreamPipe extends Thread {
89 private InputStream in;
90 private OutputStream out;
91 boolean shutdown = false;
92
93 public StreamPipe(InputStream in, OutputStream out) {
94 this.in = in;
95 this.out = out;
96 }
97
98 @Override
99 public void run() {
100 byte[] buffer = new byte[1024];
101 int length = 0;
102
103 try {
104 while(!shutdown && ((length = in.read(buffer)) > -1)) {
105 out.write(buffer, 0, length);
106 }
107 } catch (IOException e) {
108 e.printStackTrace();
109 }
110 }
111
112 @Override
113 public void interrupt() {
114 shutdown = true;
115 super.interrupt();
116 }
117 }
118}