From 41ac47d732eed8392d60d0f6773e5a279d49b999 Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 12 Dec 2013 13:36:50 +0100 Subject: initial commit of Enea Linux 3.1 Migrated from the internal git server on the dora-enea branch Signed-off-by: Adrian Dudau --- .../org/yocto/cmake/managedbuilder/Activator.java | 50 ++++ .../YoctoCMakeMakefileGenerator.java | 281 +++++++++++++++++++++ .../cmake/managedbuilder/YoctoCMakeMessages.java | 57 +++++ .../managedbuilder/YoctoCMakeMessages.properties | 29 +++ .../managedbuilder/job/ExecuteConfigureJob.java | 186 ++++++++++++++ .../cmake/managedbuilder/util/ConsoleUtility.java | 49 ++++ .../cmake/managedbuilder/util/SystemProcess.java | 118 +++++++++ 7 files changed, 770 insertions(+) create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/Activator.java create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMakefileGenerator.java create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.java create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/YoctoCMakeMessages.properties create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/job/ExecuteConfigureJob.java create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/ConsoleUtility.java create mode 100644 plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java (limited to 'plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder') 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 @@ +/******************************************************************************* + * Copyright (c) 2013 BMW Car IT GmbH. + * 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 + * + * Contributors: + * BMW Car IT - initial API and implementation + *******************************************************************************/ +package org.yocto.cmake.managedbuilder; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +public class Activator extends Plugin { + + /** The plug-in ID. */ + public static final String PLUGIN_ID = "org.yocto.cmake.managedbuilder"; //$NON-NLS-1$ + + /** The shared activator instance. */ + private static Activator plugin; + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * @return the shared instance of the Activator + */ + public static Activator getDefault() { + return plugin; + } +} 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 @@ +/******************************************************************************* + * Copyright (c) 2013 BMW Car IT GmbH. + * 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 + * + * Contributors: + * BMW Car IT - initial API and implementation + *******************************************************************************/ +package org.yocto.cmake.managedbuilder; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.eclipse.cdt.managedbuilder.core.IBuilder; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator2; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.jobs.Job; +import org.yocto.cmake.managedbuilder.job.ExecuteConfigureJob; +import org.yocto.sdk.ide.utils.YoctoSDKUtils; + +public class YoctoCMakeMakefileGenerator implements IManagedBuilderMakefileGenerator2 { + + private static final String TOOLCHAINCMAKE_FILE_NAME = "toolchain.cmake"; //$NON-NLS-1$ + private static final String MAKEFILE_NAME = "Makefile"; //$NON-NLS-1$ + private static final String CMAKE_FILE_NAME = "CMakeLists.txt"; //$NON-NLS-1$ + private static final String CMAKECACHE_FILE_NAME = "CMakeCache.txt"; //$NON-NLS-1$ + + private IProject project; + private int lastBuildInfoChecksum = 0; + private IConfiguration configuration; + private IProgressMonitor monitor; + private IPath buildDir = null; + + @Override + public String getMakefileName() { + return MAKEFILE_NAME; + } + + @Override + public IPath getBuildWorkingDir() { + IPath buildWorkingDir = null; + + if (buildDir != null) { + buildWorkingDir = buildDir.removeFirstSegments(1); + } + + return buildWorkingDir; + } + + @Override + public boolean isGeneratedResource(IResource resource) { + return false; + } + + @Override + public void initialize(IProject project, IManagedBuildInfo info, + IProgressMonitor monitor) { + this.project = project; + this.configuration = info.getDefaultConfiguration(); + this.monitor = monitor; + + if (info.getDefaultConfiguration() != null) { + buildDir = project.getFolder(info.getConfigurationName()).getFullPath(); + } + } + + @Override + public void initialize(int buildKind, IConfiguration configuration, IBuilder builder, + IProgressMonitor monitor) { + this.project = configuration.getOwner().getProject(); + this.configuration = configuration; + this.monitor = monitor; + this.buildDir = project.getFolder(configuration.getName()).getFullPath(); + } + + @Override + public void generateDependencies() throws CoreException { + // nothing to do here + } + + @Override + public void regenerateDependencies(boolean force) throws CoreException { + generateDependencies(); + } + + @Override + public MultiStatus generateMakefiles(IResourceDelta delta) + throws CoreException { + int currentBuildInfoChecksum = ManagedBuildManager.getBuildInfo(project).hashCode(); + + IFile cmakeFile = project.getFile(CMAKE_FILE_NAME); + IResourceDelta cmakeDelta = delta.findMember(cmakeFile.getProjectRelativePath()); + IResourceDelta[] deltas = delta + .getAffectedChildren(IResourceDelta.ADDED | IResourceDelta.REMOVED); + + if (deltas.length > 0 || cmakeDelta != null || currentBuildInfoChecksum != lastBuildInfoChecksum) { + lastBuildInfoChecksum = currentBuildInfoChecksum; + return regenerateMakefiles(); + } else { + // CMake is not needed to run prior to building + // just return that makefile generation is completed + return new MultiStatus( + ManagedBuilderCorePlugin.getUniqueIdentifier(), IStatus.OK, + new String(YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.ok.makefilesStillValid")), null); //$NON-NLS-1$ + } + } + + @Override + public MultiStatus regenerateMakefiles() throws CoreException { + String taskName = + YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.configure.creatingMakefiles"); //$NON-NLS-1$ + monitor.beginTask(taskName, 20); + + IFile cmakeFile = project.getFile(CMAKE_FILE_NAME); + if (!cmakeFile.exists()) { + return new MultiStatus(ManagedBuilderCorePlugin.getUniqueIdentifier(), IStatus.CANCEL, + new String(YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.cancel.missingCMakeList")), null); //$NON-NLS-1$ + } + + // Retrieve Build directory + IPath workingDir = getBuildWorkingDir(); + IPath location = project.getLocation().append(workingDir); + monitor.worked(1); + + // Create build directory if it doesn't exist + if (!location.toFile().exists()) { + monitor.subTask( + YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.creatingBuildDirectory")); //$NON-NLS-1$ + location.toFile().mkdirs(); + } else { + monitor.subTask( + YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.removingCacheFiles")); //$NON-NLS-1$ + IFile cmakeCache = project.getFile(workingDir.append(CMAKECACHE_FILE_NAME)); + cmakeCache.delete(true, monitor); + } + monitor.setTaskName(taskName); + + createToolchainCMakeFile(workingDir); + + // Create the Makefiles by executing cmake + ExecuteConfigureJob job = + new ExecuteConfigureJob( + YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.configureJob.name"), //$NON-NLS-1$ + project, configuration, location); + job.setPriority(Job.BUILD); + job.setUser(false); + + job.schedule(); + try { + job.join(); + monitor.done(); + return new MultiStatus( + Activator.PLUGIN_ID, job.getResult().getSeverity(), + job.getResult().getMessage(), null); + } catch (InterruptedException e) { + return new MultiStatus( + Activator.PLUGIN_ID, + IStatus.ERROR, new String( + YoctoCMakeMessages.getString("YoctoCMakeMakefileGenerator.error.makeFileGenerationFailed")), null); //$NON-NLS-1$ + } + } + + private String createCMakeSetStatement(String variable, String value, String cacheOption) { + String setStatement = "set("; //$NON-NLS-1$ + setStatement += variable + " " + value; //$NON-NLS-1$ + if(cacheOption != null && !cacheOption.equals("")) { //$NON-NLS-1$ + setStatement += " " + cacheOption; //$NON-NLS-1$ + } + setStatement += ")\n"; //$NON-NLS-1$ + return setStatement; + } + + // Considered poky's cmake.bbclass for this method + private void createToolchainCMakeFile(IPath workingDir) { + String toolchainCMakeFileContentAsString = "# CMake system name must be something like \"Linux\".\n" + //$NON-NLS-1$ + "# This is important for cross-compiling.\n"; //$NON-NLS-1$ + + String targetArchValue = YoctoSDKUtils.getEnvValue(project, "TARGET_ARCH"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_SYSTEM_PROCESSOR", targetArchValue, null); //$NON-NLS-1$ + + String oeCMakeCCompilerValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_COMPILER"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_COMPILER", oeCMakeCCompilerValue, null); //$NON-NLS-1$ + + String oeCMakeCXXCompilerValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_COMPILER"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_COMPILER", oeCMakeCXXCompilerValue, null); //$NON-NLS-1$ + + String oeCMakeCFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_FLAGS"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_FLAGS", //$NON-NLS-1$ + "\"" + oeCMakeCFlagsValue + "\"", "CACHE STRING \"CFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + String oeCMakeCXXFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_FLAGS"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_FLAGS", //$NON-NLS-1$ + "\"" + oeCMakeCXXFlagsValue + "\"", "CACHE STRING \"CXXFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + String oeCMakeCFlagsReleaseValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_FLAGS_RELEASE"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_FLAGS_RELEASE", //$NON-NLS-1$ + "\"" + oeCMakeCFlagsReleaseValue + "\"", "CACHE STRING \"CFLAGS for release\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + String oeCMakeCXXFlagsReleaseValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_FLAGS_RELEASE"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_FLAGS_RELEASE", //$NON-NLS-1$ + "\"" + oeCMakeCXXFlagsReleaseValue + "\"", "CACHE STRING \"CXXFLAGS for release\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + String oeCMakeCLinkFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_C_LINK_FLAGS"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_C_LINK_FLAGS", //$NON-NLS-1$ + "\"" + oeCMakeCLinkFlagsValue + "\"", "CACHE STRING \"LDFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + String oeCMakeCXXLinkFlagsValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_CXX_LINK_FLAGS"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_CXX_LINK_FLAGS", //$NON-NLS-1$ + "\"" + oeCMakeCXXLinkFlagsValue + "\"", "CACHE STRING \"LDFLAGS\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$ + toolchainCMakeFileContentAsString += "# only search in the paths provided so cmake doesnt pick\n"; //$NON-NLS-1$ + toolchainCMakeFileContentAsString += "# up libraries and tools from the native build machine\n"; //$NON-NLS-1$ + + String findRootPathValue = YoctoSDKUtils.getEnvValue(project, "STAGING_DIR_HOST"); //$NON-NLS-1$ + findRootPathValue += " "; //$NON-NLS-1$ + findRootPathValue += YoctoSDKUtils.getEnvValue(project, "STAGING_DIR_NATIVE"); //$NON-NLS-1$ + findRootPathValue += " "; //$NON-NLS-1$ + findRootPathValue += YoctoSDKUtils.getEnvValue(project, "CROSS_DIR"); //$NON-NLS-1$ + findRootPathValue += " "; //$NON-NLS-1$ + findRootPathValue += YoctoSDKUtils.getEnvValue(project, "OECMAKE_PERLNATIVE_DIR"); //$NON-NLS-1$ + findRootPathValue += " "; //$NON-NLS-1$ + findRootPathValue += YoctoSDKUtils.getEnvValue(project, "OECMAKE_EXTRA_ROOT_PATH"); //$NON-NLS-1$ + findRootPathValue += " "; //$NON-NLS-1$ + findRootPathValue += YoctoSDKUtils.getEnvValue(project, "EXTERNAL_TOOLCHAIN"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH", findRootPathValue, null); //$NON-NLS-1$ + + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", "ONLY", null); //$NON-NLS-1$ //$NON-NLS-2$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", "ONLY", null); //$NON-NLS-1$ //$NON-NLS-2$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", "ONLY", null); //$NON-NLS-1$ //$NON-NLS-2$ + toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$ + + toolchainCMakeFileContentAsString += "# Use qt.conf settings\n"; //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("ENV{QT_CONF_PATH}", "qt.conf", null); //$NON-NLS-1$ //$NON-NLS-2$ + toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$ + + toolchainCMakeFileContentAsString += "# We need to set the rpath to the correct directory as cmake does not provide any\n"; //$NON-NLS-1$ + toolchainCMakeFileContentAsString += "# directory as rpath by default\n"; //$NON-NLS-1$ + + String oeCMakeRPathValue = YoctoSDKUtils.getEnvValue(project, "OECMAKE_RPATH"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_INSTALL_RPATH", oeCMakeRPathValue, null); //$NON-NLS-1$ + + toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$ + toolchainCMakeFileContentAsString += "# Use native cmake modules\n"; //$NON-NLS-1$ + + String stagingDatadirValue = YoctoSDKUtils.getEnvValue(project, "STAGING_DATADIR"); //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_MODULE_PATH", //$NON-NLS-1$ + stagingDatadirValue + "/cmake/Modules/", null); //$NON-NLS-1$ + + toolchainCMakeFileContentAsString += "\n"; //$NON-NLS-1$ + toolchainCMakeFileContentAsString += "# add for non /usr/lib libdir, e.g. /usr/lib64\n"; //$NON-NLS-1$ + toolchainCMakeFileContentAsString += createCMakeSetStatement("CMAKE_LIBRARY_PATH", //$NON-NLS-1$ + "${libdir} ${base_libdir}", null); //$NON-NLS-1$ + + InputStream toolchainCMakeFileContent = new ByteArrayInputStream(toolchainCMakeFileContentAsString.getBytes()); + + IFile toolchainCMakeFile = project.getFile(TOOLCHAINCMAKE_FILE_NAME); + try { + if (toolchainCMakeFile.exists()) { + toolchainCMakeFile.delete(true, monitor); + } + toolchainCMakeFile.create(toolchainCMakeFileContent, true, monitor); + } catch (CoreException e) { + e.printStackTrace(); + } + } +} 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 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * 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 + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.cmake.managedbuilder; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class YoctoCMakeMessages { + + private static final String RESOURCE_BUNDLE= YoctoCMakeMessages.class.getName(); + private static ResourceBundle fgResourceBundle; + static { + try { + fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE); + } catch (MissingResourceException x) { + fgResourceBundle = null; + } + } + + private YoctoCMakeMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } catch (NullPointerException e) { + return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * Gets a string from the resource bundle and formats it with the argument + * + * @param key the string used to get the bundle value, must not be null + */ + public static String getFormattedString(String key, Object arg) { + return MessageFormat.format(getString(key), new Object[] { arg }); + } + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } +} 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 @@ +#/******************************************************************************* +# * Copyright (c) 2013 BMW Car IT GmbH. +# * 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 +# * +# * Contributors: +# * BMW Car IT - initial implementation +# *******************************************************************************/ + +# Job +ExecuteConfigureJob.runConfigure=Running configure +ExecuteConfigureJob.consoleName=Configure using CMake [{0}] +ExecuteConfigureJob.buildingMakefile=Building Makefile +ExecuteConfigureJob.warning.aborted=Build of project has been aborted +ExecuteConfigureJob.error.couldNotStart=Build of project could not be started +ExecuteConfigureJob.error.buildFailed=Build of project failed +ExecuteConfigureJob.cmakeWarning.dialogTitle=Unable to run command "cmake" +ExecuteConfigureJob.cmakeWarning.dialogMessage=Please make sure that cmake is installed properly on this machine. + +# File generator +YoctoCMakeMakefileGenerator.configureJob.name=Configuring project +YoctoCMakeMakefileGenerator.configure.creatingMakefiles=Generating Makefiles using CMake +YoctoCMakeMakefileGenerator.cancel.missingCMakeList=CMakeLists.txt file is missing +YoctoCMakeMakefileGenerator.creatingBuildDirectory=Creating build directory +YoctoCMakeMakefileGenerator.error.makeFileGenerationFailed=Makefile generation failed during configuration process +YoctoCMakeMakefileGenerator.ok.makefilesStillValid=Makefiles are still valid. +YoctoCMakeMakefileGenerator.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 @@ +/******************************************************************************* + * Copyright (c) 2013 BMW Car IT GmbH. + * 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 + * + * Contributors: + * BMW Car IT - initial API and implementation + *******************************************************************************/ +package org.yocto.cmake.managedbuilder.job; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.envvar.IContributedEnvironment; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; +import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.console.IOConsoleOutputStream; +import org.yocto.cmake.managedbuilder.Activator; +import org.yocto.cmake.managedbuilder.YoctoCMakeMessages; +import org.yocto.cmake.managedbuilder.util.ConsoleUtility; +import org.yocto.cmake.managedbuilder.util.SystemProcess; + + +public class ExecuteConfigureJob extends Job { + private SystemProcess configureProcess; + private LinkedList configureCommand; + private IProject project; + private IConfiguration configuration; + private IPath location; + + + public ExecuteConfigureJob(String name, + IProject project, IConfiguration configuration, IPath location) { + super(name); + this.project = project; + this.configuration = configuration; + this.location = location; + createCommands(); + createProcesses(); + } + + protected void createCommands() { + configureCommand = new LinkedList(); + + ITool[] configure = configuration + .getToolsBySuperClassId("org.yocto.cmake.managedbuilder.cmakeconfigure.gnu.exe"); //$NON-NLS-1$ + + addCommand(configure[0]); + + try { + addFlags(configure[0]); + } catch (BuildException e) { + // ignore this exception + } + } + + private void addCommand(ITool configure) { + String command = configuration.getToolCommand(configure); + configureCommand.add(command); + } + + private void addFlags(ITool configure) throws BuildException { + String[] flags = configure.getToolCommandFlags( + project.getLocation(), location); + for (String flag : flags) { + if (flag.contains(" ")) { //$NON-NLS-1$ + String[] separatedFlags = flag.trim().split(" "); //$NON-NLS-1$ + configureCommand.addAll(Arrays.asList(separatedFlags)); + } else { + configureCommand.add(flag); + } + } + } + + protected void createProcesses() { + configureProcess = + new SystemProcess(configureCommand, location.toFile(), getEnvVariablesAsMap(project)); + } + + private Map getEnvVariablesAsMap (IProject project) { + Map result = new HashMap(); + + ICProjectDescription cpdesc = CoreModel.getDefault().getProjectDescription(project, true); + ICConfigurationDescription ccdesc = cpdesc.getActiveConfiguration(); + IEnvironmentVariableManager manager = CCorePlugin.getDefault().getBuildEnvironmentManager(); + IContributedEnvironment env = manager.getContributedEnvironment(); + + for(IEnvironmentVariable var : env.getVariables(ccdesc)) { + result.put(var.getName(), var.getValue()); + } + + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask( + YoctoCMakeMessages.getString("ExecuteConfigureJob.runConfigure"), 20); //$NON-NLS-1$ + + IOConsoleOutputStream cos = + ConsoleUtility.getConsoleOutput(YoctoCMakeMessages.getFormattedString("ExecuteConfigureJob.consoleName", //$NON-NLS-1$ + project.getName())); + monitor.worked(1); + + try { + return buildProject(monitor, cos); + } catch (IOException e) { + if(e.getMessage().startsWith("Cannot run program \"cmake\"")) { //$NON-NLS-1$ + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + MessageDialog.openWarning(null, + YoctoCMakeMessages.getString("ExecuteConfigureJob.cmakeWarning.dialogTitle"), //$NON-NLS-1$ + YoctoCMakeMessages.getString("ExecuteConfigureJob.cmakeWarning.dialogMessage")); //$NON-NLS-1$ + } + }); + return Status.OK_STATUS; + } else { + return new Status(Status.ERROR, + Activator.PLUGIN_ID, Status.OK, + YoctoCMakeMessages.getString("ExecuteConfigureJob.error.couldNotStart"), e); //$NON-NLS-1$ + } + } catch (InterruptedException e) { + return new Status(Status.WARNING, + Activator.PLUGIN_ID, + YoctoCMakeMessages.getString("ExecuteConfigureJob.warning.aborted")); //$NON-NLS-1$ + } finally { + try { + cos.close(); + } catch (IOException e) { + cos = null; + } + } + } + + private IStatus buildProject(IProgressMonitor monitor, + IOConsoleOutputStream cos) throws IOException, InterruptedException { + monitor.subTask( + YoctoCMakeMessages.getString("ExecuteConfigureJob.buildingMakefile")); //$NON-NLS-1$ + configureProcess.start(cos); + int exitValue = configureProcess.waitForResultAndStop(); + monitor.worked(15); + + if (exitValue != 0) { + return new Status(Status.ERROR, Activator.PLUGIN_ID, + YoctoCMakeMessages.getString("ExecuteConfigureJob.error.buildFailed") + " " + exitValue); //$NON-NLS-1$ //$NON-NLS-2$ + } + + return Status.OK_STATUS; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#canceling() + */ + /** + * Cancels the job and interrupts the system process. + * {@inheritDoc} + */ + @Override + protected void canceling() { + configureProcess.interrupt(); + } +} 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 @@ +/******************************************************************************* + * Copyright (c) 2013 BMW Car IT GmbH. + * 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 + * + * Contributors: + * BMW Car IT - initial API and implementation + *******************************************************************************/ +package org.yocto.cmake.managedbuilder.util; + +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IOConsoleOutputStream; +import org.eclipse.ui.console.MessageConsole; + + +public class ConsoleUtility { + + public static IOConsoleOutputStream getConsoleOutput(String consoleName) { + return getConsole(consoleName).newOutputStream(); + } + + public static MessageConsole getConsole(String consoleName) { + MessageConsole foundConsole = findConsole(consoleName); + if (foundConsole != null) { + foundConsole.clearConsole(); + } else { + foundConsole = new MessageConsole(consoleName, null); + ConsolePlugin.getDefault(). + getConsoleManager().addConsoles(new IConsole[] { foundConsole }); + } + + return foundConsole; + } + + public static MessageConsole findConsole(String consoleName) { + IConsole[] consoles = + ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + for (IConsole console : consoles) { + if (console.getName().equals(consoleName)) { + return (MessageConsole) console; + } + } + + return null; + } +} 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 @@ +/******************************************************************************* + * Copyright (c) 2013 BMW Car IT GmbH. + * 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 + * + * Contributors: + * BMW Car IT - initial API and implementation + *******************************************************************************/ +package org.yocto.cmake.managedbuilder.util; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.LinkedList; +import java.util.Map; + +public class SystemProcess { + + private LinkedList command = new LinkedList(); + private File workingDirectory; + private ProcessBuilder builder; + private Process process; + private StreamPipe outputRedirector; + + public SystemProcess(LinkedList command) { + this(command, null); + } + + public SystemProcess(LinkedList command, File directory) { + this(command, directory, null); + } + + public SystemProcess(LinkedList command, File directory, Map additionalEnvironmentVariables) { + super(); + this.command = command; + if (directory != null) { + this.workingDirectory = directory; + } + setUpProcessBuilder(additionalEnvironmentVariables); + } + + private void setUpProcessBuilder(Map additionalEnvironmentVariables) { + builder = new ProcessBuilder(command); + if (workingDirectory != null) { + builder.directory(workingDirectory); + } + builder.redirectErrorStream(true); + + if(additionalEnvironmentVariables != null && !additionalEnvironmentVariables.isEmpty()) { + builder.environment().putAll(additionalEnvironmentVariables); + } + } + + public void start(OutputStream out) throws IOException { + if (builder != null) { + process = builder.start(); + outputRedirector = redirectOutput(process, out); + } + } + + public int waitForResultAndStop() throws InterruptedException { + if (process == null) { + return -1; + } + + process.waitFor(); + outputRedirector.interrupt(); + + return process.exitValue(); + } + + public void interrupt() { + process.destroy(); + } + + private StreamPipe redirectOutput(Process process, OutputStream out) { + InputStream in = process.getInputStream(); + StreamPipe stdoutPipe = new StreamPipe(in, out); + stdoutPipe.start(); + + return stdoutPipe; + } + + + private class StreamPipe extends Thread { + private InputStream in; + private OutputStream out; + boolean shutdown = false; + + public StreamPipe(InputStream in, OutputStream out) { + this.in = in; + this.out = out; + } + + @Override + public void run() { + byte[] buffer = new byte[1024]; + int length = 0; + + try { + while(!shutdown && ((length = in.read(buffer)) > -1)) { + out.write(buffer, 0, length); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void interrupt() { + shutdown = true; + super.interrupt(); + } + } +} -- cgit v1.2.3-54-g00ecf