Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 208685

Summary: Error parsers easily get confused when compilation directory is not known
Product: [Tools] CDT Reporter: Sergey Prigogin <eclipse.sprigogin>
Component: cdt-coreAssignee: Project Inbox <cdt-core-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cdtdoug, gong_ys2004, ken.ryall
Version: 4.0.1   
Target Milestone: 4.0.3   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Proposed fix cdtdoug: iplog-

Description Sergey Prigogin CLA 2007-11-03 20:26:35 EDT
I have a make tool that silently changes working directory going few levels up. For example, if the tool is invoked in /a/b/magic/c/d, the compiler is executed in /a/b/magic. No "Entering directory" message is printed to the output. This causes trouble for the error parser. In the case when the project contains /a/b/magic/c/d/file1.cc and /a/b/magic/c/e/file1.cc and there is a compilation error in /a/b/magic/c/d/file1.cc, the compiler error message contains a relative path: c/d/file1.cc. The error parser thinks that the compiler was executed in /a/b/magic/c/d and interprets c/d/file1.cc as /a/b/magic/c/d/c/d/file1.cc instead of /a/b/magic/c/d/file1.cc.

The error parser gets confused by the existence of /a/b/magic/c/e/file1.cc in spite of the fact that the path in the error message, c/d/file1.cc, does not match its location.
Comment 1 Sergey Prigogin CLA 2007-11-03 20:30:58 EDT
Created attachment 82044 [details]
Proposed fix

Doug, I'm still waiting for the committer paperwork to be signed on our side. Could you please review this change and check it in on my behalf. Thanks a lot.
Comment 2 Sergey Prigogin CLA 2007-12-02 20:01:06 EST
The patch applied to HEAD.
Comment 3 Sergey Prigogin CLA 2007-12-06 13:12:13 EST
Are there any objections to putting this into 4.0.3 too?
Comment 4 Doug Schaefer CLA 2007-12-06 13:53:55 EST
Nope, go ahead. and thanks!
Comment 5 Sergey Prigogin CLA 2007-12-08 13:01:34 EST
Also fixed in cdt_4_0 branch.
Comment 6 Ken Ryall CLA 2007-12-08 21:05:34 EST
Sergey - This change comments out ErrorParserManager.isConflictingName. Our error parser calls this method so our build broke after I updated to the latest CDT sources. Was the removal of isConflictingName intentional? Any guidance to how we should update our error parser?

Thanks - Ken
Comment 7 Sergey Prigogin CLA 2007-12-08 23:15:05 EST
(In reply to comment #6)
> Sergey - This change comments out ErrorParserManager.isConflictingName. Our
> error parser calls this method so our build broke after I updated to the latest
> CDT sources. Was the removal of isConflictingName intentional? Any guidance to
> how we should update our error parser?
> 
> Thanks - Ken
> 
Sorry, it was an oversight on my part. The method is restored.
Comment 8 Robin CLA 2008-01-31 04:36:33 EST
It does not fix the path resolve problem when "Entering directory `D:/test/code_opt/app'" and "Leaving directory `D:/test/code_opt/app'" messages happen in build console. and working directory is `D:/test/code_opt/app'.

below is the code from ErrorParserManager:
	public IPath getWorkingDirectory() {
		if (fDirectoryStack.size() != 0) {
			return (IPath) fDirectoryStack.lastElement();
		}
		// Fallback to the Project Location
		return fBaseDirectory;
	}

	public void pushDirectory(IPath dir) {
		if (dir != null) {
			IPath pwd = null;
			if (fBaseDirectory.isPrefixOf(dir)) {
				int segments = fBaseDirectory.matchingFirstSegments(dir);
				pwd = dir.removeFirstSegments(segments);
			} else {
				pwd = dir;
			}
			fDirectoryStack.addElement(pwd);
		}
	}
	/**
	 * Called by the error parsers.
	 */
	public IFile findFilePath(String filePath) {
		IPath path = null;
		IPath fp = new Path(filePath);
		if (fp.isAbsolute()) {
			if (fBaseDirectory.isPrefixOf(fp)) {
				int segments = fBaseDirectory.matchingFirstSegments(fp);
				path = fp.removeFirstSegments(segments);
			} else {
				path = fp;
			}
		} else {
			path = getWorkingDirectory().append(filePath);
		}

		IFile file = null;
		// The workspace may throw an IllegalArgumentException
		// Catch it and the parser should fallback to scan the entire project.
		try {
			file = findFileInWorkspace(path);
		} catch (Exception e) {
		}
...

when parsing "Entering Directory", MakeErrorParser will push the `D:/test/code_opt/app' into ErrorParserManager, but ErrorParserManager just keeps the 'd:';
If I have a conflicked file test.c in `D:/test/code_opt/app' and there are some errors in it,  ErrorParserManager's getWorkingDirectory().append("test.c") will output d:test.c path. as a result, this path can not be found anywhere.

Comment 9 Sergey Prigogin CLA 2008-01-31 12:44:58 EST
(In reply to comment #8)
Does you example work in 4.0.2?

> when parsing "Entering Directory", MakeErrorParser will push
> the `D:/test/code_opt/app' into ErrorParserManager, but ErrorParserManager
> just keeps the 'd:';

This doesn't look right. If your problem is reproducible with 4.0.2, please file a separate bug, if it's not, I'll reopen this one.
Comment 10 Robin CLA 2008-01-31 21:30:37 EST
(In reply to comment #9)
> (In reply to comment #8)
> Does you example work in 4.0.2?
> > when parsing "Entering Directory", MakeErrorParser will push
> > the `D:/test/code_opt/app' into ErrorParserManager, but ErrorParserManager
> > just keeps the 'd:';
> This doesn't look right. If your problem is reproducible with 4.0.2, please
> file a separate bug, if it's not, I'll reopen this one.

Yes, I am using 4.0.2. and I will file a separate bug