mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 01:05:38 +02:00
Bug 528940 - Execute pre/post build step
Execute the pre and post build steps as part of the build when using the internal builder in parallel mode. Change-Id: I840da0d7025597dc5b3edc1bb54a5ca45b6e2e86 Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com> Signed-off-by: Samuel Hultgren <samuel.hultgren@st.com>
This commit is contained in:
parent
8982ef90e7
commit
bb5f2d7f78
2 changed files with 84 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
* Samuel Hultgren (STMicroelectronics) - bug #217674
|
||||
* Torbjörn Svensson (STMicroelectronics) - bug #528940
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.internal.buildmodel;
|
||||
|
||||
|
@ -28,6 +29,8 @@ import org.eclipse.cdt.managedbuilder.buildmodel.IBuildStep;
|
|||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -232,6 +235,7 @@ public class ParallelBuilder {
|
|||
* ParallelBuilder#STATUS_INVALID}.
|
||||
*/
|
||||
static public int build(IBuildDescription des, IPath cwd, GenDirInfo dirs, OutputStream out, OutputStream err, IProgressMonitor monitor, boolean resumeOnErrors, boolean buildIncrementally, IResourceRebuildStateContainer rs) {
|
||||
int status = IBuildModelBuilder.STATUS_OK;
|
||||
IConfiguration cfg = des.getConfiguration();
|
||||
if(dirs == null) dirs = new GenDirInfo(cfg);
|
||||
if(cwd == null) cwd = des.getDefaultBuildDirLocation();
|
||||
|
@ -241,22 +245,100 @@ public class ParallelBuilder {
|
|||
}
|
||||
|
||||
ParallelBuilder builder = new ParallelBuilder(cwd, dirs, out, err, monitor, resumeOnErrors, buildIncrementally, rs, des);
|
||||
|
||||
status = builder.executePreBuildStep();
|
||||
if (status != IBuildModelBuilder.STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
builder.initRebuildStates();
|
||||
builder.enqueueAll(des);
|
||||
builder.sortQueue();
|
||||
monitor.beginTask("", builder.queue.size()); //$NON-NLS-1$
|
||||
BuildProcessManager buildProcessManager = new BuildProcessManager(out, err, true, threads);
|
||||
int status = builder.dispatch(buildProcessManager);
|
||||
status = builder.dispatch(buildProcessManager);
|
||||
lastThreadsUsed = buildProcessManager.getThreadsUsed();
|
||||
monitor.done();
|
||||
|
||||
if (status == IBuildModelBuilder.STATUS_OK) {
|
||||
builder.clearRebuildStates();
|
||||
status = builder.executePostBuildStep();
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all pre build commands
|
||||
*
|
||||
* @return the status of the operation, one of {@link ParallelBuilder#STATUS_OK},
|
||||
* {@link ParallelBuilder#STATUS_ERROR}, {@link ParallelBuilder#STATUS_CANCELED}, or {@link
|
||||
* ParallelBuilder#STATUS_INVALID}.
|
||||
*/
|
||||
protected int executePreBuildStep() {
|
||||
// Ensure that the target directory exist
|
||||
cwd.toFile().mkdirs();
|
||||
|
||||
// Validate that the CWD is an actual directory
|
||||
if (cwd.toFile().exists() && !cwd.toFile().isDirectory()) {
|
||||
printMessage(ManagedMakeMessages.getFormattedString("ParallelBuilder.missingOutDir", "" + cwd), err); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return IBuildModelBuilder.STATUS_ERROR_BUILD;
|
||||
}
|
||||
|
||||
return executeStep(fDes.getInputStep());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all post build commands
|
||||
*
|
||||
* @return the status of the operation, one of {@link ParallelBuilder#STATUS_OK},
|
||||
* {@link ParallelBuilder#STATUS_ERROR}, {@link ParallelBuilder#STATUS_CANCELED}, or {@link
|
||||
* ParallelBuilder#STATUS_INVALID}.
|
||||
*/
|
||||
protected int executePostBuildStep() {
|
||||
return executeStep(fDes.getOutputStep());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute all the commands associated with step
|
||||
*
|
||||
* @param step The build step
|
||||
* @return the status of the operation, one of {@link ParallelBuilder#STATUS_OK},
|
||||
* {@link ParallelBuilder#STATUS_ERROR}, {@link ParallelBuilder#STATUS_CANCELED}, or {@link
|
||||
* ParallelBuilder#STATUS_INVALID}.
|
||||
*/
|
||||
protected int executeStep(IBuildStep step) {
|
||||
if (hasResourceToBuild() && step != null) {
|
||||
IProject project = (IProject)fDes.getConfiguration().getOwner();
|
||||
IBuildCommand[] bcs = step.getCommands(cwd, null, null, true);
|
||||
for (IBuildCommand bc : bcs) {
|
||||
CommandBuilder cb = new CommandBuilder(bc, fRebuildStateContainer, project);
|
||||
int status = cb.build(out, err, monitor);
|
||||
if (status != IBuildModelBuilder.STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return IBuildModelBuilder.STATUS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is one or more resource that needs to be built
|
||||
*
|
||||
* @return True if one or more resource that needs to be built
|
||||
*/
|
||||
protected boolean hasResourceToBuild() {
|
||||
if (buildIncrementally && fDes instanceof BuildDescription) {
|
||||
IResourceDelta delta = ((BuildDescription) fDes).getDelta();
|
||||
if (delta != null && delta.getAffectedChildren() != null && delta.getAffectedChildren().length <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initRebuildStates() {
|
||||
if (fRebuildStateContainer == null) {
|
||||
return;
|
||||
|
|
|
@ -161,6 +161,7 @@ CommonBuilder.13=can not clean programmatically: build folder is not accessible
|
|||
CommonBuilder.22=Building referenced configurations..
|
||||
CommonBuilder.23=Buildfile generation error occurred..
|
||||
CommonBuilder.24=Build stopped..
|
||||
ParallelBuilder.missingOutDir=Failed to create output directory {0}
|
||||
|
||||
MakeBuilder.buildError=
|
||||
MultiResourceInfo.MultiResourceInfo.UnhandledIHoldsOptionsType=Unhandled parent type: not ITool nor IToolChain
|
||||
|
|
Loading…
Add table
Reference in a new issue