Fix for Bug 10757 (Build is not started when "Use default incremental builder" option is set in preferences).
authorstechong
Wed, 21 Apr 2010 14:14:01 -0500
changeset 1257 7adc53ca3844
parent 1250 5995486b4bed
child 1259 2a211a55b277
Fix for Bug 10757 (Build is not started when "Use default incremental builder" option is set in preferences).
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/builder/CarbideCPPBuilder.java
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/builder/CarbideCPPBuilder.java	Tue Apr 20 13:33:46 2010 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/builder/CarbideCPPBuilder.java	Wed Apr 21 14:14:01 2010 -0500
@@ -148,6 +148,7 @@
 		IProject currentProject = getProject();
 		ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(currentProject);
 		if (cpi != null) {
+			ICarbideBuildConfiguration defaultConfig = cpi.getDefaultConfiguration();
 			if (cpi.incrementalBuilderEnabled()) {
 				// the callOnEmptyDelta builder attribute is set, so we get called
 				// not matter what, even with an empty delta.  this means that when the
@@ -157,30 +158,29 @@
 				IResourceDelta delta = getDelta(currentProject);
 				if (delta != null) {
 					// something in the workspace has changed.  see if a rebuild is needed.
-					if (!shouldRebuild(delta)) {
-
-						// also rebuild if the project has errors
-						boolean hasErrors = false;
-				    	try {
-							for (IMarker currMarker : getProject().findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)){
-								if (currMarker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR){
-									hasErrors = true;
-									break;
+					if (shouldRebuild(delta)) {
+						// set rebuild flag in build configs
+						shouldRebuildConfigs(cpi);
+					} else {
+						if (defaultConfig != null) {
+							// check current build config to see if rebuild is needed
+							CarbideBuildConfiguration config = (CarbideBuildConfiguration) defaultConfig;
+							if (!config.getRebuildNeeded()) {
+								// also rebuild if the project has errors
+								if (!projectHasErrors()) {
+									return null;
 								}
 							}
-							
-						} catch (CoreException e){
-							e.printStackTrace();
-						}
-						
-						if (!hasErrors) {
-							return null;
+						} else {
+							// also rebuild if the project has errors
+							if (!projectHasErrors()) {
+								return null;
+							}
 						}
 					}
 				}
 			}
 			
-			ICarbideBuildConfiguration defaultConfig = cpi.getDefaultConfiguration();
 			if (defaultConfig != null) {
 				CarbideCommandLauncher launcher = new CarbideCommandLauncher(currentProject, monitor, getParserIdArray(defaultConfig.getErrorParserId()), cpi.getINFWorkingDirectory());
 				launcher.showCommand(true);
@@ -188,6 +188,12 @@
 			} else {
 	   			CarbideBuilderPlugin.createCarbideProjectMarker(currentProject, IMarker.SEVERITY_ERROR,  "Project has no configurations.", IMarker.PRIORITY_HIGH);
 			}
+
+			if (!monitor.isCanceled() && cpi.incrementalBuilderEnabled() && defaultConfig != null) {
+				// reset rebuild flag in current build config after build succeeded
+				CarbideBuildConfiguration config = ((CarbideBuildConfiguration) defaultConfig);
+				config.setRebuildNeeded(false);
+			}
 		}
 		monitor.done();
 
@@ -219,6 +225,31 @@
 		return false;
 	}
 	
+    protected void shouldRebuildConfigs(ICarbideProjectInfo cpi) {
+    	List<ICarbideBuildConfiguration> configs = cpi.getBuildConfigurations();
+    	ICarbideBuildConfiguration defaultConfig = cpi.getDefaultConfiguration();
+    	for (ICarbideBuildConfiguration config : configs) {
+			CarbideBuildConfiguration cbc = (CarbideBuildConfiguration) config;
+			cbc.setRebuildNeeded(true);
+    	}
+    }
+
+	protected boolean projectHasErrors() {
+		boolean hasErrors = false;
+    	try {
+			for (IMarker currMarker : getProject().findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)){
+				if (currMarker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR){
+					hasErrors = true;
+					break;
+				}
+			}
+			
+		} catch (CoreException e){
+			e.printStackTrace();
+		}
+		return hasErrors;
+	}
+	
 	protected void clean(IProgressMonitor monitor) throws CoreException {
 
 		SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java	Tue Apr 20 13:33:46 2010 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java	Wed Apr 21 14:14:01 2010 -0500
@@ -71,6 +71,7 @@
 	protected BuildConfigurationData buildConfigData;
 	protected ROMBuilderInfo romBuilderInfo;
 	protected SBSv2BuilderInfo sbsv2BuilderInfo;
+	protected boolean rebuildNeeded;
 	
 	public CarbideBuildConfiguration(IProject project, ISymbianBuildContext context) {
 		super(context.getSDK(), context.getPlatformString(), context.getTargetString(), context.getSBSv2Alias());
@@ -83,6 +84,7 @@
 		if (context.getSBSv2Alias() != null){
 			sbsv2BuilderInfo = new SBSv2BuilderInfo(context);
 		}
+		rebuildNeeded = true;
 	}
 	
 	public void loadFromStorage(ICConfigurationDescription projDes) throws CoreException {
@@ -446,4 +448,13 @@
 		}
 		return getSDK().getReleaseRoot().append(releasePlatform.toLowerCase()).append(getTargetString().toLowerCase());
 	}
+ 	
+	public boolean getRebuildNeeded() {
+		return rebuildNeeded;
+	}
+	
+	public void setRebuildNeeded(boolean value) {
+		rebuildNeeded = value;
+	}
+	
 }