mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Bug 322458 - Implemented extension to allow the CommonBuilder.invokeBuilder method to be overriden.
This commit is contained in:
parent
927fba2490
commit
b45080a6f7
7 changed files with 761 additions and 779 deletions
|
@ -1316,7 +1316,7 @@ Additional special types exist to flag options of special relevance to the build
|
|||
<attribute name="browseFilterExtensions" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
An optional value that specifies a comma-separated string of file-extension filters for the underlying file browse-dialog. For filters with multiple extensions, use semicolon as a separator - eg. "*.lib;*.a;*.cmd,*.*". This attribute only applies when user chooses to browse the file-system, and only when browseType is 'file'.
|
||||
An optional value that specifies a comma-separated string of file-extension filters for the underlying file browse-dialog. For filters with multiple extensions, use semicolon as a separator - eg. "*.lib;*.a;*.cmd,*.*". This attribute only applies when user chooses to browse the file-system, and only when browseType is 'file'.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
|
@ -1741,6 +1741,16 @@ If the builder supports specifying custom number of parallel jobs, the option de
|
|||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="buildRunner" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
A runner for the build. Overrides or extends the built-in external and internal build runners.
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.managedbuilder.core.IBuildRunner"/>
|
||||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
|
|
|
@ -0,0 +1,389 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Wind River 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
|
||||
*
|
||||
* Contributors:
|
||||
* Wind River Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext;
|
||||
import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set;
|
||||
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.ICommandLauncher;
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
|
||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCProfileInstance;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
|
||||
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
|
||||
import org.eclipse.cdt.newmake.internal.core.StreamMonitor;
|
||||
import org.eclipse.cdt.utils.CommandLineUtil;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
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.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author dschaefer
|
||||
* @since 8.0
|
||||
*/
|
||||
public class ExternalBuildRunner implements IBuildRunner {
|
||||
|
||||
private static final String TYPE_CLEAN = "ManagedMakeBuilder.type.clean"; //$NON-NLS-1$
|
||||
private static final String TYPE_INC = "ManagedMakeBuider.type.incremental"; //$NON-NLS-1$
|
||||
private static final String CONSOLE_HEADER = "ManagedMakeBuilder.message.console.header"; //$NON-NLS-1$
|
||||
private static final String WARNING_UNSUPPORTED_CONFIGURATION = "ManagedMakeBuilder.warning.unsupported.configuration"; //$NON-NLS-1$
|
||||
|
||||
public boolean invokeBuild(int kind, IProject project, IConfiguration configuration,
|
||||
IBuilder builder, IConsole console, IMarkerGenerator markerGenerator,
|
||||
IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor) throws CoreException {
|
||||
return invokeExternalBuild(kind, project, configuration, builder, console,
|
||||
markerGenerator, projectBuilder, monitor);
|
||||
}
|
||||
|
||||
protected boolean invokeExternalBuild(int kind, IProject project, IConfiguration configuration,
|
||||
IBuilder builder, IConsole console, IMarkerGenerator markerGenerator,
|
||||
IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor) throws CoreException {
|
||||
boolean isClean = false;
|
||||
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask(ManagedMakeMessages.getResourceString("MakeBuilder.Invoking_Make_Builder") + project.getName(), 100); //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
IPath buildCommand = builder.getBuildCommand();
|
||||
if (buildCommand != null) {
|
||||
OutputStream cos = console.getOutputStream();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
String[] consoleHeader = new String[3];
|
||||
switch (kind) {
|
||||
case IncrementalProjectBuilder.FULL_BUILD:
|
||||
case IncrementalProjectBuilder.INCREMENTAL_BUILD:
|
||||
case IncrementalProjectBuilder.AUTO_BUILD:
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_INC);
|
||||
break;
|
||||
case IncrementalProjectBuilder.CLEAN_BUILD:
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_CLEAN);
|
||||
break;
|
||||
}
|
||||
|
||||
consoleHeader[1] = configuration.getName();
|
||||
consoleHeader[2] = project.getName();
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(ManagedMakeMessages.getFormattedString(CONSOLE_HEADER, consoleHeader));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
if(!configuration.isSupported()){
|
||||
buf.append(ManagedMakeMessages.getFormattedString(WARNING_UNSUPPORTED_CONFIGURATION,
|
||||
new String[] { configuration.getName(), configuration.getToolChain().getName() }));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
cos.write(buf.toString().getBytes());
|
||||
cos.flush();
|
||||
|
||||
// remove all markers for this project
|
||||
IWorkspace workspace = project.getWorkspace();
|
||||
IMarker[] markers = project.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
|
||||
if (markers != null)
|
||||
workspace.deleteMarkers(markers);
|
||||
|
||||
IPath workingDirectory = ManagedBuildManager.getBuildLocation(configuration, builder);
|
||||
URI workingDirectoryURI = ManagedBuildManager.getBuildLocationURI(configuration, builder);
|
||||
|
||||
String[] targets = getTargets(kind, builder);
|
||||
if (targets.length != 0 && targets[targets.length - 1].equals(builder.getCleanBuildTarget()))
|
||||
isClean = true;
|
||||
|
||||
String errMsg = null;
|
||||
ICommandLauncher launcher = builder.getCommandLauncher();
|
||||
launcher.setProject(project);
|
||||
// Print the command for visual interaction.
|
||||
launcher.showCommand(true);
|
||||
|
||||
// Set the environment
|
||||
String[] env = getEnvStrings(getEnvironment(builder));
|
||||
String[] buildArguments = targets;
|
||||
|
||||
String[] newArgs = CommandLineUtil.argumentsToArray(builder.getBuildArguments());
|
||||
buildArguments = new String[targets.length + newArgs.length];
|
||||
System.arraycopy(newArgs, 0, buildArguments, 0, newArgs.length);
|
||||
System.arraycopy(targets, 0, buildArguments, newArgs.length, targets.length);
|
||||
|
||||
QualifiedName qName = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "progressMonitor"); //$NON-NLS-1$
|
||||
Integer last = (Integer)project.getSessionProperty(qName);
|
||||
if (last == null) {
|
||||
last = new Integer(100);
|
||||
}
|
||||
ErrorParserManager epm = new ErrorParserManager(project, workingDirectoryURI, markerGenerator, builder.getErrorParsers());
|
||||
epm.setOutputStream(cos);
|
||||
StreamMonitor streamMon = new StreamMonitor(new SubProgressMonitor(monitor, 100), epm, last.intValue());
|
||||
OutputStream stdout = streamMon;
|
||||
OutputStream stderr = streamMon;
|
||||
|
||||
// Sniff console output for scanner info
|
||||
ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, project, configuration, workingDirectory, markerGenerator, null);
|
||||
OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream());
|
||||
OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream());
|
||||
Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory, monitor);
|
||||
if (p != null) {
|
||||
try {
|
||||
// Close the input of the Process explicitly.
|
||||
// We will never write to it.
|
||||
p.getOutputStream().close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
// Before launching give visual cues via the monitor
|
||||
monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Invoking_Command") + launcher.getCommandLine()); //$NON-NLS-1$
|
||||
if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0))
|
||||
!= ICommandLauncher.OK)
|
||||
errMsg = launcher.getErrorMessage();
|
||||
monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Updating_project")); //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
// Do not allow the cancel of the refresh, since the builder is external
|
||||
// to Eclipse, files may have been created/modified and we will be out-of-sync.
|
||||
// The caveat is for hugue projects, it may take sometimes at every build.
|
||||
|
||||
// TODO should only refresh output folders
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
} else {
|
||||
errMsg = launcher.getErrorMessage();
|
||||
}
|
||||
project.setSessionProperty(qName, !monitor.isCanceled() && !isClean ? new Integer(streamMon.getWorkDone()) : null);
|
||||
|
||||
if (errMsg != null) {
|
||||
buf = new StringBuffer(buildCommand.toString() + " "); //$NON-NLS-1$
|
||||
for (String arg : buildArguments) {
|
||||
buf.append(arg);
|
||||
buf.append(' ');
|
||||
}
|
||||
|
||||
String errorDesc = ManagedMakeMessages.getFormattedString("MakeBuilder.buildError", buf.toString()); //$NON-NLS-1$
|
||||
buf = new StringBuffer(errorDesc);
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
cos.write(buf.toString().getBytes());
|
||||
cos.flush();
|
||||
}
|
||||
|
||||
stdout.close();
|
||||
stderr.close();
|
||||
|
||||
monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Creating_Markers")); //$NON-NLS-1$
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
cos.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
throw new CoreException(new Status(IStatus.ERROR,
|
||||
ManagedBuilderCorePlugin.getUniqueIdentifier(),
|
||||
e.getLocalizedMessage(),
|
||||
e));
|
||||
} finally {
|
||||
monitor.done();
|
||||
}
|
||||
return (isClean);
|
||||
}
|
||||
|
||||
protected String[] getTargets(int kind, IBuilder builder) {
|
||||
String targetsArray[] = null;
|
||||
|
||||
if(kind != IncrementalProjectBuilder.CLEAN_BUILD && !builder.isCustomBuilder() && builder.isManagedBuildOn()){
|
||||
IConfiguration cfg = builder.getParent().getParent();
|
||||
String preBuildStep = cfg.getPrebuildStep();
|
||||
try {
|
||||
preBuildStep = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(
|
||||
preBuildStep,
|
||||
"", //$NON-NLS-1$
|
||||
" ", //$NON-NLS-1$
|
||||
IBuildMacroProvider.CONTEXT_CONFIGURATION,
|
||||
cfg);
|
||||
} catch (BuildMacroException e) {
|
||||
}
|
||||
|
||||
if(preBuildStep != null && preBuildStep.length() != 0){
|
||||
targetsArray = new String[]{"pre-build", "main-build"}; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
if(targetsArray == null){
|
||||
String targets = ""; //$NON-NLS-1$
|
||||
switch (kind) {
|
||||
case IncrementalProjectBuilder.AUTO_BUILD :
|
||||
targets = builder.getAutoBuildTarget();
|
||||
break;
|
||||
case IncrementalProjectBuilder.INCREMENTAL_BUILD : // now treated as the same!
|
||||
case IncrementalProjectBuilder.FULL_BUILD :
|
||||
targets = builder.getIncrementalBuildTarget();
|
||||
break;
|
||||
case IncrementalProjectBuilder.CLEAN_BUILD :
|
||||
targets = builder.getCleanBuildTarget();
|
||||
break;
|
||||
}
|
||||
|
||||
targetsArray = CommandLineUtil.argumentsToArray(targets);
|
||||
}
|
||||
|
||||
return targetsArray;
|
||||
}
|
||||
|
||||
protected Map<String, String> getEnvironment(IBuilder builder) throws CoreException {
|
||||
Map<String, String> envMap = new HashMap<String, String>();
|
||||
if (builder.appendEnvironment()) {
|
||||
ICConfigurationDescription cfgDes = ManagedBuildManager.getDescriptionForConfiguration(builder.getParent().getParent());
|
||||
IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager();
|
||||
IEnvironmentVariable[] vars = mngr.getVariables(cfgDes, true);
|
||||
for (IEnvironmentVariable var : vars) {
|
||||
envMap.put(var.getName(), var.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// Add variables from build info
|
||||
Map<String, String> builderEnv = builder.getExpandedEnvironment();
|
||||
if (builderEnv != null)
|
||||
envMap.putAll(builderEnv);
|
||||
|
||||
return envMap;
|
||||
}
|
||||
|
||||
protected static String[] getEnvStrings(Map<String, String> env) {
|
||||
// Convert into env strings
|
||||
List<String> strings= new ArrayList<String>(env.size());
|
||||
for (Entry<String, String> entry : env.entrySet()) {
|
||||
StringBuffer buffer= new StringBuffer(entry.getKey());
|
||||
buffer.append('=').append(entry.getValue());
|
||||
strings.add(buffer.toString());
|
||||
}
|
||||
|
||||
return strings.toArray(new String[strings.size()]);
|
||||
}
|
||||
|
||||
private ConsoleOutputSniffer createBuildOutputSniffer(OutputStream outputStream,
|
||||
OutputStream errorStream,
|
||||
IProject project,
|
||||
IConfiguration cfg,
|
||||
IPath workingDirectory,
|
||||
IMarkerGenerator markerGenerator,
|
||||
IScannerInfoCollector collector){
|
||||
ICfgScannerConfigBuilderInfo2Set container = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg);
|
||||
Map<CfgInfoContext, IScannerConfigBuilderInfo2> map = container.getInfoMap();
|
||||
List<IScannerInfoConsoleParser> clParserList = new ArrayList<IScannerInfoConsoleParser>();
|
||||
|
||||
if(container.isPerRcTypeDiscovery()){
|
||||
for (IResourceInfo rcInfo : cfg.getResourceInfos()) {
|
||||
ITool tools[];
|
||||
if(rcInfo instanceof IFileInfo){
|
||||
tools = ((IFileInfo)rcInfo).getToolsToInvoke();
|
||||
} else {
|
||||
tools = ((IFolderInfo)rcInfo).getFilteredTools();
|
||||
}
|
||||
for (ITool tool : tools) {
|
||||
IInputType[] types = tool.getInputTypes();
|
||||
|
||||
if(types.length != 0){
|
||||
for (IInputType type : types) {
|
||||
CfgInfoContext c = new CfgInfoContext(rcInfo, tool, type);
|
||||
contributeToConsoleParserList(project, map, c, workingDirectory, markerGenerator, collector, clParserList);
|
||||
}
|
||||
} else {
|
||||
CfgInfoContext c = new CfgInfoContext(rcInfo, tool, null);
|
||||
contributeToConsoleParserList(project, map, c, workingDirectory, markerGenerator, collector, clParserList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(clParserList.size() == 0){
|
||||
contributeToConsoleParserList(project, map, new CfgInfoContext(cfg), workingDirectory, markerGenerator, collector, clParserList);
|
||||
}
|
||||
|
||||
if(clParserList.size() != 0){
|
||||
return new ConsoleOutputSniffer(outputStream, errorStream,
|
||||
clParserList.toArray(new IScannerInfoConsoleParser[clParserList.size()]));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean contributeToConsoleParserList(
|
||||
IProject project,
|
||||
Map<CfgInfoContext, IScannerConfigBuilderInfo2> map,
|
||||
CfgInfoContext context,
|
||||
IPath workingDirectory,
|
||||
IMarkerGenerator markerGenerator,
|
||||
IScannerInfoCollector collector,
|
||||
List<IScannerInfoConsoleParser> parserList){
|
||||
IScannerConfigBuilderInfo2 info = map.get(context);
|
||||
InfoContext ic = context.toInfoContext();
|
||||
boolean added = false;
|
||||
if (info != null &&
|
||||
info.isAutoDiscoveryEnabled() &&
|
||||
info.isBuildOutputParserEnabled()) {
|
||||
|
||||
String id = info.getSelectedProfileId();
|
||||
ScannerConfigProfile profile = ScannerConfigProfileManager.getInstance().getSCProfileConfiguration(id);
|
||||
if(profile.getBuildOutputProviderElement() != null){
|
||||
// get the make builder console parser
|
||||
SCProfileInstance profileInstance = ScannerConfigProfileManager.getInstance().
|
||||
getSCProfileInstance(project, ic, id);
|
||||
|
||||
IScannerInfoConsoleParser clParser = profileInstance.createBuildOutputParser();
|
||||
if (collector == null) {
|
||||
collector = profileInstance.getScannerInfoCollector();
|
||||
}
|
||||
if(clParser != null){
|
||||
clParser.startup(project, workingDirectory, collector,
|
||||
info.isProblemReportingEnabled() ? markerGenerator : null);
|
||||
parserList.add(clParser);
|
||||
added = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Wind River 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
|
||||
*
|
||||
* Contributors:
|
||||
* Wind River Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.core;
|
||||
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* Interface implemented by toolchain integrators to perform the actual build.
|
||||
*
|
||||
* @author Doug Schaefer
|
||||
* @since 8.0
|
||||
*/
|
||||
public interface IBuildRunner {
|
||||
|
||||
/**
|
||||
* Perform the build.
|
||||
*
|
||||
* @param kind kind from the IncrementalProjectBuilder
|
||||
* @param project project being built
|
||||
* @param configuration configuration being built
|
||||
* @param console console to use for build output
|
||||
* @param markerGenerator generator to add markers for build problems
|
||||
* @param monitor progress monitor
|
||||
* @throws CoreException standard core exception of something goes wrong
|
||||
*/
|
||||
public boolean invokeBuild(int kind, IProject project, IConfiguration configuration,
|
||||
IBuilder builder, IConsole console, IMarkerGenerator markerGenerator,
|
||||
IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor) throws CoreException;
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.managedbuilder.macros.IFileContextBuildMacroValues;
|
|||
import org.eclipse.cdt.managedbuilder.macros.IReservedMacroNameSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
|
||||
import org.eclipse.cdt.newmake.core.IMakeBuilderInfo;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
|
||||
/**
|
||||
|
@ -95,6 +96,11 @@ public interface IBuilder extends IBuildObject, IMakeBuilderInfo {
|
|||
* @since 6.0
|
||||
*/
|
||||
static final String ATTRIBUTE_COMMAND_LAUNCHER = "commandLauncher"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* @since 8.0
|
||||
*/
|
||||
static final String ATTRIBUTE_BUILD_RUNNER = "buildRunner"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Returns the command line arguments to pass to the build/make utility used
|
||||
|
@ -319,4 +325,13 @@ public interface IBuilder extends IBuildObject, IMakeBuilderInfo {
|
|||
* @since 6.0
|
||||
*/
|
||||
public ICommandLauncher getCommandLauncher();
|
||||
|
||||
/**
|
||||
* Returns the build runner for this builder.
|
||||
*
|
||||
* @return build runner
|
||||
* @since 8.0
|
||||
*/
|
||||
public IBuildRunner getBuildRunner() throws CoreException;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,242 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Wind River 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
|
||||
*
|
||||
* Contributors:
|
||||
* Wind River Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
|
||||
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildStateManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.DescriptionBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.IBuildModelBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.IConfigurationBuildState;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.IProjectBuildState;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.ParallelBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* The build runner for the internal builder.
|
||||
*
|
||||
* @author dschaefer
|
||||
* @since 8.0
|
||||
*/
|
||||
public class InternalBuildRunner implements IBuildRunner {
|
||||
|
||||
private static final String INTERNAL_BUILDER = "ManagedMakeBuilder.message.internal.builder"; //$NON-NLS-1$
|
||||
private static final String TYPE_INC = "ManagedMakeBuider.type.incremental"; //$NON-NLS-1$
|
||||
private static final String TYPE_REBUILD = "ManagedMakeBuider.type.rebuild"; //$NON-NLS-1$
|
||||
private static final String CONSOLE_HEADER = "ManagedMakeBuilder.message.console.header"; //$NON-NLS-1$
|
||||
private static final String INTERNAL_BUILDER_HEADER_NOTE = "ManagedMakeBuilder.message.internal.builder.header.note"; //$NON-NLS-1$
|
||||
private static final String WARNING_UNSUPPORTED_CONFIGURATION = "ManagedMakeBuilder.warning.unsupported.configuration"; //$NON-NLS-1$
|
||||
private static final String BUILD_FINISHED = "ManagedMakeBuilder.message.finished"; //$NON-NLS-1$
|
||||
private static final String BUILD_CANCELLED = "ManagedMakeBuilder.message.cancelled"; //$NON-NLS-1$
|
||||
private static final String BUILD_FINISHED_WITH_ERRS = "ManagedMakeBuilder.message.finished.with.errs"; //$NON-NLS-1$
|
||||
private static final String BUILD_STOPPED_ERR = "ManagedMakeBuilder.message.stopped.error"; //$NON-NLS-1$
|
||||
private static final String BUILD_FAILED_ERR = "ManagedMakeBuilder.message.internal.builder.error"; //$NON-NLS-1$
|
||||
private static final String MARKERS = "ManagedMakeBuilder.message.creating.markers"; //$NON-NLS-1$
|
||||
private static final String NOTHING_BUILT = "ManagedMakeBuilder.message.no.build"; //$NON-NLS-1$
|
||||
private static final String BUILD_ERROR = "ManagedMakeBuilder.message.error"; //$NON-NLS-1$
|
||||
|
||||
public boolean invokeBuild(int kind, IProject project, IConfiguration configuration,
|
||||
IBuilder builder, IConsole console, IMarkerGenerator markerGenerator,
|
||||
IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor) throws CoreException {
|
||||
boolean isParallel = builder.isParallelBuildOn() && builder.getParallelizationNum() > 1;
|
||||
// boolean buildIncrementaly = true;
|
||||
boolean resumeOnErr = !builder.isStopOnError();
|
||||
|
||||
// Get the project and make sure there's a monitor to cancel the build
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
|
||||
String[] msgs = new String[2];
|
||||
msgs[0] = ManagedMakeMessages.getResourceString(INTERNAL_BUILDER);
|
||||
msgs[1] = project.getName();
|
||||
|
||||
ConsoleOutputStream consoleOutStream = null;
|
||||
OutputStream epmOutputStream = null;
|
||||
try {
|
||||
int flags = 0;
|
||||
IResourceDelta delta = projectBuilder.getDelta(project);
|
||||
BuildStateManager bsMngr = BuildStateManager.getInstance();
|
||||
IProjectBuildState pBS = bsMngr.getProjectBuildState(project);
|
||||
IConfigurationBuildState cBS = pBS.getConfigurationBuildState(configuration.getId(), true);
|
||||
|
||||
// if(delta != null){
|
||||
flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED | BuildDescriptionManager.DEPS;
|
||||
// delta = getDelta(currentProject);
|
||||
// }
|
||||
|
||||
boolean buildIncrementaly = delta != null;
|
||||
|
||||
// Get a build console for the project
|
||||
StringBuffer buf = new StringBuffer();
|
||||
consoleOutStream = console.getOutputStream();
|
||||
String[] consoleHeader = new String[3];
|
||||
if(buildIncrementaly)
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_INC);
|
||||
else
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_REBUILD);
|
||||
|
||||
consoleHeader[1] = configuration.getName();
|
||||
consoleHeader[2] = project.getName();
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(ManagedMakeMessages.getFormattedString(CONSOLE_HEADER, consoleHeader));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
buf.append(ManagedMakeMessages.getResourceString(INTERNAL_BUILDER_HEADER_NOTE));
|
||||
buf.append("\n"); //$NON-NLS-1$
|
||||
|
||||
if(!configuration.isSupported()){
|
||||
buf.append(ManagedMakeMessages.getFormattedString(WARNING_UNSUPPORTED_CONFIGURATION,
|
||||
new String[] { configuration.getName(), configuration.getToolChain().getName()}));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
|
||||
IBuildDescription des = BuildDescriptionManager.createBuildDescription(configuration, cBS, delta, flags);
|
||||
|
||||
DescriptionBuilder dBuilder = null;
|
||||
if (!isParallel)
|
||||
dBuilder = new DescriptionBuilder(des, buildIncrementaly, resumeOnErr, cBS);
|
||||
|
||||
if(isParallel || dBuilder.getNumCommands() > 0) {
|
||||
// Remove all markers for this project
|
||||
IWorkspace workspace = project.getWorkspace();
|
||||
IMarker[] markers = project.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
|
||||
if (markers != null)
|
||||
workspace.deleteMarkers(markers);
|
||||
|
||||
// Hook up an error parser manager
|
||||
String[] errorParsers = builder.getErrorParsers();
|
||||
ErrorParserManager epm = new ErrorParserManager(project, des.getDefaultBuildDirLocationURI(), markerGenerator, errorParsers);
|
||||
epm.setOutputStream(consoleOutStream);
|
||||
// This variable is necessary to ensure that the EPM stream stay open
|
||||
// until we explicitly close it. See bug#123302.
|
||||
epmOutputStream = epm.getOutputStream();
|
||||
|
||||
int status = 0;
|
||||
|
||||
long t1 = System.currentTimeMillis();
|
||||
if (isParallel)
|
||||
status = ParallelBuilder.build(des, null, null, epmOutputStream, epmOutputStream, monitor, resumeOnErr, buildIncrementaly);
|
||||
else
|
||||
status = dBuilder.build(epmOutputStream, epmOutputStream, monitor);
|
||||
long t2 = System.currentTimeMillis();
|
||||
|
||||
// Report either the success or failure of our mission
|
||||
buf = new StringBuffer();
|
||||
|
||||
switch(status){
|
||||
case IBuildModelBuilder.STATUS_OK:
|
||||
buf.append(ManagedMakeMessages
|
||||
.getFormattedString(BUILD_FINISHED,
|
||||
project.getName()));
|
||||
break;
|
||||
case IBuildModelBuilder.STATUS_CANCELLED:
|
||||
buf.append(ManagedMakeMessages
|
||||
.getResourceString(BUILD_CANCELLED));
|
||||
break;
|
||||
case IBuildModelBuilder.STATUS_ERROR_BUILD:
|
||||
String msg = resumeOnErr ?
|
||||
ManagedMakeMessages.getResourceString(BUILD_FINISHED_WITH_ERRS) :
|
||||
ManagedMakeMessages.getResourceString(BUILD_STOPPED_ERR);
|
||||
buf.append(msg);
|
||||
break;
|
||||
case IBuildModelBuilder.STATUS_ERROR_LAUNCH:
|
||||
default:
|
||||
buf.append(ManagedMakeMessages
|
||||
.getResourceString(BUILD_FAILED_ERR));
|
||||
break;
|
||||
}
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
// Report time and number of threads used
|
||||
buf.append(ManagedMakeMessages.getFormattedString("CommonBuilder.6", Integer.toString((int)(t2 - t1)))); //$NON-NLS-1$
|
||||
// buf.append(t2 - t1);
|
||||
// buf.append(" ms. ");
|
||||
if (isParallel) {
|
||||
buf.append(ManagedMakeMessages.getFormattedString("CommonBuilder.7", Integer.toString(ParallelBuilder.lastThreadsUsed))); //$NON-NLS-1$
|
||||
// buf.append(ParallelBuilder.lastThreadsUsed);
|
||||
}
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// Write message on the console
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
epmOutputStream.close();
|
||||
epmOutputStream = null;
|
||||
// Generate any error markers that the build has discovered
|
||||
monitor.subTask(ManagedMakeMessages
|
||||
.getResourceString(MARKERS));
|
||||
|
||||
bsMngr.setProjectBuildState(project, pBS);
|
||||
} else {
|
||||
buf = new StringBuffer();
|
||||
buf.append(ManagedMakeMessages.getFormattedString(NOTHING_BUILT, project.getName()));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if(consoleOutStream != null){
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String errorDesc = ManagedMakeMessages
|
||||
.getResourceString(BUILD_ERROR);
|
||||
buf.append(errorDesc);
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
buf.append(e.getLocalizedMessage());
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
try {
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
} catch (IOException e1) {
|
||||
}
|
||||
}
|
||||
projectBuilder.forgetLastBuiltState();
|
||||
} finally {
|
||||
if(epmOutputStream != null){
|
||||
try {
|
||||
epmOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
if(consoleOutStream != null){
|
||||
try {
|
||||
consoleOutStream.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
monitor.done();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -37,13 +37,16 @@ import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
|||
import org.eclipse.cdt.core.settings.model.extension.CBuildData;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||
import org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner;
|
||||
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
|
||||
import org.eclipse.cdt.managedbuilder.core.IBuildRunner;
|
||||
import org.eclipse.cdt.managedbuilder.core.IBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.core.IProjectType;
|
||||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.InternalBuildRunner;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||
import org.eclipse.cdt.managedbuilder.internal.dataprovider.BuildBuildData;
|
||||
|
@ -137,6 +140,9 @@ public class Builder extends BuildObject implements IBuilder, IMatchKeyProvider,
|
|||
private ICommandLauncher fCommandLauncher = null;
|
||||
private IConfigurationElement fCommandLauncherElement = null;
|
||||
|
||||
private IBuildRunner fBuildRunner = null;
|
||||
private IConfigurationElement fBuildRunnerElement = null;
|
||||
|
||||
/*
|
||||
* C O N S T R U C T O R S
|
||||
*/
|
||||
|
@ -326,6 +332,9 @@ public class Builder extends BuildObject implements IBuilder, IMatchKeyProvider,
|
|||
|
||||
fCommandLauncher = builder.fCommandLauncher;
|
||||
fCommandLauncherElement = builder.fCommandLauncherElement;
|
||||
|
||||
fBuildRunner = builder.fBuildRunner;
|
||||
fBuildRunnerElement = builder.fBuildRunnerElement;
|
||||
}
|
||||
|
||||
public void copySettings(Builder builder, boolean allBuildSettings){
|
||||
|
@ -577,6 +586,9 @@ public class Builder extends BuildObject implements IBuilder, IMatchKeyProvider,
|
|||
fCommandLauncherElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
|
||||
}
|
||||
|
||||
String buildRunner = element.getAttribute(ATTRIBUTE_BUILD_RUNNER);
|
||||
if (buildRunner != null && element instanceof DefaultManagedConfigElement)
|
||||
fBuildRunnerElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -2745,4 +2757,26 @@ public class Builder extends BuildObject implements IBuilder, IMatchKeyProvider,
|
|||
return fCommandLauncher;
|
||||
}
|
||||
|
||||
public IBuildRunner getBuildRunner() throws CoreException {
|
||||
// Already defined
|
||||
if (fBuildRunner != null)
|
||||
return fBuildRunner;
|
||||
|
||||
// Instantiate from model
|
||||
if (fBuildRunnerElement != null) {
|
||||
fBuildRunner = (IBuildRunner)fBuildRunnerElement.createExecutableExtension(ATTRIBUTE_BUILD_RUNNER);
|
||||
return fBuildRunner;
|
||||
}
|
||||
|
||||
// Check with superClass
|
||||
if (superClass != null)
|
||||
return superClass.getBuildRunner();
|
||||
|
||||
// Default internal or external builder
|
||||
if (isInternalBuilder())
|
||||
return new InternalBuildRunner();
|
||||
|
||||
return new ExternalBuildRunner();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,73 +15,42 @@
|
|||
package org.eclipse.cdt.managedbuilder.internal.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext;
|
||||
import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set;
|
||||
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.ICommandLauncher;
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
||||
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.model.ICModelMarker;
|
||||
import org.eclipse.cdt.core.resources.ACBuilder;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.util.ListComparator;
|
||||
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCProfileInstance;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
|
||||
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
|
||||
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep;
|
||||
import org.eclipse.cdt.managedbuilder.core.IBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IInputType;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildDescription;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildStateManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.DescriptionBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.IBuildModelBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.IConfigurationBuildState;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.IProjectBuildState;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.ParallelBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.StepBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
|
||||
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
|
||||
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator2;
|
||||
import org.eclipse.cdt.newmake.core.IMakeBuilderInfo;
|
||||
import org.eclipse.cdt.newmake.internal.core.StreamMonitor;
|
||||
import org.eclipse.cdt.utils.CommandLineUtil;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
|
@ -99,7 +68,6 @@ import org.eclipse.core.runtime.MultiStatus;
|
|||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
|
@ -108,25 +76,14 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
public class CommonBuilder extends ACBuilder {
|
||||
|
||||
public final static String BUILDER_ID = ManagedBuilderCorePlugin.getUniqueIdentifier() + ".genmakebuilder"; //$NON-NLS-1$
|
||||
private static final String BUILD_ERROR = "ManagedMakeBuilder.message.error"; //$NON-NLS-1$
|
||||
private static final String BUILD_FINISHED = "ManagedMakeBuilder.message.finished"; //$NON-NLS-1$
|
||||
private static final String CONSOLE_HEADER = "ManagedMakeBuilder.message.console.header"; //$NON-NLS-1$
|
||||
private static final String ERROR_HEADER = "GeneratedmakefileBuilder error ["; //$NON-NLS-1$
|
||||
private static final String MARKERS = "ManagedMakeBuilder.message.creating.markers"; //$NON-NLS-1$
|
||||
private static final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
private static final String NOTHING_BUILT = "ManagedMakeBuilder.message.no.build"; //$NON-NLS-1$
|
||||
private static final String TRACE_FOOTER = "]: "; //$NON-NLS-1$
|
||||
private static final String TRACE_HEADER = "GeneratedmakefileBuilder trace ["; //$NON-NLS-1$
|
||||
private static final String TYPE_CLEAN = "ManagedMakeBuilder.type.clean"; //$NON-NLS-1$
|
||||
private static final String TYPE_INC = "ManagedMakeBuider.type.incremental"; //$NON-NLS-1$
|
||||
private static final String WARNING_UNSUPPORTED_CONFIGURATION = "ManagedMakeBuilder.warning.unsupported.configuration"; //$NON-NLS-1$
|
||||
private static final String BUILD_CANCELLED = "ManagedMakeBuilder.message.cancelled"; //$NON-NLS-1$
|
||||
private static final String BUILD_FINISHED_WITH_ERRS = "ManagedMakeBuilder.message.finished.with.errs"; //$NON-NLS-1$
|
||||
private static final String BUILD_FAILED_ERR = "ManagedMakeBuilder.message.internal.builder.error"; //$NON-NLS-1$
|
||||
private static final String BUILD_STOPPED_ERR = "ManagedMakeBuilder.message.stopped.error"; //$NON-NLS-1$
|
||||
private static final String INTERNAL_BUILDER_HEADER_NOTE = "ManagedMakeBuilder.message.internal.builder.header.note"; //$NON-NLS-1$
|
||||
private static final String TYPE_REBUILD = "ManagedMakeBuider.type.rebuild"; //$NON-NLS-1$
|
||||
private static final String INTERNAL_BUILDER = "ManagedMakeBuilder.message.internal.builder"; //$NON-NLS-1$
|
||||
public static boolean VERBOSE = false;
|
||||
|
||||
private static CfgBuildSet fBuildSet = new CfgBuildSet();
|
||||
|
@ -781,7 +738,15 @@ public class CommonBuilder extends ACBuilder {
|
|||
|
||||
if(status.isBuild()){
|
||||
try {
|
||||
boolean isClean = invokeBuilder(kind, bInfo, monitor);
|
||||
boolean isClean = builder.getBuildRunner().invokeBuild(
|
||||
kind,
|
||||
bInfo.getProject(),
|
||||
bInfo.getConfiguration(),
|
||||
builder,
|
||||
bInfo.getConsole(),
|
||||
this,
|
||||
this,
|
||||
monitor);
|
||||
if (isClean) {
|
||||
forgetLastBuiltState();
|
||||
cfg.setRebuildState(true);
|
||||
|
@ -868,424 +833,6 @@ public class CommonBuilder extends ACBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
// private IConsole getConsole(IProject project, boolean bg){
|
||||
// IConsole console = CCorePlugin.getDefault().getConsole();
|
||||
// console.start(project);
|
||||
// return console;
|
||||
// }
|
||||
/**
|
||||
* called to invoke the MBS Internal Builder for building the given configuration
|
||||
*
|
||||
* @param monitor monitor
|
||||
*/
|
||||
protected boolean invokeInternalBuilder(int kind, CfgBuildInfo bInfo,
|
||||
IProgressMonitor monitor) {
|
||||
|
||||
IBuilder builder = bInfo.getBuilder();
|
||||
IConfiguration cfg = bInfo.getConfiguration();
|
||||
boolean isParallel = builder.isParallelBuildOn() && builder.getParallelizationNum() > 1;
|
||||
// boolean buildIncrementaly = true;
|
||||
boolean resumeOnErr = !builder.isStopOnError();
|
||||
|
||||
// Get the project and make sure there's a monitor to cancel the build
|
||||
IProject currentProject = bInfo.getProject();
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
|
||||
String[] msgs = new String[2];
|
||||
msgs[0] = ManagedMakeMessages.getResourceString(INTERNAL_BUILDER);
|
||||
msgs[1] = currentProject.getName();
|
||||
|
||||
ConsoleOutputStream consoleOutStream = null;
|
||||
IConsole console = null;
|
||||
OutputStream epmOutputStream = null;
|
||||
try {
|
||||
int flags = 0;
|
||||
IResourceDelta delta = getDelta(currentProject);
|
||||
BuildStateManager bsMngr = BuildStateManager.getInstance();
|
||||
IProjectBuildState pBS = bsMngr.getProjectBuildState(currentProject);
|
||||
IConfigurationBuildState cBS = pBS.getConfigurationBuildState(cfg.getId(), true);
|
||||
|
||||
// if(delta != null){
|
||||
flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED | BuildDescriptionManager.DEPS;
|
||||
// delta = getDelta(currentProject);
|
||||
// }
|
||||
|
||||
boolean buildIncrementaly = delta != null;
|
||||
|
||||
// Get a build console for the project
|
||||
StringBuffer buf = new StringBuffer();
|
||||
// console = CCorePlugin.getDefault().getConsole();
|
||||
// console.start(currentProject);
|
||||
console = bInfo.getConsole();
|
||||
consoleOutStream = console.getOutputStream();
|
||||
String[] consoleHeader = new String[3];
|
||||
if(buildIncrementaly)
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_INC);
|
||||
else
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_REBUILD);
|
||||
|
||||
consoleHeader[1] = cfg.getName();
|
||||
consoleHeader[2] = currentProject.getName();
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(ManagedMakeMessages.getFormattedString(CONSOLE_HEADER, consoleHeader));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
buf.append(ManagedMakeMessages.getResourceString(INTERNAL_BUILDER_HEADER_NOTE));
|
||||
buf.append("\n"); //$NON-NLS-1$
|
||||
|
||||
if(!cfg.isSupported()){
|
||||
buf.append(ManagedMakeMessages.getFormattedString(WARNING_UNSUPPORTED_CONFIGURATION,new String[] {cfg.getName(),cfg.getToolChain().getName()}));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
|
||||
IBuildDescription des = BuildDescriptionManager.createBuildDescription(cfg, cBS, delta, flags);
|
||||
|
||||
DescriptionBuilder dBuilder = null;
|
||||
if (!isParallel)
|
||||
dBuilder = new DescriptionBuilder(des, buildIncrementaly, resumeOnErr, cBS);
|
||||
|
||||
if(isParallel || dBuilder.getNumCommands() > 0) {
|
||||
// Remove all markers for this project
|
||||
removeAllMarkers(currentProject);
|
||||
|
||||
// Hook up an error parser manager
|
||||
String[] errorParsers = builder.getErrorParsers();
|
||||
ErrorParserManager epm = new ErrorParserManager(currentProject, des.getDefaultBuildDirLocationURI(), this, errorParsers);
|
||||
epm.setOutputStream(consoleOutStream);
|
||||
// This variable is necessary to ensure that the EPM stream stay open
|
||||
// until we explicitly close it. See bug#123302.
|
||||
epmOutputStream = epm.getOutputStream();
|
||||
|
||||
int status = 0;
|
||||
|
||||
long t1 = System.currentTimeMillis();
|
||||
if (isParallel)
|
||||
status = ParallelBuilder.build(des, null, null, epmOutputStream, epmOutputStream, monitor, resumeOnErr, buildIncrementaly);
|
||||
else
|
||||
status = dBuilder.build(epmOutputStream, epmOutputStream, monitor);
|
||||
long t2 = System.currentTimeMillis();
|
||||
|
||||
// Report either the success or failure of our mission
|
||||
buf = new StringBuffer();
|
||||
|
||||
switch(status){
|
||||
case IBuildModelBuilder.STATUS_OK:
|
||||
buf.append(ManagedMakeMessages
|
||||
.getFormattedString(BUILD_FINISHED,
|
||||
currentProject.getName()));
|
||||
break;
|
||||
case IBuildModelBuilder.STATUS_CANCELLED:
|
||||
buf.append(ManagedMakeMessages
|
||||
.getResourceString(BUILD_CANCELLED));
|
||||
break;
|
||||
case IBuildModelBuilder.STATUS_ERROR_BUILD:
|
||||
String msg = resumeOnErr ?
|
||||
ManagedMakeMessages.getResourceString(BUILD_FINISHED_WITH_ERRS) :
|
||||
ManagedMakeMessages.getResourceString(BUILD_STOPPED_ERR);
|
||||
buf.append(msg);
|
||||
break;
|
||||
case IBuildModelBuilder.STATUS_ERROR_LAUNCH:
|
||||
default:
|
||||
buf.append(ManagedMakeMessages
|
||||
.getResourceString(BUILD_FAILED_ERR));
|
||||
break;
|
||||
}
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
// Report time and number of threads used
|
||||
buf.append(ManagedMakeMessages.getFormattedString("CommonBuilder.6", Integer.toString((int)(t2 - t1)))); //$NON-NLS-1$
|
||||
// buf.append(t2 - t1);
|
||||
// buf.append(" ms. ");
|
||||
if (isParallel) {
|
||||
buf.append(ManagedMakeMessages.getFormattedString("CommonBuilder.7", Integer.toString(ParallelBuilder.lastThreadsUsed))); //$NON-NLS-1$
|
||||
// buf.append(ParallelBuilder.lastThreadsUsed);
|
||||
}
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// Write message on the console
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
epmOutputStream.close();
|
||||
epmOutputStream = null;
|
||||
// Generate any error markers that the build has discovered
|
||||
monitor.subTask(ManagedMakeMessages
|
||||
.getResourceString(MARKERS));
|
||||
|
||||
bsMngr.setProjectBuildState(currentProject, pBS);
|
||||
} else {
|
||||
buf = new StringBuffer();
|
||||
buf.append(ManagedMakeMessages.getFormattedString(NOTHING_BUILT, currentProject.getName()));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if(consoleOutStream != null){
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String errorDesc = ManagedMakeMessages
|
||||
.getResourceString(BUILD_ERROR);
|
||||
buf.append(errorDesc);
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
buf.append(e.getLocalizedMessage());
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
try {
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
} catch (IOException e1) {
|
||||
}
|
||||
}
|
||||
forgetLastBuiltState();
|
||||
} finally {
|
||||
if(epmOutputStream != null){
|
||||
try {
|
||||
epmOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
if(consoleOutStream != null){
|
||||
try {
|
||||
consoleOutStream.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
monitor.done();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String[] calcEnvironment(IBuilder builder) throws CoreException{
|
||||
HashMap<String, String> envMap = new HashMap<String, String>();
|
||||
if (builder.appendEnvironment()) {
|
||||
ICConfigurationDescription cfgDes = ManagedBuildManager.getDescriptionForConfiguration(builder.getParent().getParent());
|
||||
IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager();
|
||||
IEnvironmentVariable[] vars = mngr.getVariables(cfgDes, true);
|
||||
for (IEnvironmentVariable var : vars) {
|
||||
envMap.put(var.getName(), var.getValue());
|
||||
}
|
||||
}
|
||||
// Add variables from build info
|
||||
Map<String, String> builderEnv = builder.getExpandedEnvironment();
|
||||
if(builderEnv != null)
|
||||
envMap.putAll(builderEnv);
|
||||
List<String> strings= new ArrayList<String>(envMap.size());
|
||||
for (Entry<String, String> entry : envMap.entrySet()) {
|
||||
StringBuffer buffer= new StringBuffer(entry.getKey());
|
||||
buffer.append('=').append(entry.getValue());
|
||||
strings.add(buffer.toString());
|
||||
}
|
||||
return strings.toArray(new String[strings.size()]);
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Called to invoke the MBS Internal Builder for building the given resources in
|
||||
// * the given configuration
|
||||
// *
|
||||
// * This method is considered experimental. Clients implementing this API should expect
|
||||
// * possible changes in the API.
|
||||
// *
|
||||
// * @param cfg configuration to be built
|
||||
// * @param buildIncrementaly if true, incremental build will be performed,
|
||||
// * only files that need rebuild will be built.
|
||||
// * If false, full rebuild will be performed
|
||||
// * @param resumeOnErr if true, build will continue in case of error while building.
|
||||
// * If false the build will stop on the first error
|
||||
// * @param monitor Progress monitor. For every resource built this monitor will consume one unit of work.
|
||||
// */
|
||||
// private void invokeInternalBuilder(IResource[] resourcesToBuild, CfgBuildInfo bInfo,
|
||||
// boolean buildIncrementaly,
|
||||
// boolean resumeOnErr,
|
||||
// boolean initNewConsole,
|
||||
// boolean printFinishedMessage,
|
||||
// IProgressMonitor monitor) {
|
||||
// // Get the project and make sure there's a monitor to cancel the build
|
||||
//
|
||||
// IProject currentProject = bInfo.getProject();
|
||||
// IConfiguration cfg = bInfo.getConfiguration();
|
||||
//
|
||||
// if (monitor == null) {
|
||||
// monitor = new NullProgressMonitor();
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// int flags = 0;
|
||||
// IResourceDelta delta = null;
|
||||
//
|
||||
// if(buildIncrementaly){
|
||||
// flags = BuildDescriptionManager.REBUILD | BuildDescriptionManager.REMOVED | BuildDescriptionManager.DEPS;
|
||||
// delta = getDelta(currentProject);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// String[] msgs = new String[2];
|
||||
// msgs[0] = ManagedMakeMessages.getResourceString(INTERNAL_BUILDER);
|
||||
// msgs[1] = currentProject.getName();
|
||||
//
|
||||
//// IConsole console = CCorePlugin.getDefault().getConsole();
|
||||
//// console.start(currentProject);
|
||||
// IConsole console = bInfo.getConsole();
|
||||
// ConsoleOutputStream consoleOutStream = console.getOutputStream();
|
||||
//
|
||||
// StringBuffer buf = new StringBuffer();
|
||||
//
|
||||
// if (initNewConsole) {
|
||||
// if (buildIncrementaly)
|
||||
// buf.append(ManagedMakeMessages.getResourceString("GeneratedMakefileBuilder.buildSelectedIncremental")); //$NON-NLS-1$
|
||||
// else
|
||||
// buf.append(ManagedMakeMessages.getResourceString("GeneratedMakefileBuilder.buildSelectedRebuild")); //$NON-NLS-1$
|
||||
//
|
||||
//
|
||||
// buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
//
|
||||
// buf.append(ManagedMakeMessages
|
||||
// .getResourceString(INTERNAL_BUILDER_HEADER_NOTE));
|
||||
// buf.append("\n"); //$NON-NLS-1$
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if(!cfg.isSupported()){
|
||||
// buf.append(ManagedMakeMessages.getFormattedString(WARNING_UNSUPPORTED_CONFIGURATION,new String[] {cfg.getName(),cfg.getToolChain().getName()}));
|
||||
// buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// }
|
||||
// consoleOutStream.write(buf.toString().getBytes());
|
||||
// consoleOutStream.flush();
|
||||
//
|
||||
// // Remove all markers for this project
|
||||
// // TODO remove only necessary markers
|
||||
// removeAllMarkers(currentProject);
|
||||
//
|
||||
// IBuildDescription des = BuildDescriptionManager.createBuildDescription(cfg, delta, flags);
|
||||
//
|
||||
// // Hook up an error parser manager
|
||||
// String[] errorParsers = cfg.getErrorParserList();
|
||||
// ErrorParserManager epm = new ErrorParserManager(currentProject, des.getDefaultBuildDirLocationURI(), this, errorParsers);
|
||||
// epm.setOutputStream(consoleOutStream);
|
||||
// // This variable is necessary to ensure that the EPM stream stay open
|
||||
// // until we explicitly close it. See bug#123302.
|
||||
// OutputStream epmOutputStream = epm.getOutputStream();
|
||||
//
|
||||
// boolean errorsFound = false;
|
||||
//
|
||||
// doneBuild: for (int k = 0; k < resourcesToBuild.length; k++) {
|
||||
// IBuildResource buildResource = des
|
||||
// .getBuildResource(resourcesToBuild[k]);
|
||||
//
|
||||
//// step collector
|
||||
// Set<IBuildStep> dependentSteps = new HashSet<IBuildStep>();
|
||||
//
|
||||
//// get dependent IO types
|
||||
// IBuildIOType depTypes[] = buildResource.getDependentIOTypes();
|
||||
//
|
||||
//// iterate through each type and add the step the type belongs to to the collector
|
||||
// for (IBuildIOType type : depTypes) {
|
||||
// if(type != null && type.getStep() != null)
|
||||
// dependentSteps.add(type.getStep());
|
||||
// }
|
||||
//
|
||||
// monitor.subTask(ManagedMakeMessages.getResourceString("GeneratedMakefileBuilder.buildingFile") + resourcesToBuild[k].getProjectRelativePath()); //$NON-NLS-1$
|
||||
//
|
||||
// // iterate through all build steps
|
||||
// Iterator stepIter = dependentSteps.iterator();
|
||||
//
|
||||
// while(stepIter.hasNext())
|
||||
// {
|
||||
// IBuildStep step = (IBuildStep) stepIter.next();
|
||||
//
|
||||
// StepBuilder stepBuilder = new StepBuilder(step, null);
|
||||
//
|
||||
// int status = stepBuilder.build(consoleOutStream, epmOutputStream, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
|
||||
//
|
||||
// // Refresh the output resource without allowing the user to cancel.
|
||||
// // This is probably unkind, but short of this there is no way to ensure
|
||||
// // the UI is up-to-date with the build results
|
||||
//
|
||||
// for (IBuildIOType type : step.getOutputIOTypes()) {
|
||||
// for (IBuildResource res : type.getResources()) {
|
||||
// IFile file = currentProject.getFile(res.getLocation());
|
||||
// file.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // check status
|
||||
//
|
||||
// switch (status) {
|
||||
// case IBuildModelBuilder.STATUS_OK:
|
||||
// // don't print anything if the step was successful,
|
||||
// // since the build might not be done as a whole
|
||||
// break;
|
||||
// case IBuildModelBuilder.STATUS_CANCELLED:
|
||||
// buf.append(ManagedMakeMessages
|
||||
// .getResourceString(BUILD_CANCELLED));
|
||||
// break doneBuild;
|
||||
// case IBuildModelBuilder.STATUS_ERROR_BUILD:
|
||||
// errorsFound = true;
|
||||
// if (!resumeOnErr) {
|
||||
// buf.append(ManagedMakeMessages
|
||||
// .getResourceString(BUILD_STOPPED_ERR));
|
||||
// break doneBuild;
|
||||
// }
|
||||
// break;
|
||||
// case IBuildModelBuilder.STATUS_ERROR_LAUNCH:
|
||||
// default:
|
||||
// buf.append(ManagedMakeMessages
|
||||
// .getResourceString(BUILD_FAILED_ERR));
|
||||
// break doneBuild;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // check status
|
||||
// // Report either the success or failure of our mission
|
||||
// buf = new StringBuffer();
|
||||
//
|
||||
//
|
||||
// buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
//
|
||||
// if (printFinishedMessage) {
|
||||
// if (errorsFound) {
|
||||
// buf.append(ManagedMakeMessages
|
||||
// .getResourceString(BUILD_FAILED_ERR));
|
||||
// } else {
|
||||
// buf
|
||||
// .append(ManagedMakeMessages
|
||||
// .getResourceString("GeneratedMakefileBuilder.buildResourcesFinished")); //$NON-NLS-1$
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Write message on the console
|
||||
// consoleOutStream.write(buf.toString().getBytes());
|
||||
// consoleOutStream.flush();
|
||||
// epmOutputStream.close();
|
||||
//
|
||||
// // Generate any error markers that the build has discovered
|
||||
////TODO: addBuilderMarkers(epm);
|
||||
// epm.reportProblems();
|
||||
// consoleOutStream.close();
|
||||
// } catch (Exception e) {
|
||||
// StringBuffer buf = new StringBuffer();
|
||||
// String errorDesc = ManagedMakeMessages
|
||||
// .getResourceString(BUILD_ERROR);
|
||||
// buf.append(errorDesc);
|
||||
// buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
// buf.append("(").append(e.getLocalizedMessage()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
//
|
||||
// forgetLastBuiltState();
|
||||
// } finally {
|
||||
//// getGenerationProblems().clear();
|
||||
// }
|
||||
// }
|
||||
|
||||
protected BuildStatus performPostbuildGeneration(int kind, CfgBuildInfo bInfo, BuildStatus buildStatus, IProgressMonitor monitor) throws CoreException{
|
||||
IBuilder builder = bInfo.getBuilder();
|
||||
if(builder.isInternalBuilder())
|
||||
|
@ -1562,7 +1109,15 @@ public class CommonBuilder extends ACBuilder {
|
|||
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
|
||||
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
invokeMake(CLEAN_BUILD, bInfo, monitor);
|
||||
bInfo.fBuilder.getBuildRunner().invokeBuild(
|
||||
CLEAN_BUILD,
|
||||
bInfo.getProject(),
|
||||
bInfo.getConfiguration(),
|
||||
bInfo.getBuilder(),
|
||||
bInfo.getConsole(),
|
||||
CommonBuilder.this,
|
||||
CommonBuilder.this,
|
||||
monitor);
|
||||
}
|
||||
}, rule, IWorkspace.AVOID_UPDATE, monitor);
|
||||
} catch (CoreException e) {
|
||||
|
@ -1578,7 +1133,15 @@ public class CommonBuilder extends ACBuilder {
|
|||
backgroundJob.setRule(rule);
|
||||
backgroundJob.schedule();
|
||||
} else {
|
||||
invokeMake(CLEAN_BUILD, bInfo, monitor);
|
||||
bInfo.fBuilder.getBuildRunner().invokeBuild(
|
||||
CLEAN_BUILD,
|
||||
bInfo.getProject(),
|
||||
bInfo.getConfiguration(),
|
||||
bInfo.getBuilder(),
|
||||
bInfo.getConsole(),
|
||||
this,
|
||||
this,
|
||||
monitor);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1720,261 +1283,6 @@ public class CommonBuilder extends ACBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean invokeBuilder(int kind, CfgBuildInfo bInfo, IProgressMonitor monitor) throws CoreException {
|
||||
if(bInfo.getBuilder().isInternalBuilder())
|
||||
return invokeInternalBuilder(kind, bInfo, monitor);
|
||||
return invokeMake(kind, bInfo, monitor);
|
||||
}
|
||||
|
||||
private ConsoleOutputSniffer createBuildOutputSniffer(OutputStream outputStream,
|
||||
OutputStream errorStream,
|
||||
IProject project,
|
||||
IConfiguration cfg,
|
||||
IPath workingDirectory,
|
||||
IMarkerGenerator markerGenerator,
|
||||
IScannerInfoCollector collector){
|
||||
ICfgScannerConfigBuilderInfo2Set container = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg);
|
||||
Map<CfgInfoContext, IScannerConfigBuilderInfo2> map = container.getInfoMap();
|
||||
List<IScannerInfoConsoleParser> clParserList = new ArrayList<IScannerInfoConsoleParser>();
|
||||
|
||||
if(container.isPerRcTypeDiscovery()){
|
||||
for (IResourceInfo rcInfo : cfg.getResourceInfos()) {
|
||||
ITool tools[];
|
||||
if(rcInfo instanceof IFileInfo){
|
||||
tools = ((IFileInfo)rcInfo).getToolsToInvoke();
|
||||
} else {
|
||||
tools = ((IFolderInfo)rcInfo).getFilteredTools();
|
||||
}
|
||||
for (ITool tool : tools) {
|
||||
IInputType[] types = tool.getInputTypes();
|
||||
|
||||
if(types.length != 0){
|
||||
for (IInputType type : types) {
|
||||
CfgInfoContext c = new CfgInfoContext(rcInfo, tool, type);
|
||||
contributeToConsoleParserList(project, map, c, workingDirectory, markerGenerator, collector, clParserList);
|
||||
}
|
||||
} else {
|
||||
CfgInfoContext c = new CfgInfoContext(rcInfo, tool, null);
|
||||
contributeToConsoleParserList(project, map, c, workingDirectory, markerGenerator, collector, clParserList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(clParserList.size() == 0){
|
||||
contributeToConsoleParserList(project, map, new CfgInfoContext(cfg), workingDirectory, markerGenerator, collector, clParserList);
|
||||
}
|
||||
|
||||
if(clParserList.size() != 0){
|
||||
return new ConsoleOutputSniffer(outputStream, errorStream,
|
||||
clParserList.toArray(new IScannerInfoConsoleParser[clParserList.size()]));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean contributeToConsoleParserList(
|
||||
IProject project,
|
||||
Map<CfgInfoContext, IScannerConfigBuilderInfo2> map,
|
||||
CfgInfoContext context,
|
||||
IPath workingDirectory,
|
||||
IMarkerGenerator markerGenerator,
|
||||
IScannerInfoCollector collector,
|
||||
List<IScannerInfoConsoleParser> parserList){
|
||||
IScannerConfigBuilderInfo2 info = map.get(context);
|
||||
InfoContext ic = context.toInfoContext();
|
||||
boolean added = false;
|
||||
if (info != null &&
|
||||
info.isAutoDiscoveryEnabled() &&
|
||||
info.isBuildOutputParserEnabled()) {
|
||||
|
||||
String id = info.getSelectedProfileId();
|
||||
ScannerConfigProfile profile = ScannerConfigProfileManager.getInstance().getSCProfileConfiguration(id);
|
||||
if(profile.getBuildOutputProviderElement() != null){
|
||||
// get the make builder console parser
|
||||
SCProfileInstance profileInstance = ScannerConfigProfileManager.getInstance().
|
||||
getSCProfileInstance(project, ic, id);
|
||||
|
||||
IScannerInfoConsoleParser clParser = profileInstance.createBuildOutputParser();
|
||||
if (collector == null) {
|
||||
collector = profileInstance.getScannerInfoCollector();
|
||||
}
|
||||
if(clParser != null){
|
||||
clParser.startup(project, workingDirectory, collector,
|
||||
info.isProblemReportingEnabled() ? markerGenerator : null);
|
||||
parserList.add(clParser);
|
||||
added = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
protected boolean invokeMake(int kind, CfgBuildInfo bInfo, IProgressMonitor monitor) throws CoreException {
|
||||
boolean isClean = false;
|
||||
IProject currProject = bInfo.getProject();
|
||||
IBuilder builder = bInfo.getBuilder();
|
||||
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask(ManagedMakeMessages.getResourceString("MakeBuilder.Invoking_Make_Builder") + currProject.getName(), 100); //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
IPath buildCommand = builder.getBuildCommand();
|
||||
if (buildCommand != null) {
|
||||
// IConsole console = CCorePlugin.getDefault().getConsole();
|
||||
// console.start(currProject);
|
||||
IConsole console = bInfo.getConsole();
|
||||
|
||||
OutputStream cos = console.getOutputStream();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
String[] consoleHeader = new String[3];
|
||||
switch (kind) {
|
||||
case FULL_BUILD:
|
||||
case INCREMENTAL_BUILD:
|
||||
case AUTO_BUILD:
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_INC);
|
||||
break;
|
||||
case CLEAN_BUILD:
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_CLEAN);
|
||||
break;
|
||||
}
|
||||
|
||||
IConfiguration cfg = bInfo.getConfiguration();
|
||||
consoleHeader[1] = cfg.getName();
|
||||
consoleHeader[2] = currProject.getName();
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(ManagedMakeMessages.getFormattedString(CONSOLE_HEADER, consoleHeader));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
if(!cfg.isSupported()){
|
||||
buf.append(ManagedMakeMessages.getFormattedString(WARNING_UNSUPPORTED_CONFIGURATION,new String[] {cfg.getName(),cfg.getToolChain().getName()}));
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
cos.write(buf.toString().getBytes());
|
||||
cos.flush();
|
||||
|
||||
// remove all markers for this project
|
||||
removeAllMarkers(currProject);
|
||||
|
||||
IPath workingDirectory = ManagedBuildManager.getBuildLocation(cfg, builder);
|
||||
URI workingDirectoryURI = ManagedBuildManager.getBuildLocationURI(cfg, builder);
|
||||
|
||||
String[] targets = getTargets(kind, builder);
|
||||
if (targets.length != 0 && targets[targets.length - 1].equals(builder.getCleanBuildTarget()))
|
||||
isClean = true;
|
||||
|
||||
String errMsg = null;
|
||||
ICommandLauncher launcher = builder.getCommandLauncher();
|
||||
launcher.setProject(currProject);
|
||||
// Print the command for visual interaction.
|
||||
launcher.showCommand(true);
|
||||
|
||||
// Set the environment
|
||||
String[] env = calcEnvironment(builder);
|
||||
String[] buildArguments = targets;
|
||||
|
||||
String[] newArgs = argumentsToArray(builder.getBuildArguments());
|
||||
buildArguments = new String[targets.length + newArgs.length];
|
||||
System.arraycopy(newArgs, 0, buildArguments, 0, newArgs.length);
|
||||
System.arraycopy(targets, 0, buildArguments, newArgs.length, targets.length);
|
||||
|
||||
// MakeRecon recon = new MakeRecon(buildCommand, buildArguments, env, workingDirectory, makeMonitor, cos);
|
||||
// recon.invokeMakeRecon();
|
||||
// cos = recon;
|
||||
QualifiedName qName = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "progressMonitor"); //$NON-NLS-1$
|
||||
Integer last = (Integer)currProject.getSessionProperty(qName);
|
||||
if (last == null) {
|
||||
last = new Integer(100);
|
||||
}
|
||||
ErrorParserManager epm = new ErrorParserManager(currProject, workingDirectoryURI, this, builder.getErrorParsers());
|
||||
epm.setOutputStream(cos);
|
||||
StreamMonitor streamMon = new StreamMonitor(new SubProgressMonitor(monitor, 100), epm, last.intValue());
|
||||
OutputStream stdout = streamMon;
|
||||
OutputStream stderr = streamMon;
|
||||
// Sniff console output for scanner info
|
||||
// ICfgScannerConfigBuilderInfo2Set container = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg);
|
||||
// CfgInfoContext context = new CfgInfoContext(cfg);
|
||||
// InfoContext baseContext;
|
||||
// IScannerConfigBuilderInfo2 info = container.getInfo(context);
|
||||
// if(info == null){
|
||||
// baseContext = new InfoContext(currProject);
|
||||
// } else {
|
||||
// baseContext = context.toInfoContext();
|
||||
// }
|
||||
// ConsoleOutputSniffer sniffer = ScannerInfoConsoleParserFactory.getMakeBuilderOutputSniffer(
|
||||
// stdout, stderr, currProject, baseContext, workingDirectory, info, this, null);
|
||||
ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, currProject, cfg, workingDirectory, this, null);
|
||||
OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream());
|
||||
OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream());
|
||||
Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory, monitor);
|
||||
if (p != null) {
|
||||
try {
|
||||
// Close the input of the Process explicitly.
|
||||
// We will never write to it.
|
||||
p.getOutputStream().close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
// Before launching give visual cues via the monitor
|
||||
monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Invoking_Command") + launcher.getCommandLine()); //$NON-NLS-1$
|
||||
if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0))
|
||||
!= ICommandLauncher.OK)
|
||||
errMsg = launcher.getErrorMessage();
|
||||
monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Updating_project")); //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
// Do not allow the cancel of the refresh, since the builder is external
|
||||
// to Eclipse, files may have been created/modified and we will be out-of-sync.
|
||||
// The caveat is for hugue projects, it may take sometimes at every build.
|
||||
currProject.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
} else {
|
||||
errMsg = launcher.getErrorMessage();
|
||||
}
|
||||
currProject.setSessionProperty(qName, !monitor.isCanceled() && !isClean ? new Integer(streamMon.getWorkDone()) : null);
|
||||
|
||||
if (errMsg != null) {
|
||||
buf = new StringBuffer(buildCommand.toString() + " "); //$NON-NLS-1$
|
||||
for (String arg : buildArguments) {
|
||||
buf.append(arg);
|
||||
buf.append(' ');
|
||||
}
|
||||
|
||||
String errorDesc = ManagedMakeMessages.getFormattedString("MakeBuilder.buildError", buf.toString()); //$NON-NLS-1$
|
||||
buf = new StringBuffer(errorDesc);
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
cos.write(buf.toString().getBytes());
|
||||
cos.flush();
|
||||
}
|
||||
|
||||
stdout.close();
|
||||
stderr.close();
|
||||
|
||||
monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Creating_Markers")); //$NON-NLS-1$
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
cos.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
throw new CoreException(new Status(IStatus.ERROR,
|
||||
ManagedBuilderCorePlugin.getUniqueIdentifier(),
|
||||
e.getLocalizedMessage(),
|
||||
e));
|
||||
} finally {
|
||||
monitor.done();
|
||||
}
|
||||
return (isClean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the build has been canceled.
|
||||
*/
|
||||
|
@ -1996,65 +1304,6 @@ public class CommonBuilder extends ACBuilder {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected String[] getTargets(int kind, IBuilder builder) {
|
||||
String targetsArray[] = null;
|
||||
|
||||
if(kind != CLEAN_BUILD && !builder.isCustomBuilder() && builder.isManagedBuildOn()){
|
||||
IConfiguration cfg = builder.getParent().getParent();
|
||||
String preBuildStep = cfg.getPrebuildStep();
|
||||
try {
|
||||
preBuildStep = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(
|
||||
preBuildStep,
|
||||
"", //$NON-NLS-1$
|
||||
" ", //$NON-NLS-1$
|
||||
IBuildMacroProvider.CONTEXT_CONFIGURATION,
|
||||
cfg);
|
||||
} catch (BuildMacroException e) {
|
||||
}
|
||||
|
||||
if(preBuildStep != null && preBuildStep.length() != 0){
|
||||
targetsArray = new String[]{"pre-build", "main-build"}; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
if(targetsArray == null){
|
||||
String targets = ""; //$NON-NLS-1$
|
||||
switch (kind) {
|
||||
case IncrementalProjectBuilder.AUTO_BUILD :
|
||||
targets = builder.getAutoBuildTarget();
|
||||
break;
|
||||
case IncrementalProjectBuilder.INCREMENTAL_BUILD : // now treated as the same!
|
||||
case IncrementalProjectBuilder.FULL_BUILD :
|
||||
targets = builder.getIncrementalBuildTarget();
|
||||
break;
|
||||
case IncrementalProjectBuilder.CLEAN_BUILD :
|
||||
targets = builder.getCleanBuildTarget();
|
||||
break;
|
||||
}
|
||||
|
||||
targetsArray = argumentsToArray(targets);
|
||||
}
|
||||
|
||||
return targetsArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing arguments in a shell style
|
||||
*/
|
||||
private String[] argumentsToArray(String args) {
|
||||
return CommandLineUtil.argumentsToArray(args);
|
||||
}
|
||||
|
||||
private void removeAllMarkers(IProject currProject) throws CoreException {
|
||||
IWorkspace workspace = currProject.getWorkspace();
|
||||
|
||||
// remove all markers
|
||||
IMarker[] markers = currProject.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
|
||||
if (markers != null) {
|
||||
workspace.deleteMarkers(markers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only lock the workspace is this is a ManagedBuild, or this project references others.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue