mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
1. Fix for [Bug 203056] Change Clean behaviour
2. Internal builder-based clean implementation
This commit is contained in:
parent
99cc9e3e84
commit
5ec9c633a4
3 changed files with 129 additions and 14 deletions
|
@ -130,6 +130,8 @@ public class BuildDescription implements IBuildDescription {
|
|||
|
||||
private PathSettingsContainer fToolInfos;
|
||||
|
||||
private BuildStep fCleanStep;
|
||||
|
||||
private class ToolInfoHolder {
|
||||
Map fExtToToolAndTypeListMap;
|
||||
Map fInTypeToGroupMap = new HashMap();
|
||||
|
@ -1452,6 +1454,18 @@ public class BuildDescription implements IBuildDescription {
|
|||
}
|
||||
return (IBuildResource[])list.toArray(new IBuildResource[list.size()]);
|
||||
}
|
||||
|
||||
public IBuildResource[] getResources(boolean generated){
|
||||
IBuildResource[] rcs = getResources();
|
||||
List list = new ArrayList();
|
||||
for(int i = 0; i < rcs.length; i++){
|
||||
IBuildResource rc = rcs[i];
|
||||
if(generated == (rc.getProducerStep() != fInputStep))
|
||||
list.add(rc);
|
||||
}
|
||||
|
||||
return (IBuildResource[])list.toArray(new IBuildResource[list.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.builddescription.IBuildDescription#getConfiguration()
|
||||
|
@ -2231,4 +2245,12 @@ public class BuildDescription implements IBuildDescription {
|
|||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
public IBuildStep getCleanStep(){
|
||||
if(fCleanStep == null){
|
||||
fCleanStep = new BuildStep(this, null, null);
|
||||
}
|
||||
return fCleanStep;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -251,20 +251,42 @@ public class BuildStep implements IBuildStep {
|
|||
* @see org.eclipse.cdt.managedbuilder.builddescription.IBuildStep#getCommands(org.eclipse.core.runtime.IPath, java.util.Map, java.util.Map, boolean)
|
||||
*/
|
||||
public IBuildCommand[] getCommands(IPath cwd, Map inputArgValues, Map outputArgValues, boolean resolveAll) {
|
||||
if(cwd == null)
|
||||
cwd = calcCWD();
|
||||
|
||||
|
||||
if(fTool == null){
|
||||
String step = null;
|
||||
String appendToLastStep = null;
|
||||
if(this == fBuildDescription.getInputStep()){
|
||||
step = fBuildDescription.getConfiguration().getPrebuildStep();
|
||||
} else if(this == fBuildDescription.getOutputStep()){
|
||||
step = fBuildDescription.getConfiguration().getPostbuildStep();
|
||||
} else if(this == fBuildDescription.getCleanStep()){
|
||||
step = fBuildDescription.getConfiguration().getCleanCommand();
|
||||
|
||||
IBuildResource[] generated = fBuildDescription.getResources(true);
|
||||
|
||||
if(generated.length != 0){
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for(int i = 0; i < generated.length; i++){
|
||||
buf.append(' ');
|
||||
|
||||
IPath rel = BuildDescriptionManager.getRelPath(cwd, generated[i].getLocation());
|
||||
buf.append(rel.toString());
|
||||
}
|
||||
appendToLastStep = buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
if(step != null && (step = step.trim()).length() > 0){
|
||||
step = resolveMacros(step, resolveAll);
|
||||
if(step != null && (step = step.trim()).length() > 0){
|
||||
String commands[] = step.split(";"); //$NON-NLS-1$
|
||||
if(cwd == null)
|
||||
cwd = calcCWD();
|
||||
|
||||
if(appendToLastStep != null && commands.length != 0){
|
||||
commands[commands.length - 1] = commands[commands.length - 1] + appendToLastStep;
|
||||
}
|
||||
|
||||
List list = new ArrayList();
|
||||
for(int i = 0; i < commands.length; i++){
|
||||
|
@ -279,8 +301,6 @@ public class BuildStep implements IBuildStep {
|
|||
return new IBuildCommand[0];
|
||||
}
|
||||
|
||||
if(cwd == null)
|
||||
cwd = calcCWD();
|
||||
|
||||
performAsignToOption(cwd);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.CommandLauncher;
|
|||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
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;
|
||||
|
@ -61,6 +62,7 @@ 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;
|
||||
|
@ -128,6 +130,8 @@ public class CommonBuilder extends ACBuilder {
|
|||
public static boolean VERBOSE = false;
|
||||
|
||||
private static CfgBuildSet fBuildSet = new CfgBuildSet();
|
||||
|
||||
private boolean fBuildErrOccured;
|
||||
|
||||
public CommonBuilder() {
|
||||
}
|
||||
|
@ -1492,6 +1496,19 @@ public class CommonBuilder extends ACBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
public void addMarker(IResource file, int lineNumber, String errorDesc,
|
||||
int severity, String errorVar) {
|
||||
super.addMarker(file, lineNumber, errorDesc, severity, errorVar);
|
||||
if(severity == IStatus.ERROR)
|
||||
fBuildErrOccured = true;
|
||||
}
|
||||
|
||||
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
|
||||
super.addMarker(problemMarkerInfo);
|
||||
if(problemMarkerInfo.severity == IStatus.ERROR)
|
||||
fBuildErrOccured = true;
|
||||
}
|
||||
|
||||
protected void clean(CfgBuildInfo bInfo, IProgressMonitor monitor) throws CoreException{
|
||||
if (shouldBuild(CLEAN_BUILD, bInfo.getBuilder())) {
|
||||
BuildStateManager bsMngr = BuildStateManager.getInstance();
|
||||
|
@ -1504,17 +1521,28 @@ public class CommonBuilder extends ACBuilder {
|
|||
bsMngr.setProjectBuildState(project, pbs);
|
||||
}
|
||||
|
||||
boolean performExternalClean = true;
|
||||
if(shouldCleanProgrammatically(bInfo)){
|
||||
try {
|
||||
cleanProgrammatically(bInfo, monitor);
|
||||
performExternalClean = false;
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if(performExternalClean){
|
||||
if(!cfg.getEditableBuilder().isManagedBuildOn()){
|
||||
performExternalClean(bInfo, false, monitor);
|
||||
} else {
|
||||
boolean programmatically = true;
|
||||
if(!cfg.getEditableBuilder().isInternalBuilder()){
|
||||
fBuildErrOccured = false;
|
||||
try {
|
||||
performExternalClean(bInfo, false, monitor);
|
||||
} catch (CoreException e) {
|
||||
fBuildErrOccured = true;
|
||||
}
|
||||
if(!fBuildErrOccured)
|
||||
programmatically = false;
|
||||
}
|
||||
|
||||
if(programmatically){
|
||||
try {
|
||||
cleanWithInternalBuilder(bInfo, monitor);
|
||||
} catch (CoreException e) {
|
||||
cleanProgrammatically(bInfo, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1567,6 +1595,51 @@ public class CommonBuilder extends ACBuilder {
|
|||
// return cfg.getOwner().getProject().getFullPath().isPrefixOf(path);
|
||||
}
|
||||
|
||||
protected void cleanWithInternalBuilder(CfgBuildInfo bInfo, IProgressMonitor monitor) throws CoreException {
|
||||
// referencedProjects = getProject().getReferencedProjects();
|
||||
IProject curProject = bInfo.getProject();
|
||||
outputTrace(curProject.getName(), "Clean build with Internal Builder requested"); //$NON-NLS-1$
|
||||
IConfiguration cfg = bInfo.getConfiguration();
|
||||
int flags = BuildDescriptionManager.DEPFILES;
|
||||
BuildDescription des = (BuildDescription)BuildDescriptionManager.createBuildDescription(cfg, null, null, flags);
|
||||
|
||||
IBuildStep cleanStep = des.getCleanStep();
|
||||
|
||||
StepBuilder sBuilder = new StepBuilder(cleanStep, null, null);
|
||||
|
||||
try {
|
||||
// try the brute force approach first
|
||||
StringBuffer buf = new StringBuffer();
|
||||
// write to the console
|
||||
//
|
||||
// IConsole console = CCorePlugin.getDefault().getConsole();
|
||||
// console.start(getProject());
|
||||
IConsole console = bInfo.getConsole();
|
||||
ConsoleOutputStream consoleOutStream = console.getOutputStream();
|
||||
String[] consoleHeader = new String[3];
|
||||
consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_CLEAN);
|
||||
consoleHeader[1] = cfg.getName();
|
||||
consoleHeader[2] = curProject.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$
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
buf = new StringBuffer();
|
||||
|
||||
sBuilder.build(consoleOutStream, consoleOutStream, monitor);
|
||||
|
||||
// Report a successful clean
|
||||
String successMsg = ManagedMakeMessages.getFormattedString(BUILD_FINISHED, curProject.getName());
|
||||
buf.append(successMsg);
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
consoleOutStream.close();
|
||||
} catch (IOException io) {} // Ignore console failures...
|
||||
|
||||
}
|
||||
|
||||
protected void cleanProgrammatically(CfgBuildInfo bInfo, IProgressMonitor monitor) throws CoreException {
|
||||
// referencedProjects = getProject().getReferencedProjects();
|
||||
IProject curProject = bInfo.getProject();
|
||||
|
|
Loading…
Add table
Reference in a new issue