mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Progress Monitor support for internal builder
This commit is contained in:
parent
d29e62720b
commit
77d9a2e79b
4 changed files with 140 additions and 28 deletions
|
@ -82,6 +82,10 @@ public class CommandBuilder implements IBuildModelBuilder {
|
||||||
public int build(OutputStream out, OutputStream err,
|
public int build(OutputStream out, OutputStream err,
|
||||||
IProgressMonitor monitor){
|
IProgressMonitor monitor){
|
||||||
|
|
||||||
|
//TODO: should we display the command line here?
|
||||||
|
monitor.beginTask("", getNumCommands()); //$NON-NLS-1$
|
||||||
|
monitor.subTask(""/*getCommandLine()*/); //$NON-NLS-1$
|
||||||
|
|
||||||
CommandLauncher launcher = new CommandLauncher();
|
CommandLauncher launcher = new CommandLauncher();
|
||||||
int status = STATUS_OK;
|
int status = STATUS_OK;
|
||||||
|
|
||||||
|
@ -99,8 +103,7 @@ public class CommandBuilder implements IBuildModelBuilder {
|
||||||
|
|
||||||
//wrapping out and err streams to avoid their closure
|
//wrapping out and err streams to avoid their closure
|
||||||
int st = launcher.waitAndRead(wrap(out), wrap(err),
|
int st = launcher.waitAndRead(wrap(out), wrap(err),
|
||||||
new SubProgressMonitor(monitor,
|
new SubProgressMonitor(monitor, getNumCommands()));
|
||||||
IProgressMonitor.UNKNOWN));
|
|
||||||
switch(st){
|
switch(st){
|
||||||
case CommandLauncher.OK:
|
case CommandLauncher.OK:
|
||||||
if(fProcess.exitValue() != 0)
|
if(fProcess.exitValue() != 0)
|
||||||
|
@ -124,6 +127,8 @@ public class CommandBuilder implements IBuildModelBuilder {
|
||||||
printMessage(fErrMsg, out);
|
printMessage(fErrMsg, out);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monitor.done();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,4 +163,22 @@ public class CommandBuilder implements IBuildModelBuilder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumCommands() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getCommandLine() {
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
if (fCmd != null) {
|
||||||
|
buf.append(fCmd.getCommand().toOSString());
|
||||||
|
String args[] = fCmd.getArgs();
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
buf.append(' ');
|
||||||
|
buf.append(args[i]);
|
||||||
|
}
|
||||||
|
buf.append(LINE_SEPARATOR);
|
||||||
|
}
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
package org.eclipse.cdt.managedbuilder.internal.buildmodel;
|
package org.eclipse.cdt.managedbuilder.internal.buildmodel;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
|
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
|
||||||
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
|
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
|
||||||
|
@ -19,6 +21,8 @@ import org.eclipse.cdt.managedbuilder.buildmodel.IStepVisitor;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -36,19 +40,27 @@ public class DescriptionBuilder implements IBuildModelBuilder {
|
||||||
private IPath fCWD;
|
private IPath fCWD;
|
||||||
private boolean fBuildIncrementaly;
|
private boolean fBuildIncrementaly;
|
||||||
private boolean fResumeOnErrs;
|
private boolean fResumeOnErrs;
|
||||||
|
private Map fStepToStepBuilderMap = new HashMap();
|
||||||
|
private int fNumCommands = -1;
|
||||||
|
private GenDirInfo fDir;
|
||||||
|
|
||||||
private class BuildStepVisitor implements IStepVisitor{
|
private class BuildStepVisitor implements IStepVisitor{
|
||||||
private OutputStream fOut;
|
private OutputStream fOut;
|
||||||
private OutputStream fErr;
|
private OutputStream fErr;
|
||||||
private IProgressMonitor fMonitor;
|
private IProgressMonitor fMonitor;
|
||||||
private GenDirInfo fDir = new GenDirInfo(fDes.getConfiguration());
|
|
||||||
private int fStatus;
|
private int fStatus;
|
||||||
|
private boolean fBuild;
|
||||||
|
|
||||||
public BuildStepVisitor(OutputStream out, OutputStream err, IProgressMonitor monitor){
|
public BuildStepVisitor(OutputStream out, OutputStream err, IProgressMonitor monitor){
|
||||||
|
this(out, err, monitor, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuildStepVisitor(OutputStream out, OutputStream err, IProgressMonitor monitor, boolean build){
|
||||||
fOut = out;
|
fOut = out;
|
||||||
fErr = err;
|
fErr = err;
|
||||||
fMonitor = monitor;
|
fMonitor = monitor;
|
||||||
fStatus = STATUS_OK;
|
fStatus = STATUS_OK;
|
||||||
|
fBuild = build;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -64,19 +76,23 @@ public class DescriptionBuilder implements IBuildModelBuilder {
|
||||||
&& (!fBuildIncrementaly || action.needsRebuild())){
|
&& (!fBuildIncrementaly || action.needsRebuild())){
|
||||||
if(DbgUtil.DEBUG)
|
if(DbgUtil.DEBUG)
|
||||||
DbgUtil.trace("step " + DbgUtil.stepName(action) + " needs rebuild" );
|
DbgUtil.trace("step " + DbgUtil.stepName(action) + " needs rebuild" );
|
||||||
StepBuilder builder = new StepBuilder(action, fCWD, fResumeOnErrs, fDir);
|
StepBuilder builder = getStepBuilder(action);//new StepBuilder(action, fCWD, fResumeOnErrs, fDir);
|
||||||
|
|
||||||
switch(builder.build(fOut, fErr, fMonitor)){
|
if(fBuild){
|
||||||
case STATUS_OK:
|
switch(builder.build(fOut, fErr, new SubProgressMonitor(fMonitor, builder.getNumCommands()))){
|
||||||
|
case STATUS_OK:
|
||||||
|
break;
|
||||||
|
case STATUS_CANCELLED:
|
||||||
|
fStatus = STATUS_CANCELLED;
|
||||||
|
break;
|
||||||
|
case STATUS_ERROR_BUILD:
|
||||||
|
case STATUS_ERROR_LAUNCH:
|
||||||
|
default:
|
||||||
|
fStatus = STATUS_ERROR_BUILD;
|
||||||
break;
|
break;
|
||||||
case STATUS_CANCELLED:
|
}
|
||||||
fStatus = STATUS_CANCELLED;
|
} else {
|
||||||
break;
|
fNumCommands += builder.getNumCommands();
|
||||||
case STATUS_ERROR_BUILD:
|
|
||||||
case STATUS_ERROR_LAUNCH:
|
|
||||||
default:
|
|
||||||
fStatus = STATUS_ERROR_BUILD;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +121,7 @@ public class DescriptionBuilder implements IBuildModelBuilder {
|
||||||
fCWD = cwd;
|
fCWD = cwd;
|
||||||
fBuildIncrementaly = buildIncrementaly;
|
fBuildIncrementaly = buildIncrementaly;
|
||||||
fResumeOnErrs = resumeOnErrs;
|
fResumeOnErrs = resumeOnErrs;
|
||||||
|
fDir = new GenDirInfo(fDes.getConfiguration());
|
||||||
|
|
||||||
if(fCWD == null)
|
if(fCWD == null)
|
||||||
fCWD = fDes.getDefaultBuildDirLocation();
|
fCWD = fDes.getDefaultBuildDirLocation();
|
||||||
|
@ -116,6 +133,10 @@ public class DescriptionBuilder implements IBuildModelBuilder {
|
||||||
public int build(OutputStream out, OutputStream err,
|
public int build(OutputStream out, OutputStream err,
|
||||||
IProgressMonitor monitor){
|
IProgressMonitor monitor){
|
||||||
|
|
||||||
|
//TODO: should we specify some task name here?
|
||||||
|
monitor.beginTask("", getNumCommands()); //$NON-NLS-1$
|
||||||
|
monitor.subTask(""); //$NON-NLS-1$
|
||||||
|
|
||||||
BuildStepVisitor visitor = new BuildStepVisitor(out, err, monitor);
|
BuildStepVisitor visitor = new BuildStepVisitor(out, err, monitor);
|
||||||
try {
|
try {
|
||||||
BuildDescriptionManager.accept(visitor,
|
BuildDescriptionManager.accept(visitor,
|
||||||
|
@ -123,7 +144,35 @@ public class DescriptionBuilder implements IBuildModelBuilder {
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return STATUS_ERROR_LAUNCH;
|
return STATUS_ERROR_LAUNCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monitor.done();
|
||||||
|
|
||||||
return visitor.fStatus;
|
return visitor.fStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumCommands() {
|
||||||
|
if(fNumCommands == -1){
|
||||||
|
fNumCommands = 0;
|
||||||
|
BuildStepVisitor visitor = new BuildStepVisitor(null, null, new NullProgressMonitor(), false);
|
||||||
|
try {
|
||||||
|
BuildDescriptionManager.accept(visitor,
|
||||||
|
fDes, true);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
//TODO: report an error
|
||||||
|
}
|
||||||
|
if(DbgUtil.DEBUG)
|
||||||
|
DbgUtil.trace("Description Builder: total work = " + fNumCommands); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
return fNumCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected StepBuilder getStepBuilder(IBuildStep step){
|
||||||
|
StepBuilder b = (StepBuilder)fStepToStepBuilderMap.get(step);
|
||||||
|
if(b == null){
|
||||||
|
b = new StepBuilder(step, fCWD, fResumeOnErrs, fDir);
|
||||||
|
fStepToStepBuilderMap.put(step, b);
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -39,6 +41,8 @@ public class StepBuilder implements IBuildModelBuilder {
|
||||||
private IPath fCWD;
|
private IPath fCWD;
|
||||||
private GenDirInfo fDirs;
|
private GenDirInfo fDirs;
|
||||||
private boolean fResumeOnErrs;
|
private boolean fResumeOnErrs;
|
||||||
|
private int fNumCommands = -1;
|
||||||
|
private CommandBuilder fCommandBuilders[];
|
||||||
|
|
||||||
public StepBuilder(IBuildStep step){
|
public StepBuilder(IBuildStep step){
|
||||||
this(step, null);
|
this(step, null);
|
||||||
|
@ -66,18 +70,23 @@ public class StepBuilder implements IBuildModelBuilder {
|
||||||
*/
|
*/
|
||||||
public int build(OutputStream out, OutputStream err,
|
public int build(OutputStream out, OutputStream err,
|
||||||
IProgressMonitor monitor){
|
IProgressMonitor monitor){
|
||||||
|
|
||||||
|
monitor.beginTask("", getNumCommands()); //$NON-NLS-1$
|
||||||
|
monitor.subTask(""); //$NON-NLS-1$
|
||||||
|
|
||||||
int status = STATUS_OK;
|
int status = STATUS_OK;
|
||||||
IBuildCommand cmds[] = fStep.getCommands(fCWD, null, null, true);
|
CommandBuilder bs[] = getCommandBuilders();
|
||||||
if(cmds != null){
|
if(bs.length > 0){
|
||||||
createOutDirs(monitor);
|
//TODO: monitor
|
||||||
|
createOutDirs(new NullProgressMonitor());
|
||||||
|
|
||||||
for(int i = 0;
|
for(int i = 0;
|
||||||
i < cmds.length
|
i < bs.length
|
||||||
&& status != STATUS_CANCELLED
|
&& status != STATUS_CANCELLED
|
||||||
&& (fResumeOnErrs || status == STATUS_OK);
|
&& (fResumeOnErrs || status == STATUS_OK);
|
||||||
i++){
|
i++){
|
||||||
CommandBuilder builder = new CommandBuilder(cmds[i]);
|
CommandBuilder builder = bs[i];
|
||||||
switch(builder.build(out, err, monitor)){
|
switch(builder.build(out, err, new SubProgressMonitor(monitor, builder.getNumCommands()))){
|
||||||
case STATUS_OK:
|
case STATUS_OK:
|
||||||
break;
|
break;
|
||||||
case STATUS_CANCELLED:
|
case STATUS_CANCELLED:
|
||||||
|
@ -92,8 +101,10 @@ public class StepBuilder implements IBuildModelBuilder {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status = postProcess(status, monitor);
|
//TODO: monitor
|
||||||
|
status = postProcess(status, new NullProgressMonitor());
|
||||||
}
|
}
|
||||||
|
monitor.done();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,4 +177,30 @@ public class StepBuilder implements IBuildModelBuilder {
|
||||||
fDirs.createDir(rcs[i], monitor);
|
fDirs.createDir(rcs[i], monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumCommands() {
|
||||||
|
if(fNumCommands == -1){
|
||||||
|
CommandBuilder bs[] = getCommandBuilders();
|
||||||
|
fNumCommands = 0;
|
||||||
|
for(int i = 0; i < bs.length; i++){
|
||||||
|
fNumCommands += bs[i].getNumCommands();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fNumCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CommandBuilder[] getCommandBuilders(){
|
||||||
|
if(fCommandBuilders == null){
|
||||||
|
IBuildCommand cmds[] = fStep.getCommands(fCWD, null, null, true);
|
||||||
|
if(cmds == null)
|
||||||
|
fCommandBuilders = new CommandBuilder[0];
|
||||||
|
else {
|
||||||
|
fCommandBuilders = new CommandBuilder[cmds.length];
|
||||||
|
for(int i = 0; i < cmds.length; i++){
|
||||||
|
fCommandBuilders[i] = new CommandBuilder(cmds[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fCommandBuilders;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1188,6 +1188,13 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
||||||
if (monitor == null) {
|
if (monitor == null) {
|
||||||
monitor = new NullProgressMonitor();
|
monitor = new NullProgressMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] msgs = new String[2];
|
||||||
|
msgs[0] = ManagedMakeMessages.getResourceString(INTERNAL_BUILDER);
|
||||||
|
msgs[1] = currentProject.getName();
|
||||||
|
|
||||||
|
monitor.beginTask("", 1000); //$NON-NLS-1$
|
||||||
|
monitor.subTask(ManagedMakeMessages.getFormattedString(MAKE, msgs));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
@ -1200,12 +1207,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
||||||
|
|
||||||
IBuildDescription des = BuildDescriptionManager.createBuildDescription(cfg, delta, flags);
|
IBuildDescription des = BuildDescriptionManager.createBuildDescription(cfg, delta, flags);
|
||||||
|
|
||||||
IBuildModelBuilder builder = new DescriptionBuilder(des, buildIncrementaly, resumeOnErr);
|
DescriptionBuilder builder = new DescriptionBuilder(des, buildIncrementaly, resumeOnErr);
|
||||||
|
|
||||||
String[] msgs = new String[2];
|
|
||||||
msgs[0] = ManagedMakeMessages.getResourceString(INTERNAL_BUILDER);
|
|
||||||
msgs[1] = currentProject.getName();
|
|
||||||
monitor.subTask(ManagedMakeMessages.getFormattedString(MAKE, msgs));
|
|
||||||
|
|
||||||
// Get a build console for the project
|
// Get a build console for the project
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
|
@ -1247,7 +1249,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
||||||
// until we explicitly close it. See bug#123302.
|
// until we explicitly close it. See bug#123302.
|
||||||
OutputStream epmOutputStream = epm.getOutputStream();
|
OutputStream epmOutputStream = epm.getOutputStream();
|
||||||
|
|
||||||
int status = builder.build(epmOutputStream, epmOutputStream, monitor);
|
int status = builder.build(epmOutputStream, epmOutputStream, new SubProgressMonitor(monitor, 1000));
|
||||||
|
|
||||||
//no refresh is needed since the builder now performs
|
//no refresh is needed since the builder now performs
|
||||||
//a refresh automatically after each build step
|
//a refresh automatically after each build step
|
||||||
|
@ -1310,6 +1312,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
||||||
forgetLastBuiltState();
|
forgetLastBuiltState();
|
||||||
} finally {
|
} finally {
|
||||||
getGenerationProblems().clear();
|
getGenerationProblems().clear();
|
||||||
|
monitor.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue