Bug 366039: Internal Builder reduced build step input resource count
authorJohn Dallaway <john@dallaway.org.uk>
Mon, 26 Oct 2015 11:00:04 +0000 (11:00 +0000)
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>
Wed, 16 Dec 2015 13:59:48 +0000 (08:59 -0500)
Change-Id: I7c7c8ba5d1bf7b96bbef66449ea6470f3c266f98
Signed-off-by: John Dallaway <john@dallaway.org.uk>
(cherry picked from commit e62e2772fe26628dbdc0cf86675983f7c399e7aa)

build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java

index 125cf36..45c45fd 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors:
  * Intel Corporation - Initial API and implementation
  * IBM Corporation
+ * John Dallaway - Handle reduced build step input resource count (bug 366039)
  *******************************************************************************/
 package org.eclipse.cdt.managedbuilder.internal.buildmodel;
 
@@ -329,18 +330,28 @@ public class BuildDescription implements IBuildDescription {
 
                        }
 
-                       if(!removed && !rebuild){
+                       if(!removed){
                                for (BuildResource rc : rcs) {
                                        if(rc.needsRebuild()){
                                                if(DbgUtil.DEBUG)
                                                        DbgUtil.trace("resource " + locationToRel(rc.getLocation()).toString() + " needs rebuild");     //$NON-NLS-1$   //$NON-NLS-2$
                                                rebuild = true;
-                                               break;
-                                       } else if(rc.isRemoved()){
+                                       }
+                                       if(rc.isRemoved()){
                                                if(DbgUtil.DEBUG)
                                                        DbgUtil.trace("resource " + locationToRel(rc.getLocation()).toString() + " is removed");        //$NON-NLS-1$   //$NON-NLS-2$
+
+                                               // Remove the obsolete input resource from the action (Bug #366039)
+                                               for (BuildIOType type : action.getPrimaryTypes(true)) {
+                                                       for (BuildResource res : (BuildResource[]) type.getResources()) {
+                                                               if (res.equals(rc)) {
+                                                                       action.removeResource(type, rc, true);
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+
                                                rebuild = true;
-                                               break;
                                        }
                                }
                        }
@@ -356,6 +367,9 @@ public class BuildDescription implements IBuildDescription {
                                                DbgUtil.trace("setting remove state for resource " + locationToRel(outRc.getLocation()).toString());    //$NON-NLS-1$
 
                                        ((BuildResource)outRc).setRemoved(true);
+
+                                       // Delete the obsolete output file (Bug #366039)
+                                       deleteResource(outRc);
                                }
 
                        } else if(rebuild){
@@ -379,6 +393,23 @@ public class BuildDescription implements IBuildDescription {
                }
        }
 
+       private void deleteResource(IBuildResource rc) {
+               if (rc.isProjectResource()) {
+                       final IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(rc.getFullPath());
+                       if ((resource != null) && resource.isDerived(IResource.CHECK_ANCESTORS)) {
+                               if (DbgUtil.DEBUG) {
+                                       DbgUtil.trace("deleting resource " + locationToRel(rc.getLocation()).toString()); //$NON-NLS-1$
+                               }
+                               try {
+                                       resource.delete(false, null);
+                               } catch (CoreException e) {
+                                       ManagedBuilderCorePlugin.log(new Status(IStatus.WARNING,
+                                                       ManagedBuilderCorePlugin.PLUGIN_ID,     IStatus.OK, e.getMessage(), e));
+                               }
+                       }
+               }
+       }
+
        private class ToolOrderEstimation {
                private ITool fTool;
                private ITool fDeps[];