Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Small bug fix and some more work on incremental build

Sure is nice to have a project all to myself! Anyway, details are in the 
change logs. The fix is for bug 43017, something I need anyway. The 
incremental build work is to make a full rebuild happen when the build 
settings change through the UI. Tested the changes on Linux and Win32.


Sean Evoy
Rational Software - IBM Software Group
Ottawa, Ontario, Canada
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.ui/ChangeLog,v
retrieving revision 1.1
diff -u -r1.1 ChangeLog
--- ChangeLog	15 Sep 2003 20:44:43 -0000	1.1
+++ ChangeLog	16 Sep 2003 19:34:57 -0000
@@ -1,3 +1,11 @@
+2003-09-16 Sean Evoy
+	Changed the initialization and button status logic so the list buttons are 
+	enabled correctly on start-up and that the fist item in the list (if 
+	any) is selected. Also changed the "Add" event handler to properly enable 
+	the buttons and set the list selection.
+	
+	* src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionListFieldEditor.java
+
 2003-09-15 Sean Evoy
 	First submission of code to new project. Moved all the managed 
 	builder-specific UI elements out of the cdt.ui project. This 
Index: src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionListFieldEditor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionListFieldEditor.java,v
retrieving revision 1.1
diff -u -r1.1 BuildOptionListFieldEditor.java
--- src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionListFieldEditor.java	15 Sep 2003 20:44:42 -0000	1.1
+++ src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionListFieldEditor.java	16 Sep 2003 19:34:57 -0000
@@ -90,11 +90,14 @@
 		// Add it to the list
 		if (input != null) {
 			int index = list.getSelectionIndex();
-			if (index >= 0)
+			if (index >= 0) {
 				list.add(input, index + 1);
-			else
+				list.setSelection(index + 1);
+			}
+			else {
 				list.add(input, 0);
-			selectionChanged();
+				list.setSelection(0);
+			}
 		}
 	}
 
@@ -213,6 +216,7 @@
 	
 		// Create the buttons
 		createButtons(buttonGroup);
+		selectionChanged();
 	}
 
 	/* (non-Javadoc)
@@ -284,6 +288,7 @@
 			for (int i = 0; i < array.length; i++){
 				list.add(array[i]);
 			}
+			list.setSelection(0);
 		}
 	}
 
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/ChangeLog,v
retrieving revision 1.1
diff -u -r1.1 ChangeLog
--- ChangeLog	15 Sep 2003 20:44:24 -0000	1.1
+++ ChangeLog	16 Sep 2003 19:34:38 -0000
@@ -1,3 +1,24 @@
+2003-09-16 Sean Evoy
+	Patch contains a fix for bug 43017. Renamed the "addDeps" method to a 
+	more descriptive "addSourceDependencies". Added a flag when the 
+	inter-project dependencies are calculated so that clean and all are 
+	properly passed to the make invocation. Finally, I replaced the hard-coded
+	'make' with $(MAKE)
+	* src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java
+	
+	It also contains some more work on 41826, specifically on the logic to
+	implement a rebuild when the build settings change. The builder checks for 
+	a build model change whenever a build is requested and responds appropriately. 
+	The make targets (i.e. 'clean' and 'all') are also calculated differently now.
+	* src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
+	
+	The build model was modified to set a dirty flag when an option changes. I also
+	made a change to avoid an NPE when the build info was loaded.
+	* src/org/eclipse/cdt/managedbuilder/core/IManagedBuildInfo.java
+	* src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
+	* src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
+	
+
 2003-09-15 Sean Evoy
 	First submission of code to new project. Moved the managed builder 
 	source code out of the cdt.core project. This includes the code to 
Index: src/org/eclipse/cdt/managedbuilder/core/IManagedBuildInfo.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IManagedBuildInfo.java,v
retrieving revision 1.1
diff -u -r1.1 IManagedBuildInfo.java
--- src/org/eclipse/cdt/managedbuilder/core/IManagedBuildInfo.java	15 Sep 2003 20:44:24 -0000	1.1
+++ src/org/eclipse/cdt/managedbuilder/core/IManagedBuildInfo.java	16 Sep 2003 19:34:38 -0000
@@ -183,6 +183,20 @@
 	public String getToolForTarget(String extension);
 	
 	/**
+	 * Answers true if the build model has been changed by the user.
+	 * 
+	 * @return
+	 */
+	public boolean isDirty();
+	
+	/**
+	 * Set the dirty flag for the build model to the value of the argument.
+	 * 
+	 * @param isDirty
+	 */
+	public void setDirty(boolean isDirty);
+	
+	/**
 	 * Set the primary configuration for the receiver.
 	 * 
 	 * @param configuration The <code>IConfiguration</code> that will be used as the default
Index: src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java,v
retrieving revision 1.1
diff -u -r1.1 ManagedBuildManager.java
--- src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	15 Sep 2003 20:44:24 -0000	1.1
+++ src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	16 Sep 2003 19:34:38 -0000
@@ -207,20 +207,24 @@
 	 * @param option
 	 */
 	private static void setDirty(IConfiguration config, IOption option) {
-		// Don't bother unless this is something that effect the 
+		// Set the build info dirty so builder will rebuild
+		IResource resource = config.getOwner();
+		IManagedBuildInfo info = getBuildInfo(resource);
+		info.setDirty(true);
+
+		// Continue if change is something that effect the scanner
 		if (!(option.getValueType() == IOption.INCLUDE_PATH 
 			|| option.getValueType() == IOption.PREPROCESSOR_SYMBOLS)) {
 			return;
 		}
 		// Figure out if there is a listener for this change
-		IResource resource = config.getOwner();
 		List listeners = (List) getBuildModelListeners().get(resource);
 		if (listeners == null) {
 			return;
 		}
 		ListIterator iter = listeners.listIterator();
 		while (iter.hasNext()) {
-			((IScannerInfoChangeListener)iter.next()).changeNotification(resource, getScannerInfo(resource));
+			((IScannerInfoChangeListener)iter.next()).changeNotification(resource, (IScannerInfo)getBuildInfo(resource, false));
 		}
 	}
 
@@ -465,7 +469,7 @@
 		
 		if (buildInfo == null && create) {
 			try {
-				buildInfo = new ManagedBuildInfo();
+				buildInfo = new ManagedBuildInfo(resource);
 				resource.setSessionProperty(buildInfoProperty, buildInfo);
 			} catch (CoreException e) {
 				buildInfo = null;
@@ -491,21 +495,6 @@
 			buildModelListeners = new HashMap();
 		}
 		return buildModelListeners;
-	}
-
-	/**
-	 * Answers with an interface to the parse information that has been 
-	 * associated with the resource specified in the argument. 
-	 * 
-	 * @deprecated This method is not part of the registration interface. 
-	 * Clients of build information should now use getScannerInformation(IResource) 
-	 * for one-time information requests.
-	 * 
-	 * @param resource
-	 * @return
-	 */
-	public static IScannerInfo getScannerInfo(IResource resource) {
-		return (IScannerInfo) getBuildInfo(resource, false);
 	}
 
 	/* (non-Javadoc)
Index: src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java,v
retrieving revision 1.1
diff -u -r1.1 GeneratedMakefileBuilder.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java	15 Sep 2003 20:44:24 -0000	1.1
+++ src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java	16 Sep 2003 19:34:38 -0000
@@ -99,23 +99,27 @@
 			monitor.subTask(statusMsg);
 		}
 
-		if (kind == IncrementalProjectBuilder.FULL_BUILD) {
-			fullBuild(monitor);
+		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject());
+
+		if (kind == IncrementalProjectBuilder.FULL_BUILD || info.isDirty()) {
+			fullBuild(monitor, info);
 		}
 		else {
 			// Create a delta visitor to make sure we should be rebuilding
 			ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
 			IResourceDelta delta = getDelta(getProject());
 			if (delta == null) {
-				fullBuild(monitor);
+				fullBuild(monitor, info);
 			}
 			else {
 				delta.accept(visitor);
 				if (visitor.shouldBuild()) {
-					incrementalBuild(delta, monitor);
+					incrementalBuild(delta, info, monitor);
 				}
 			}
 		}
+		info.setDirty(false);
+		
 		// Checking to see if the user cancelled the build
 		checkCancel(monitor);
 
@@ -138,7 +142,7 @@
 	/**
 	 * @param monitor
 	 */
-	protected void fullBuild(IProgressMonitor monitor) throws CoreException {
+	protected void fullBuild(IProgressMonitor monitor, IManagedBuildInfo info) throws CoreException {
 		// Always need one of these bad boys
 		if (monitor == null) {
 			monitor = new NullProgressMonitor();
@@ -175,7 +179,6 @@
 		monitor.subTask(statusMsg);
 
 		// Regenerate the makefiles for this project
-		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject());
 		MakefileGenerator generator = new MakefileGenerator(currentProject, info, monitor);		
 		try {
 			generator.regenerateMakefiles();
@@ -194,20 +197,27 @@
 		monitor.worked(1);		
 	}
 
-	/**
-	 * @param makefilePath
-	 * @param info
+	/* (non-javadoc)
+	 * Answers an array of strings with the proper make targets
+	 * 
+	 * @param fullBuild
 	 * @return
 	 */
-	protected String[] getMakeTargets() {
+	protected String[] getMakeTargets(boolean fullBuild) {
 		List args = new ArrayList();
+		if (fullBuild) {
+			args.add("clean");
+		}
 		// Add each target
 		String sessionTarget = MakeUtil.getSessionTarget(getProject());
 		StringTokenizer tokens = new StringTokenizer(sessionTarget);
 		while (tokens.hasMoreTokens()) {
-			args.add(tokens.nextToken().trim());
+			String target = tokens.nextToken().trim();
+			if (!args.contains(target)) {
+				args.add(target);
+			}
 		}
-		if (args.isEmpty()) {
+		if (args.isEmpty() || !args.contains("all")) {
 			args.add("all");
 		}
 		return (String[])args.toArray(new String[args.size()]);
@@ -248,7 +258,7 @@
 	 * @param delta
 	 * @param monitor
 	 */
-	protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
+	protected void incrementalBuild(IResourceDelta delta, IManagedBuildInfo info, IProgressMonitor monitor) throws CoreException {
 		// Rebuild the resource tree in the delta
 		IProject currentProject = getProject();
 		String statusMsg = null;
@@ -261,7 +271,6 @@
 		monitor.subTask(statusMsg);
 		
 		// Ask the makefile generator to generate any makefiles needed to build delta
-		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(getProject());
 		MakefileGenerator generator = new MakefileGenerator(currentProject, info, monitor);
 		try {
 			generator.generateMakefiles(delta);
@@ -324,7 +333,7 @@
 		IPath workingDirectory = getWorkingDirectory().append(buildDir);
 
 		// Get the arguments to be passed to make from build model
-		String[] makeTargets = getMakeTargets();
+		String[] makeTargets = getMakeTargets(fullBuild);
 		
 		// Get a launcher for the make command
 		String errMsg = null;
Index: src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java,v
retrieving revision 1.1
diff -u -r1.1 MakefileGenerator.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java	15 Sep 2003 20:44:24 -0000	1.1
+++ src/org/eclipse/cdt/managedbuilder/internal/core/MakefileGenerator.java	16 Sep 2003 19:34:39 -0000
@@ -196,6 +196,11 @@
 		}
 	}	
 
+	/**
+	 * @param project
+	 * @param info
+	 * @param monitor
+	 */
 	public MakefileGenerator(IProject project, IManagedBuildInfo info, IProgressMonitor monitor) {
 		super();
 		// Save the project so we can get path and member information
@@ -209,11 +214,14 @@
 	}
 
 	/* (non-javadoc)
+	 * Calculates dependencies for all the source files in the argument. A source 
+	 * file can depend on any number of header files, so the dependencies have to 
+	 * be added to its dependency list. 
 	 * 
 	 * @param module
 	 * @return
 	 */
-	protected StringBuffer addDeps(IContainer module) throws CoreException {
+	protected StringBuffer addSourceDependencies(IContainer module) throws CoreException {
 		// Calculate the new directory relative to the build output
 		IPath moduleRelativePath = module.getProjectRelativePath();
 		String relativePath = moduleRelativePath.toString();
@@ -372,7 +380,7 @@
 	 * Answers a <code>StrinBuffer</code> containing all of the required targets to
 	 * properly build the project.
 	 */
-	protected StringBuffer addTargets() {
+	protected StringBuffer addTargets(boolean rebuild) {
 		StringBuffer buffer = new StringBuffer();
 
 		// Get the target and it's extension
@@ -383,16 +391,16 @@
 		/*
 		 * Write out the target rule as:
 		 * <prefix><target>.<extension>: $(CC_SRCS:$(ROOT)/%.cpp=%.o) $(C_SRCS:$(ROOT)/%.c=%.o)
-		 * 		<cd <Proj_Dep_1/build_dir>; make all> 
-		 * 		<cd <Proj_Dep_.../build_dir>; make all> 
-		 * 		<cd <Proj_Dep_n/build_dir>; make all> 
+		 * 		<cd <Proj_Dep_1/build_dir>; $(MAKE) all> 
+		 * 		<cd <Proj_Dep_.../build_dir>; $(MAKE) all> 
+		 * 		<cd <Proj_Dep_n/build_dir>; $(MAKE) all> 
 		 * 		$(BUILD_TOOL) $(FLAGS) $(OUTPUT_FLAG) $@ $^ $(LIB_DEPS)
 		 */
 		String cmd = info.getToolForTarget(extension);
 		String flags = info.getFlagsForTarget(extension);
 		String outflag = info.getOutputFlag(extension);
 		String outputPrefix = info.getOutputPrefix(extension);
-
+		String targets = rebuild ? "clean all" : "all";
 		buffer.append(outputPrefix + target + COLON + WHITESPACE + "$(CC_SRCS:$(ROOT)/%.cpp=%.o) $(C_SRCS:$(ROOT)/%.c=%.o)" + NEWLINE);
 		IProject[] deps;
 		try {
@@ -404,11 +412,11 @@
 					IManagedBuildInfo depInfo = ManagedBuildManager.getBuildInfo(dep);
 					buildDir += SEPARATOR + depInfo.getConfigurationName();
 				}
-				buffer.append(TAB + "cd" + WHITESPACE + buildDir + SEMI_COLON + WHITESPACE + "make all" + NEWLINE);
+				buffer.append(TAB + "cd" + WHITESPACE + buildDir + SEMI_COLON + WHITESPACE + "$(MAKE) " + targets + NEWLINE);
 			}
 		} catch (CoreException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+			// There are 2 exceptions; the project does not exist or it is not open
+			// and neither conditions apply if we are building for it ....
 		}
 
 		buffer.append(TAB + cmd + WHITESPACE + flags + WHITESPACE + outflag + WHITESPACE + "$@" + WHITESPACE + "$^");
@@ -420,7 +428,7 @@
 		buffer.append(NEWLINE);
 		buffer.append(NEWLINE);
 
-		// TODO Generate 'all' for now but determine the real rules from UI
+		// We only have one target, 'all'
 		buffer.append("all: " + outputPrefix + target + NEWLINE);
 		buffer.append(NEWLINE);
 		
@@ -587,7 +595,7 @@
 		topBuildDir = createDirectory(info.getConfigurationName());
 		IPath makefilePath = topBuildDir.addTrailingSeparator().append(MAKEFILE_NAME);
 		IFile makefileHandle = createFile(makefilePath);
-		populateTopMakefile(makefileHandle);
+		populateTopMakefile(makefileHandle, false);
 		checkCancel();
 		
 		// Regenerate any fragments for modified directories
@@ -725,10 +733,9 @@
 	 * Create the entire contents of the makefile.
 	 * 
 	 * @param fileHandle The file to place the contents in.
-	 * @param info
-	 * @param monitor
+	 * @param rebuild FLag signalling that the user is doing a full rebuild
 	 */
-	protected void populateTopMakefile(IFile fileHandle) {
+	protected void populateTopMakefile(IFile fileHandle, boolean rebuild) {
 		StringBuffer buffer = new StringBuffer();
 		
 		// Add the macro definitions
@@ -738,7 +745,7 @@
 		buffer.append(addModules()); 
 
 		// Add targets
-		buffer.append(addTargets());
+		buffer.append(addTargets(rebuild));
 
 		// Save the file
 		try {
@@ -772,7 +779,7 @@
 		// Create a module dep file
 		IFile modDepfile = createFile(moduleOutputDir.addTrailingSeparator().append(DEPFILE_NAME));
 		StringBuffer depBuf = new StringBuffer();
-		depBuf.append(addDeps(module));
+		depBuf.append(addSourceDependencies(module));
 
 		// Save the files
 		Util.save(makeBuf, modMakefile);
@@ -804,7 +811,7 @@
 		IFile makefileHandle = createFile(makefilePath);
 		
 		// Populate the makefile
-		populateTopMakefile(makefileHandle);
+		populateTopMakefile(makefileHandle, true);
 		checkCancel();
 		
 		// Now populate the module makefiles
Index: src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java,v
retrieving revision 1.1
diff -u -r1.1 ManagedBuildInfo.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java	15 Sep 2003 20:44:24 -0000	1.1
+++ src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java	16 Sep 2003 19:34:39 -0000
@@ -33,20 +33,23 @@
 
 public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
 
+	private boolean isDirty;
 	private IResource owner;
 	private Map targetMap;
 	private List targets;
 	private Map defaultConfigurations;
 	private ITarget defaultTarget;
 	
-	public ManagedBuildInfo() {
+	public ManagedBuildInfo(IResource owner) {
 		targetMap = new HashMap();
 		targets = new ArrayList();
 		defaultConfigurations = new HashMap();
+		this.owner = owner;
 	}
 	
 	public ManagedBuildInfo(IResource owner, Element element) {
-		this();
+		this(owner);
+		
 		// The id of the default configuration
 		String defaultTargetId = null;
 		List configIds = new ArrayList();
@@ -460,6 +463,20 @@
 		return null;
 	}
 
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#isDirty()
+	 */
+	public boolean isDirty() {
+		return isDirty;
+	}
+
+	/**
+	 * Write the contents of the build model to the persistent store specified in the 
+	 * argument.
+	 * 
+	 * @param doc
+	 * @param element
+	 */
 	public void serialize(Document doc, Element element) {
 		// Write out each target and their default config
 		for (int i = 0; i < targets.size(); ++i) {
@@ -500,6 +517,13 @@
 			return;
 		}
 		defaultTarget = target;		
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#setDirty(boolean)
+	 */
+	public void setDirty(boolean isDirty) {
+		this.isDirty = isDirty;
 	}
 
 }
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.100
diff -u -r1.100 ChangeLog
--- ChangeLog	16 Sep 2003 17:31:43 -0000	1.100
+++ ChangeLog	16 Sep 2003 19:34:11 -0000
@@ -1,3 +1,7 @@
+2003-09-16 Sean Evoy
+	Added test to see if the managed build info dirty flag is properly set after a change.
+	* build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java
+
 2003-09-17 Bogdan Gheorghe
 	Added asserts to all index lookups in IndexManagerTests
 	Fixed testAddNewFileToIndex
Index: build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java,v
retrieving revision 1.4
diff -u -r1.4 ManagedBuildTests.java
--- build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java	15 Sep 2003 20:44:31 -0000	1.4
+++ build/org/eclipse/cdt/core/build/managed/tests/ManagedBuildTests.java	16 Sep 2003 19:34:12 -0000
@@ -208,7 +208,12 @@
 			}
 		}
 		assertNotNull(symbolOpt);
+		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+		assertFalse(info.isDirty());
 		ManagedBuildManager.setOption(defaultConfig, symbolOpt, expectedSymbols);
+		assertTrue(info.isDirty());
+		info.setDirty(false);
+		assertFalse(info.isDirty());
 	}
 	
 	/**

Back to the top