Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Fix for CDT MBS bugzilla #80185

Title: Fix for CDT MBS bugzilla #80185

<<mbct.txt>> <<mbc.txt>>
In the attachments, you will find a patch for bugzilla #80185. It handles the case where a project where all sources are marked as "excluded from build" gracefully. It also generally improves managed

build "behavior" with projects which have no sources or no build able sources, in general.
I have added a regression test as well.

Bob Monteleone
Intel Corporation
Nashua Software Lab     
603-886-7665

Index: suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java,v
retrieving revision 1.4
diff -u -r1.4 ManagedBuildTestHelper.java
--- suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java	20 May 2005 18:31:37 -0000	1.4
+++ suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java	26 May 2005 21:44:50 -0000
@@ -242,6 +242,27 @@
 		return true;
 	}
 
+	static public boolean verifyFilesDoNotExist(IProject project, IPath testDir, IPath[] files) {
+		try {
+			project.refreshLocal(IResource.DEPTH_INFINITE, null);
+		} catch (Exception e) {
+			Assert.fail("File " + files[0].lastSegment() + " - project refresh failed.");
+		}
+		for (int i=0; i<files.length; i++) {
+			IPath testFile = testDir.append(files[i]);
+			IPath fullPath = project.getLocation().append(testFile);
+			try {
+				if (fullPath.toFile().exists()) {
+					Assert.fail("File " + testFile.lastSegment() + " unexpectedly found.");
+					return false;
+				}					
+			} catch (Exception e) {
+				Assert.fail("File " + fullPath.toString() + " could not be referenced.");
+			}
+		}
+		return true;
+	}
+
 	static public StringBuffer readContentsStripLineEnds(IProject project, IPath path) {
 		StringBuffer buff = new StringBuffer();
 		IPath fullPath = project.getLocation().append(path);
Index: tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java,v
retrieving revision 1.1
diff -u -r1.1 ManagedProject30MakefileTests.java
--- tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java	23 May 2005 23:56:32 -0000	1.1
+++ tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java	26 May 2005 21:44:50 -0000
@@ -25,6 +25,8 @@
 
 import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
 import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
 import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
 import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
 import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
@@ -57,6 +59,7 @@
 		//suite.addTest(new ManagedProject30MakefileTests("test30LinkedFolder"));
 		suite.addTest(new ManagedProject30MakefileTests("test30CopyandDeploy"));
 		suite.addTest(new ManagedProject30MakefileTests("test30DeleteFile"));
+		suite.addTest(new ManagedProject30MakefileTests("test30NoFilesToBuild"));
 		suite.addTest(new ManagedProject30MakefileTests("test30_1"));
 		suite.addTest(new ManagedProject30MakefileTests("test30_2"));
 		
@@ -132,12 +135,12 @@
 		return projects;
 	}
 		
-	private void buildProjects(IProject projects[], IPath[] files) {	
+	private void buildProjectsWorker(IProject projects[], IPath[] files, boolean compareBenchmark) {	
 		if(projects == null || projects.length == 0)
 			return;
 				
 		boolean succeeded = true;
-		for(int i = 0; i < projects.length; i++){
+		for (int i = 0; i < projects.length; i++){
 			IProject curProject = projects[i];
 			
 			IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(curProject);
@@ -146,7 +149,7 @@
 			boolean isCompatible = UpdateManagedProjectManager.isCompatibleProject(info);
 			assertTrue(isCompatible);
 			
-			if(isCompatible){
+			if (isCompatible){
 				// Build the project in order to generate the makefiles 
 				try{
 					curProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD,null);
@@ -163,18 +166,31 @@
 					if (i == 0) {
 						String configName = info.getDefaultConfiguration().getName();
 						IPath buildDir = Path.fromOSString(configName);
-						succeeded = ManagedBuildTestHelper.compareBenchmarks(curProject, buildDir, files);
+						if (compareBenchmark)
+						    succeeded = ManagedBuildTestHelper.compareBenchmarks(curProject, buildDir, files);
+						else
+							succeeded = ManagedBuildTestHelper.verifyFilesDoNotExist(curProject, buildDir, files);
 					}
 				}
 			}
 		}
 		
 		if (succeeded) {	//  Otherwise leave the projects around for comparison
-			for(int i = 0; i < projects.length; i++)
+			for (int i = 0; i < projects.length; i++)
 				ManagedBuildTestHelper.removeProject(projects[i].getName());
 		}
 	}
 
+	// Build projects and compare benchmarks
+	private void buildProjects(IProject projects[], IPath[] files) {
+		buildProjectsWorker(projects, files, true);
+	}
+	
+	// Build projects but don't compare benchmarks because there should be not build files generated
+	private void buildDegenerativeProjects(IProject projects[], IPath[] files) {	
+		buildProjectsWorker(projects, files, false);
+	}
+		
 	private void createPathVariable(IPath tmpDir) {
 		IWorkspace workspace = ResourcesPlugin.getWorkspace();
 		workspace = ResourcesPlugin.getWorkspace();
@@ -348,10 +364,31 @@
 		IResource[] fileResource = (IResource[])resourceList.toArray(new IResource[resourceList.size()]);
 		try {
 		    workspace.delete(fileResource, false, null);
-		}  catch (Exception e) {fail("could not delete file in project " + project.getName());}
-		try {
-			buildProjects(projects, makefiles);
-		} finally {};
+		} catch (Exception e) { 
+		    fail("could not delete file in project " + project.getName());
+		}
+		buildProjects(projects, makefiles);
+	}
+
+	/* (non-Javadoc)
+	 * tests 3.0 managed build system with a project which has only a single source file that is marked as 
+	 * "excluded from build" to see that this degenerative case is handled gracefully
+	 */
+	public void test30NoFilesToBuild(){
+		IPath[] makefiles = {
+				 Path.fromOSString("makefile"), 
+				 Path.fromOSString("objects.mk"), 
+				 Path.fromOSString("subdir.mk"),
+				 Path.fromOSString("sources.mk")}; 		
+
+		IProject[] projects = createProjects("noFilesToBuild", null, null, true);
+		IProject project = projects[0];
+		IFile projfile = project.getFile("filetobeexcluded.cxx");
+		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
+		IConfiguration config = info.getDefaultConfiguration();
+		IResourceConfiguration rconfig = config.createResourceConfiguration(projfile);
+		rconfig.setExclude(true);
+		buildDegenerativeProjects(projects, makefiles);			
 	}
 
 	/* (non-Javadoc)
Index: src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java,v
retrieving revision 1.41
diff -u -r1.41 GeneratedMakefileBuilder.java
--- src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java	23 May 2005 20:30:12 -0000	1.41
+++ src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java	26 May 2005 21:43:23 -0000
@@ -264,6 +264,46 @@
 		}
 	}
 
+	/* (non-javadoc)
+	 * Emits a message to the console indicating that there were no source files to build
+	 * @param buildType
+	 * @param status
+	 * @param configName
+	 */
+	private void emitNoSourceMessage(int buildType, IStatus status, String configName) throws CoreException {
+		try {
+			StringBuffer buf = new StringBuffer();
+			IConsole console = CCorePlugin.getDefault().getConsole();
+			console.start(getProject());
+			ConsoleOutputStream consoleOutStream = console.getOutputStream();
+			// Report a successful clean
+			String[] consoleHeader = new String[3];
+			if (buildType == FULL_BUILD) {
+			    consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_FULL);
+			} else if (buildType == INCREMENTAL_BUILD) {
+				consoleHeader[0] = ManagedMakeMessages.getResourceString(TYPE_INC);
+			} else {
+				consoleHeader[0] = new String();
+				outputError(getProject().getName(), "The given build type is not supported in this context");	//$NON-NLS-1$
+			}			
+			consoleHeader[1] = configName;
+			consoleHeader[2] = getProject().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$
+			buf.append(System.getProperty("line.separator", "\n"));	//$NON-NLS-1$	//$NON-NLS-2$
+			buf.append(status.getMessage());
+			buf.append(System.getProperty("line.separator", "\n"));  //$NON-NLS-1$//$NON-NLS-2$
+			consoleOutStream.write(buf.toString().getBytes());
+			consoleOutStream.flush();
+			consoleOutStream.close();
+		} catch (CoreException e) {
+			// Throw the exception back to the builder
+			throw e;
+		} catch (IOException io) {	//  Ignore console failures...
+		}		
+	}
+
 	/* (non-Javadoc)
 	 * @see org.eclipse.core.internal.events.InternalBuilder#build(int, java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
 	 */
@@ -395,8 +435,9 @@
 	}
 	
 	/* (non-Javadoc)
-	 * @param monitor
 	 * @param info
+	 * @param generator
+	 * @param monitor
 	 */
 	protected void cleanBuild(IManagedBuildInfo info, IManagedBuilderMakefileGenerator generator, IProgressMonitor monitor) {
 		// Make sure that there is a top level directory and a set of makefiles
@@ -418,6 +459,8 @@
 	}
 
 	/* (non-Javadoc)
+	 * @param info
+	 * @param generator
 	 * @param monitor
 	 */
 	protected void fullBuild(IManagedBuildInfo info, IManagedBuilderMakefileGenerator generator, IProgressMonitor monitor) throws CoreException {
@@ -439,6 +482,15 @@
 				// One possibility is that there is nothing to build
 				IStatus status = kids[index]; 
 				if (status.getCode() == IManagedBuilderMakefileGenerator.NO_SOURCE_FOLDERS) {
+					// Inform the user, via the console, that there is nothing to build
+					// either because there are no buildable sources files or all potentially
+					// buildable files have been excluded from build
+					try { 
+						emitNoSourceMessage(FULL_BUILD, status, info.getConfigurationName());
+					} catch (CoreException e) {
+						// Throw the exception back to the builder
+					    throw e;
+					}					
 					// Dude, we're done
 					return;
 				} else {
@@ -550,6 +602,15 @@
 				// One possibility is that there is nothing to build
 				IStatus status = kids[index]; 
 				if (status.getCode() == IManagedBuilderMakefileGenerator.NO_SOURCE_FOLDERS) {
+					// Inform the user, via the console, that there is nothing to build
+					// either because there are no buildable sources files or all potentially
+					// buildable files have been excluded from build
+					try { 
+						emitNoSourceMessage(INCREMENTAL_BUILD, status, info.getConfigurationName());
+					} catch (CoreException e) {
+						// Throw the exception back to the builder
+					    throw e;
+					}					
 					// Dude, we're done
 					return;
 				} else {
@@ -691,7 +752,7 @@
 						//resolve the build macros in environment variables
 						try{
 							envList.add(variables[i].getName() + "=" + macroProvier.resolveValue(variables[i].getValue(),""," ",IBuildMacroProvider.CONTEXT_CONFIGURATION,cfg));	//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-						}catch(BuildMacroException e){
+						} catch(BuildMacroException e) {
 						envList.add(variables[i].getName() + "=" + variables[i].getValue());	//$NON-NLS-1$
 					}
 					}
Index: src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java,v
retrieving revision 1.40
diff -u -r1.40 GnuMakefileGenerator.java
--- src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java	26 May 2005 21:17:34 -0000	1.40
+++ src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java	26 May 2005 21:43:25 -0000
@@ -204,12 +204,17 @@
 			if (proxy.getType() == IResource.FILE) {
 				// Check extension to see if build model should build this file
 				IResource resource = proxy.requestResource();
-				String ext = resource.getFileExtension();
+				String ext = resource.getFileExtension();				
 				if (info.buildsFileType(ext)) {
+					// If this file resource is a generated resource, then it is uninteresting
 					if (!generator.isGeneratedResource(resource)) {
-						generator.appendBuildSubdirectory(resource);
+						// If this file resource is excluded from build, then it is uninteresting
+						IResourceConfiguration resConfig = config.getResourceConfiguration(resource.getFullPath().toString());
+						if ((resConfig == null) || (!(resConfig.isExcluded()))) {						
+						    generator.appendBuildSubdirectory(resource);
+						}
 					}
-				}
+				}				
 				return false;
 			}
 
@@ -432,13 +437,13 @@
 			status = new MultiStatus(
 					ManagedBuilderCorePlugin.getUniqueIdentifier(),
 					IStatus.INFO,
-					info,
+					new String(),
 					null);
 			status.add(new Status (
 					IStatus.INFO,
 					ManagedBuilderCorePlugin.getUniqueIdentifier(),
 					NO_SOURCE_FOLDERS,
-					new String(),
+					info,
 					null));
 			return status;
 		} 
@@ -632,20 +637,20 @@
 		// See if the user has cancelled the build
 		checkCancel();
 
-		// Populate the makefile if any source files have been found in the project
+		// Populate the makefile if any buildable source files have been found in the project
 		if (getSubdirList().isEmpty()) {
 			String info = ManagedMakeMessages.getFormattedString("MakefileGenerator.warning.no.source", project.getName()); //$NON-NLS-1$ 
 			updateMonitor(info);	
 			status = new MultiStatus(
 					ManagedBuilderCorePlugin.getUniqueIdentifier(),
 					IStatus.INFO,
-					info,
+					new String(),
 					null);
 			status.add(new Status (
 					IStatus.INFO,
 					ManagedBuilderCorePlugin.getUniqueIdentifier(),
 					NO_SOURCE_FOLDERS,
-					new String(),
+					info,
 					null));
 			return status;
 		} 

Back to the top