Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] [PATCH] Custom Build Root & Clean Bug

Hello,

CDT developers are busy with Europa, so no response to my query is understandable. However, I took a look and made some changes, not too many due to pretty good design, it was localized. Now I can use this to deposit *.o and resulting artifacts into a custom out-of-project directory (through a linked folder and variables to specify root for common projects), which is nice.

I think this feature should be included in CDT, it makes sense for many reasons.

Please consider it, and the patch should give an idea of how much work it took.

However, although the patch is against CDT-4.0.0RC4, I uncovered what look like a bug in the pristine branch.

After a new project is created, CDT creates the Debug/Release directory and builds it ok. However, if either of these directories is removed without CDT knowing about it ( e.g., clean not controlled by eclipse) and a rebuild is attempted, CDT chokes with this:

---
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\Test4.o ..\src\Test4.cpp
Internal Builder: Exec error:The directory name is invalid.
 
Build error occurred, build is stopped
Time consumed: 16  ms.
---

Doing a clean build, replaces the removed directory and builds fine. Perhaps CDT should detect that directory is gone, much like it detects if a file is modified, and issue a clean build.

Thank you.
diff -r 690ee17a4f9d -r 0697435f78f8 org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
--- a/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	Sat Jun 23 12:49:18 2007 -0400
+++ b/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java	Tue Jun 26 14:28:46 2007 -0400
@@ -3939,40 +3939,81 @@ public class ManagedBuildManager extends
 		return des;
 	}
 	
-	public static IPath getBuildFullPath(IConfiguration cfg, IBuilder builder){
-		IProject project = cfg.getOwner().getProject();
-//		String path = builder.getBuildPath();
-		
-		IPath buildDirectory = builder.getBuildLocation();
-		IPath fullPath = null;
-		if (buildDirectory != null && !buildDirectory.isEmpty()) {
-			IResource res = project.getParent().findMember(buildDirectory);
-			if (res instanceof IContainer && res.exists()) {
-				fullPath = res.getFullPath();
-			} else {
-				IContainer crs[] = ((IWorkspaceRoot)project.getParent()).findContainersForLocation(buildDirectory);
-				if(crs.length != 0){
-					String projName = project.getName();
-					for(int i = 0; i < crs.length; i++){
-						IPath path = crs[i].getFullPath();
-						if(path.segmentCount() != 0 && path.segment(0).equals(projName)){
-							fullPath = path;
-							break;
-						}
-					}
-					
-					if(fullPath == null){
-						fullPath = crs[0].getFullPath();
-					}
-				}
-			}
-		} else {
-			fullPath = cfg.getOwner().getProject().getFullPath();
-			if(builder.isManagedBuildOn())
-				fullPath = fullPath.append(cfg.getName());
-		}
-		
-		return fullPath;
+	public static IPath getBuildFullPath(final IConfiguration c) {
+		return getBuildFullPath(c, c.getBuilder());
+	}
+	
+	public static IPath getBuildFullPath(final IConfiguration c, final IBuilder b) {
+		final IResource o = c.getOwner();
+		if(o == null)
+			return Path.EMPTY;
+
+		IPath r = null;
+		final IProject p = o.getProject();
+		final IPath l = b.getBuildLocation();
+		if(l != null && !l.isEmpty()) {
+			r = fullPathForLocation(p, l);
+		}
+		else {
+			r = p.getFullPath();
+		}
+		if(b.isManagedBuildOn()) {
+			r = fix(c, r);
+		}
+		return r;
+	}
+	
+	public static IPath getBuildLocation(final IConfiguration c) {
+		return getBuildLocation(c, c.getBuilder());
+	}
+	
+	public static IPath getBuildLocation(final IConfiguration c, final IBuilder b) {
+		final IResource o = c.getOwner();
+		if(o == null)
+			return Path.EMPTY;
+
+		IPath r = b.getBuildLocation();
+		if(r == null || r.isEmpty()) {
+			r = o.getProject().getLocation();
+		}
+		if(b.isManagedBuildOn()) {
+			r = fix(c, r);
+		}
+		return r;
+	}
+	
+	private static IPath fix(final IConfiguration c, final IPath p) {
+		final String n = c.getName();
+		final int i = p.segmentCount();
+		if(i > 0 && !n.equals(p.segment(i - 1))) {
+			return p.append(n);
+		}
+		return p;
+	}
+	
+	private static IPath fullPathForLocation(final IProject p, final IPath l) {
+		final IWorkspaceRoot w = (IWorkspaceRoot)p.getParent();
+		final IResource r = w.findMember(l);
+		if(r instanceof IContainer && r.exists())
+			return r.getFullPath();
+
+		final IContainer[] c = w.findContainersForLocation(l);
+		if(c.length == 0)
+			return null;
+
+		IPath o = null;
+		final String n = p.getName();
+		for(int i = 0; i < c.length; i++) {
+			final IPath path = c[i].getFullPath();
+			if(path.segmentCount() != 0 && n.equals(path.segment(0))) {
+				o = path;
+				break;
+			}
+		}
+		if(o == null) {
+			o = c[0].getFullPath();
+		}
+		return o;
 	}
 	
 	public static String locationToFullPath(String path){
@@ -4002,25 +4043,6 @@ public class ManagedBuildManager extends
 	public static String fullPathToLocation(String path){
 		StringBuffer buf = new StringBuffer();
 		return buf.append("${").append("workspace_loc:").append(path).append("}").toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-	}
-
-	public static IPath getBuildLocation(IConfiguration cfg, IBuilder builder) {
-		if(cfg.getOwner() == null)
-			return Path.EMPTY;
-		
-		IProject project = cfg.getOwner().getProject(); 
-		IPath buildDirectory = builder.getBuildLocation();
-		if (buildDirectory != null && !buildDirectory.isEmpty()) {
-			IResource res = project.getParent().findMember(buildDirectory);
-			if (res instanceof IContainer && res.exists()) {
-				buildDirectory = res.getLocation();
-			}
-		} else {
-			buildDirectory = project.getLocation();
-			if(builder.isManagedBuildOn())
-				buildDirectory = buildDirectory.append(cfg.getName());
-		}
-		return buildDirectory;
 	}
 	
 	public static IBuilder[] createBuilders(IProject project, Map args){
diff -r 690ee17a4f9d -r 0697435f78f8 org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java
--- a/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java	Sat Jun 23 12:49:18 2007 -0400
+++ b/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/BuildDescription.java	Tue Jun 26 14:28:46 2007 -0400
@@ -110,6 +110,7 @@ public class BuildDescription implements
 	private IProject fProject;
 	private IManagedBuildInfo fInfo;
 	private IPath fTopBuildDirFullPath;
+	private IPath fTopBuildDirLocation;
 	private IPath fGeneratedPaths[];
 	private int fFlags;
 
@@ -990,34 +991,49 @@ public class BuildDescription implements
 		return fMakeGen;
 	}
 	
-	private IPath getTopBuildDirFullPath(){
-		if(fTopBuildDirFullPath == null)
-			fTopBuildDirFullPath = fProject.getFullPath().append(getMakeGenInitialized().getBuildWorkingDir()).addTrailingSeparator();
+	private IPath getTopBuildDirFullPath() {
+		if(fTopBuildDirFullPath == null) {
+			if(!fCfg.isInternalBuilderEnabled() && fCfg.isManagedBuildOn()) {
+				getMakeGenInitialized();
+			}
+			fTopBuildDirFullPath = ManagedBuildManager.getBuildFullPath(fCfg).addTrailingSeparator();
+		}
 		return fTopBuildDirFullPath;
 	}
 	
-	private IPath getTopBuildDirLocation(){
-		return fProject.getLocation().append(getTopBuildDirFullPath().removeFirstSegments(1));
+	private IPath getTopBuildDirLocation() {
+		if(fTopBuildDirLocation == null) {
+			fTopBuildDirLocation = ManagedBuildManager.getBuildLocation(fCfg);
+		}
+		return fTopBuildDirLocation;
+	}
+	
+	private IPath fix(final IPath p) {
+		final IPath f = getTopBuildDirFullPath();
+		final IPath l = getTopBuildDirLocation();
+		return l.append(p.removeFirstSegments(f.segmentCount()));
 	}
 	
 	private BuildResource[] addOutputs(IPath paths[], BuildIOType buildArg, IPath outDirPath){
 		if(paths != null){
 			List list = new ArrayList();
+			final IPath l = getTopBuildDirLocation();
 			for(int k = 0; k < paths.length; k++){
 				IPath outFullPath = paths[k];
 				IPath outLocation;
-				
-				
-				if(outFullPath.isAbsolute()){
+
+				if(outFullPath.isAbsolute()) {
 					outLocation = outFullPath;
-					if(fProject.getLocation().isPrefixOf(outLocation))
-						outFullPath = fProject.getFullPath().append(outLocation.removeFirstSegments(fProject.getLocation().segmentCount()));
-					else
+					if(l.isPrefixOf(outLocation)) {
+						outFullPath = fProject.getFullPath().append(outLocation.removeFirstSegments(l.segmentCount()));
+					}
+					else {
 						outFullPath = null;
+					}
 				} else {
-					if (outFullPath.segmentCount() == 1) {
-						outFullPath = outDirPath.append(outFullPath); 
-						outLocation = fProject.getLocation().append(outFullPath.removeFirstSegments(1));
+					if(outFullPath.segmentCount() == 1) {
+						outFullPath = outDirPath.append(outFullPath);
+						outLocation = fix(outFullPath);
 					} else {
 						outLocation = getTopBuildDirLocation().append(outFullPath);
 						outFullPath = getTopBuildDirFullPath().append(outFullPath);
@@ -1327,7 +1343,7 @@ public class BuildDescription implements
 				String outExt = tool.getOutputExtension(inExt);
 				outFullPath = resolvePercent(outFullPath.addFileExtension(outExt), buildRc.getLocation());
 				
-				outLocation = fProject.getLocation().append(outFullPath.removeFirstSegments(1));
+				outLocation = fix(outFullPath);
 				
 				BuildIOType buildArg = action.createIOType(false, true, null);
 
@@ -1415,8 +1431,9 @@ public class BuildDescription implements
 	
 	
 	private IPath locationToRel(IPath location){
-		if(fProject.getLocation().isPrefixOf(location))
-			return location.removeFirstSegments(fProject.getLocation().segmentCount()).setDevice(null);
+		final IPath l = getTopBuildDirLocation();
+		if(l.isPrefixOf(location))
+			return location.removeFirstSegments(l.segmentCount()).setDevice(null);
 		//TODO
 		return location;
 	}
@@ -1868,8 +1885,9 @@ public class BuildDescription implements
 				}
 				if(inFullPath == null && files.length > 0)
 					inFullPath = files[0].getFullPath();
-				if(inFullPath == null && fProject.getLocation().isPrefixOf(inLocation)){
-					inFullPath = fProject.getFullPath().append(inLocation.removeFirstSegments(fProject.getLocation().segmentCount())); 
+				final IPath l = getTopBuildDirLocation();
+				if(inFullPath == null && l.isPrefixOf(inLocation)){
+					inFullPath = fProject.getFullPath().append(inLocation.removeFirstSegments(l.segmentCount())); 
 				}
 			} else {
 				IPath projPath = inFullPath;
@@ -1900,7 +1918,7 @@ public class BuildDescription implements
 	}
 
 	public BuildResource createResource(IPath projPath){
-		return createResource(fProject.getLocation().append(projPath),fProject.getFullPath().append(projPath));
+		return createResource(getTopBuildDirLocation().append(projPath), fProject.getFullPath().append(projPath));
 	}
 	
 	public BuildResource createResource(IResource rc){
diff -r 690ee17a4f9d -r 0697435f78f8 org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Builder.java
--- a/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Builder.java	Sat Jun 23 12:49:18 2007 -0400
+++ b/org.eclipse.cdt-build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Builder.java	Tue Jun 26 14:28:46 2007 -0400
@@ -1715,9 +1715,6 @@ public class Builder extends BuildObject
 	}
 	
 	public String getBuildPath(){
-		if(isManagedBuildOn())
-			return getDefaultBuildPath();
-		
 		String path = getBuildPathAttribute();
 		if(path == null){
 			path = getDefaultBuildPath();
@@ -2584,9 +2581,6 @@ public class Builder extends BuildObject
 	}
 	
 	public ICOutputEntry[] getOutputEntries(){
-		if(isManagedBuildOn()){
-			return getDefaultOutputSettings(true);
-		}
 		ICOutputEntry[] entries = getOutputEntrySettings();
 		if(entries == null || entries.length == 0){
 			entries = getDefaultOutputSettings(false);

Back to the top