Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Rebuilding managed build project on properties change

Hello!

At the moment, when I change properties of a managed make project, a rebuild 
is automatically initiated. Unfortunately, that does not help when I, for 
example, change compiler options, because make is not capable of detecting 
when command line options change.

As result, user might end up with binaries that no longer correspond to 
project properties.

I see two solutions to this problem:

- Adding dependency from all targets to all makefiles
- Automatically cleaning project when properties change

The first approach looks a bit problematic for me, as getting right 
dependencies if there are several directories can be tricky.

The second approach is not so hard to implement, and the attached patch 
implements it. However, I wanted to discuss one point before adding this 
patch to bugzilla. At the moment, clean is done unconditionally. The 
motivation is to be on the safe side. Does this look OK? Should the code 
pop-up a dialog asking if project should be cleaned? That can please 
power-users, but the dialog can quickly become annoying.

Thanks,
Volodya



Index: org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java
===================================================================
--- org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java	(revision 148692)
+++ org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildPropertyPage.java	(revision 148693)
@@ -27,6 +27,7 @@
 import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
 import org.eclipse.cdt.utils.ui.controls.ControlFactory;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Preferences;
 import org.eclipse.jface.dialogs.DialogPage;
@@ -57,6 +58,12 @@
 import org.eclipse.ui.IWorkbenchPropertyPage;
 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
 import org.eclipse.ui.help.WorkbenchHelp;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.SubProgressMonitor;
 
 public class BuildPropertyPage extends AbstractBuildPropertyPage implements IWorkbenchPropertyPage, 
 					IPreferencePageContainer, ICOptionContainer {
@@ -259,6 +266,32 @@
 		//check for the inexistent configurations environment data stored in project preferences
 		EnvironmentVariableProvider.fUserSupplier.checkInexistentConfigurations(clonedConfiguration.getManagedProject());
 
+		if (!selectedConfiguration.needsRebuild())
+			return true;
+		
+		WorkspaceJob cleanJob = new WorkspaceJob("Cleaning the project") {
+			public boolean belongsTo(Object family) {
+				return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
+			}
+
+			public IStatus runInWorkspace(IProgressMonitor monitor)
+					throws CoreException {
+				try {
+					monitor.beginTask("Cleaning the project", 1);
+					getProject().build(IncrementalProjectBuilder.CLEAN_BUILD,
+							new SubProgressMonitor(monitor, 1));
+				} finally {
+					monitor.done();
+				}
+
+				return Status.OK_STATUS;
+			}
+		};
+		cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory()
+				.buildRule());
+		cleanJob.setUser(true);
+		cleanJob.schedule();
+		
 		return true;
 	}
 	

Back to the top