Bug 410529 - Adding and deleting a "source folder" corrupts the project
Summary: Adding and deleting a "source folder" corrupts the project
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 8.2   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: 9.0.0   Edit
Assignee: John Dallaway CLA
QA Contact: Chris Recoskie CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-11 15:23 EDT by Baltasar Belyavsky CLA
Modified: 2016-09-29 11:09 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Baltasar Belyavsky CLA 2013-06-11 15:23:05 EDT
Adding and immediately deleting a "source folder" corrupts the project by clearing all library and search-path settings on the linker, and expanding all macros on the include-path settings on the compiler.

Steps to reproduce:

1. Create a simple MinGW project.
2. Define one build-variable, named TEST, pointing to "C:/temp".
3. Add to compiler include-path: "${TEST}/f1"
4. Add to linker search-path: "${TEST}/f1"
5. Add the library "test"
-> So far all is OK...

6. Now, add new source-folder, name it "a", and immediately delete it
-> Open the tool settings page and see the following unexpected changes:
   1. The list of libraries and search-path were both cleared.
   2. The macro TEST in the compiler include-path was expanded.
   3. The compiler's include-path value has been copied onto the assembler.
Comment 1 John Dallaway CLA 2016-03-04 03:57:42 EST
With CDT 8.8.1, I can confirm that there are multiple issues with the "PathEntry Update source root" WorkspaceJob triggered when a CDT root source folder (ISourceRoot) is deleted.

Firstly, this is reproducible on both win32 and linux hosts.

To the list of issues already reported, I can add:

  4. Workspace-relative include paths are corrupted. The project folder is
     prepended to each path such that it appears twice:

        "${workspace_loc:/myProject/include}" -->
             "${workspace_loc:/myProject/myProject/include}"

     The BuildEntryStorage.doConvertToOptionValue() method is appending the
     workspace-relative path fragment to the project folder but it should be
     appended to the workspace root.
Comment 2 John Dallaway CLA 2016-03-13 05:18:32 EDT
Regarding issue 1 ("The list of libraries and search-path were both cleared"), this appears to be a related to changes made many years ago to fix bug 100844:

http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java?id=297e4e1de8d46f3a9ecf40cb757976ecce9908e3

The "PathEntry Update source root" WorkspaceJob requests an array of all IPathEntry objects (getRawPathEntries), makes a copy of the array with without the IPathEntry of the deleted source folder, and then writes the new array back to storage (setRawPathEntries). Historic changes in PathEntryTranslator.toPathEntry() result in PathEntryManager.getRawPathEntries() not returning any entries of type IPathEntry.CDT_LIBRARY (mapped to ICSettingEntry.LIBRARY_FILE). So when the array is written back to storage, all library elements are lost.

We can resolve this particular issue either by:

a) providing a better fix for bug 100844, or
b) modifying the "PathEntry Update source root" WorkspaceJob to remove
   source folders in a different way.

I can spend some time working on a fix but need some initial guidance from the CDT committers regarding the which option would be acceptable. Based on comments in bug 100844, it would appear that reworking the "PathEntry Update source root" WorkspaceJob may be the less invasive of the two options and could resolve some of the other issues reported here at the same time.
Comment 3 Eclipse Genie CLA 2016-04-14 09:13:28 EDT
New Gerrit change created: https://git.eclipse.org/r/70645
Comment 4 John Dallaway CLA 2016-04-14 09:22:25 EDT
The contribution at https://git.eclipse.org/r/70645 addresses the reported issue by re-implementing the "PathEntry Update source root" WorkspaceJob to remove the path entry of the deleted source folder from project settings using the same technique that the New Source Folder wizard employs to add a path entry.
Comment 6 Jonah Graham CLA 2016-05-10 09:06:45 EDT
John, Thanks for tracking this down and pushing through a resolution.
Comment 7 John Dallaway CLA 2016-05-10 12:29:13 EDT
Jonah, thank you for the review. Great to see this particular bug marked FIXED.
Comment 8 Michael Schaffner CLA 2016-09-29 11:01:15 EDT
This bug still exists in CDT 8.5.

Adding or deleting folders in project tree corrupts project settings that were entered manually, such as include paths.
Comment 9 Jonah Graham CLA 2016-09-29 11:09:31 EDT
(In reply to Michael Schaffner from comment #8)
> This bug still exists in CDT 8.5.
> 
> Adding or deleting folders in project tree corrupts project settings that
> were entered manually, such as include paths.

Hi Michael, that's expected fir 8.5. It is fixed in CDT 9.0. Please let us know if you find any issues in that version. 

Thanks for taking the time to report the issue. 
Jonah