Bug 70491

Summary: Unable to build source files in a linked directory
Product: [Tools] CDT Reporter: Hurai Rody <hurai_r>
Component: cdt-buildAssignee: Sean Evoy <sevoy>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: cdtdoug, recoskie
Version: 2.0   
Target Milestone: 2.0.1   
Hardware: All   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
proposed patch
cdtdoug: iplog+
NPE in generated makefile builder none

Description Hurai Rody CLA 2004-07-20 17:34:03 EDT
If you create a sample project with a single directory linked to an existing 
directory containing source files, it will not build.  The makefile does not 
realize that the directory is linked, so therefore the GnuMakefileGenerator 
attempts to locate the resources using relative paths.  

The fix is actually very simple.  In the addRule(...) method of the 
GnuMakefileGenerator.java file, you just need to see if the resource's actual 
location is contained within the project's actual location.  Here is a snippet 
from my code:

String buildFlags = null;
		String resourceName = getFileName(resource);
		String inputExtension = resource.getFileExtension();
		IPath resourceLocation = resource.getLocation();
		String cmd = info.getToolForSource(inputExtension);
		String outputExtension = info.getOutputExtension
(inputExtension);
		String outflag = null;
		String outputPrefix = null;
		String projectLocation = project.getLocation().toString();

		String resourcePath = null;		
		String buildRule = null;
		/**
		 * We need to check if the current resource is LINKED, because 
		 * the default CDT doesn't handle this properly.  If it IS 
linked,
		 * then we must get the actual location of the resource, rather
		 * than the relative path.
		 */
		if(!resourceLocation.toString().startsWith(projectLocation)) {
			// it IS linked, so use the actual location
			resourcePath = resourceLocation.toString();
			buildRule = relativePath + resourceName + DOT + 
outputExtension
			+ COLON + WHITESPACE + resourcePath;
		}
		else {
			// use the relative path
			resourcePath = relativePath;
			buildRule = relativePath + resourceName + DOT + 
outputExtension
			+ COLON + WHITESPACE + ROOT + SEPARATOR + relativePath
			+ resourceName + DOT + inputExtension;
		}

Thanks!
Comment 1 Sean Evoy CLA 2004-07-21 14:17:42 EDT
Will test the fix and if it works I will add it to the default makefile 
generator
Comment 2 Chris Recoskie CLA 2004-08-12 15:02:18 EDT
Created attachment 13924 [details]
proposed patch

This patch is largely the same as the one posted by the submitter, however, the
submitter's patch did not take into account the relative path of the object
file in the project.  Currently there is a restriction (for unknown reasons)
that linked files can only be in the project root directory, but I am hoping
that this restriction will disappear, and hence it would be good to allow for
this case.
Comment 3 Sean Evoy CLA 2004-08-16 13:52:36 EDT
Applied the patch to 2.0.1 and head. The switch to absolute paths is probably 
the only way to go until we have a strategy in place to define and use path 
variables. There are two usability probalems that will not be addressed with 
thispatch. Despite the fact that the resource "looks" like it is part of the 
worksapce, the user will have to set the proper includes path in the build 
settings or the compielr will failt o find it. Second, error markers are not 
cleared if the linked resource belongs to another, open project in the 
workspace.
Comment 4 Tanya Wolff CLA 2004-09-08 12:33:25 EDT
Created attachment 14445 [details]
NPE in generated makefile builder

These log entries are added when I build a project containing a linked
directory to a mixed source/object directory.
Comment 5 Tanya Wolff CLA 2004-09-08 14:19:48 EDT
Found out that the NPEs would also happen if the object files were in a
non-linked directory as well, so now we can mark this fix for linked dir as
verified. I verified in CDT 2.0.1 build 200408271356.
Comment 6 Kleo Hapitas CLA 2004-09-14 21:29:41 EDT
Marking it verified as per Tany's comment