Bug 242955 - new configurations badly or not saved
Summary: new configurations badly or not saved
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build (show other bugs)
Version: 5.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 major with 2 votes (vote)
Target Milestone: 5.0.2   Edit
Assignee: Elena Laskavaia CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-02 10:23 EDT by Bruno Piar CLA Friend
Modified: 2014-01-29 21:50 EST (History)
12 users (show)

See Also:


Attachments
broken C project (2.19 KB, application/zip)
2008-09-21 14:18 EDT, Andreas Kraatz CLA Friend
no flags Details
Proposed patch to fix managed configurations problem. (1009 bytes, patch)
2008-10-07 15:36 EDT, Jeff Johnston CLA Friend
no flags Details | Diff
Proposed patch to fix managed configurations problem (3.06 KB, patch)
2008-11-06 15:33 EST, Jeff Johnston CLA Friend
cdtdoug: iplog+
Details | Diff
phantom configuration test case (5.41 KB, patch)
2008-11-06 23:00 EST, Andrew Gvozdev CLA Friend
jamesblackburn+eclipse: iplog+
Details | Diff
patch 1 (6.33 KB, patch)
2009-01-11 16:18 EST, James Blackburn CLA Friend
jamesblackburn+eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Piar CLA Friend 2008-08-02 10:23:42 EDT
Build ID: Build id: I20080617-2000

Steps To Reproduce:
1. create a new configuration for a given project :
Properties -> C/C++ build -> manage configuration -> new -> ... -> apply -> ok
2. quit eclipse
3. restart eclipse: the configuration has not been saved.


More information:
When restarting eclipse, the configuration that was created during the previous session does not appear in the "build" icon (the hammer). If now you look at:
Properties -> C/C++ build -> manage configuration, it does not appear in the list but the formerly existing configuration that was used to "copy settings from" appears twice.
Comment 1 Andrew Gvozdev CLA Friend 2008-08-02 17:33:52 EDT
Mac specific or you have some other specific settings? Worksforme just fine on WinXp with virgin installation 3.4+5.0.0. Maybe you can try in fresh empty workspace?
Comment 2 Bruno Piar CLA Friend 2008-08-03 05:24:19 EDT
(In reply to comment #1)
Same with a fresh empty workspace.
Same with Linux 32 bits.
Comment 3 Akos Ladanyi CLA Friend 2008-08-03 09:59:48 EDT
Happens on Linux 64 bit too.
Version: 3.4.0
Build id: I20080617-2000
CDT: 5.0.0.200806171202
Comment 4 Akos Ladanyi CLA Friend 2008-08-03 11:03:25 EDT
I can reproduce this with the Windows version too. Here is what I did:
 - created a new C++ makefile project with 'Other toolchain'
 - now I have a single configuration called Default
 - added a new build configuration under 'C/C++ Build' called Debug
 - changed the build directory in the Debug configuration to
   ${workspace_loc:/TestProject/Debug}
 - quit eclipse, restart
 - now I have two configurations, both named Default

Version: 3.4.0
Build id: I20080617-2000
CDT: 5.0.0.200806171202
Comment 5 Jonn CLA Friend 2008-09-02 15:04:48 EDT
I, too, am experiencing this problem under WinXP.  Originally I noticed the behavior documented above by Akos Ladanyi.  Now I have tried creating a new workspace and reinstalling eclipse from scratch and am finding the problems in the original bug report.

Interestingly, if you search in your project's .cproject file for the missing build configuration, it is, in fact, there.

Version: 3.4.0
Build id: I20080617-2000
Comment 6 Andreas Kraatz CLA Friend 2008-09-18 16:41:37 EDT
I can confirm this bug.
Steps to reproduce:
I'm using a "fresh" installation of eclipse (Version: 3.4.0, Build id: I20080617-2000) and CDT (Version: 5.0.0.200806171202, Build id: 200806171202) on WinXP.
After creating a new C Makefile Project with 'Other Toolchain' a have a 'Default' build configuration.
1) open project properties
2) C/C++ Build
3) Manage Configurations...
4) New...
5) enter name and press OK
6) press OK again (to quit 'Manage Configurations...')
7) press 'Apply'
8) press OK (to quit project properties)
9) close project (or exit eclipse)
10) open project (or start eclipse)
=> Voilá the new configuration is lost and at 'Manage Configurations...' dialog you can see two 'Default' configurations. Btw. in the .cproject file there are three build configurations (two 'Default' and the new one)

If you do the same procedure without pressing 'Apply' all works fine. Furthermore you can add several build configurations one after another by this procedure without quitting the project properties dialog but you must not press the 'Apply' button. It seems that the 'Apply' button causes the confusion.

Comment 7 Andrew Gvozdev CLA Friend 2008-09-18 18:28:07 EDT
You spelled this out down to exact keys but I still can't reproduce. Fresh installation of eclipse with matching numbers, fresh workspace. No other plugins installed. WinXP. I am getting 2 configurations after reopening of the project, one is "Default" and another is "New". No duplicates. 2 correct ones in .cproject. This is very puzzling.
Comment 8 Andreas Kraatz CLA Friend 2008-09-21 14:18:22 EDT
Created attachment 113080 [details]
broken C project
Comment 9 Andreas Kraatz CLA Friend 2008-09-21 14:20:25 EDT
Ok, my first description is not bullet proof to reproduce the bug.
I hope that my second description will do it.
Very important are the steps 12, 13 and 14! You must select the new configuration, press 'Apply' and after that press OK. It depends on the choosen configuration name if the 'Default' configuration stays selected or the new configuration is selected automatically.

Ok, I have executed these steps and the .cproject file is broken. See attachment (id=113080).

1) Start eclipse (set workspace, don't check "Use this as default...", close 'Welcome' screen)
2) Menu: File->New->C Project
3) enter "myproject" as project name (Makefile project, -- Other Toolchain --), click Next, click Finish
4) click on 'myproject' at Project Explorer to set focus on it
5) Menu: Project->Properties
--- now the dialog "Properties for myproject" is open
6) click on C/C++ Build
--- the 'Default' configuration is selected at the drop down list (ok, its the only existing one)
7) click on "Manage Configurations..."
8) click on "New..."
9) enter "Rebuild" as configuration name
10) press OK to close "New.." dialog
11) press OK to close "Manage Configurations..."
--- back at "Properties for myproject" dialog, note that the 'Default' configuration is still selected
12) select configuration "Rebuild" at drop down list
13) press 'Apply', note that a small window opens and closes immediatly
14) press 'OK', note that a small window opens and closes immediatly
15) exit eclipse by clicking the 'X', confirm by pressing 'OK'
--- take a look at ".cproject", it will has a size about 30KB
16) open eclipse, confirm workspace
17) click on 'myproject' at Project Explorer to set focus on it
18) click on "Manage Configurations for current project" icon at toolbar
--- you will see two 'Default' configurations, the .cproject file contains two 'Default' and one 'Rebuild' configuration

Comment 10 Andrew Gvozdev CLA Friend 2008-09-21 21:12:41 EDT
This bug was driving me mad but I was finally able to reproduce switching to my home desktop. Obviously my laptop works better, this bug just is not there - no matter how hard I try. Also reproducible on the head.
Comment 11 Andrew Gvozdev CLA Friend 2008-09-23 17:32:21 EDT
There are also other problems with saving configuration changes on Apply button. Try adding 2 new configurations inside Manage Configurations and select one of them before pressing Apply in C/C++ Build. Press Apply. Then press Cancel. The one selected is saved but the other is not. Any deletion is not saved on Apply either. It seems that fixing bug 233432 opened up some more darker corners in CDT to explore. I filed also bug 248341 - although unlikely that it is related.
Comment 12 Andrew Gvozdev CLA Friend 2008-09-26 11:38:26 EDT
It seems that not only me had problem of reproducing. See bug 239687 which was happily closed as "FIXED" as noted by Ali Burak Kulakli in eclipse.tools.cdt.

I can reliably reproduce now even on my laptop. The key seems to be to select just created configuration before pressing Apply. At that point the new configuration gets created in project description. I can see that InternalXmlStorageElement gets copied from Default configuration along with its name. Not sure that it is really the cause but it definitely creates internal inconsistency in CConfigurationDescription object. Creating a new configuration from another one works in general.
Comment 13 Jeff Johnston CLA Friend 2008-10-07 15:34:49 EDT
(In reply to comment #12)
> It seems that not only me had problem of reproducing. See bug 239687 which was

Some more details.  The .cproject file is wrong.  The problem I have found is that there is a second configuration with the id in question.  The first one is the correct configuration with the additional changes I made and the proper name.  The second one is the default configuration with the default name.  Perhaps because I copied the default configuration to make this new configuration???  

The code in: CProjectDescriptionManager.java: createCfgStorages() adds to a Map based on the id.  Since there is a second ICStorageElement with that id, the second put operation overwrites the correct ICStorageElement with the default one.

A way to fix this (kludge???) is to look at the return value from Map.put() which will be null or the previous element (if one existed).  If non-null and the element doesn't equal the new one we are just adding, put back the previous value (i.e. so first one wins).

	Map createCfgStorages(ICProjectDescription des) throws CoreException{
		LinkedHashMap map = new LinkedHashMap();
		ICStorageElement rootElement = des.getStorage(MODULE_ID, false);
		if(rootElement != null){
			ICStorageElement children[] = rootElement.getChildren();
			
			for(int i = 0; i < children.length; i++){
				ICStorageElement el = children[i];
				if(CONFIGURATION.equals(el.getName())){
					String id = el.getAttribute(CConfigurationSpecSettings.ID);
					if(id != null) {
						ICStorageElement el2 = (ICStorageElement)map.put(id, el);
                                                if (el2 != null && el2 != el)
                                                        map.put(id, el2);
                                        {
				}
			}
		}
		return map;
	}
 

This fixes the problem for me and in fact, my new configuration comes back as the active one as it was active when I shut down Eclipse.

I'll attach it as a patch as well for anyone who has commit rights to look at and try out.
Comment 14 Jeff Johnston CLA Friend 2008-10-07 15:36:16 EDT
Created attachment 114468 [details]
Proposed patch to fix managed configurations problem.
Comment 15 Andrew Gvozdev CLA Friend 2008-10-07 22:55:28 EDT
The patch deals with already corrupted project. There are still 2 configurations with the name "Default" in cproject being created. I think it would be appropriate to address the cause of corruption in this task.
Comment 16 Jeff Johnston CLA Friend 2008-11-06 15:33:44 EST
Created attachment 117245 [details]
Proposed patch to fix managed configurations problem
Comment 17 Jeff Johnston CLA Friend 2008-11-06 16:39:43 EST
(In reply to comment #15)
> The patch deals with already corrupted project. There are still 2
> configurations with the name "Default" in cproject being created. I think it
> would be appropriate to address the cause of corruption in this task.
> 

I have posted a 2nd patch to prevent the corrupted .cproject.

The problem occurs when a new configuration is added then selected prior to the apply button being pressed.

What is occurring is that the new configuration has been added to a different CProjectDescription than the one being used during Apply.  

So, when a new configuration just added is selected and the Apply button is hit, the AbstractPage.performSave() method at one point calls its findCfg() method.  The ICConfigurationDescription selected isn't known to the current ICProjectDescription so it creates one using ICProjectDescription.createConfiguration(id, name, base).

There are two createConfiguration() methods for ICProjectDescription and the one currently used by findCfg() is used when cloning an existing configuration.  I found that using this form results in the phantom configuration when the Ok button gets pressed.  It ends up calling the CConfigurationDescription constructor form which has:

CConfigurationSpecSettings baseSettings = ((CConfigurationDescription)base).getSpecSettings();

InternalXmlStorageElement baseRootEl = (InternalXmlStorageElement)baseSettings.getRootStorageElement();

InternalXmlStorageElement newRootEl = CProjectDescriptionManager.getInstance().copyConfigurationElement(baseRootEl, id, false);

My patch adds a check to see if the ICConfigurationDescription id in question is known to the cached CProjectDescription of the CDTPropertyManager.  If this is the case, it uses the 2nd form of createConfiguration() that takes ICConfigurationData and a build system id.  The build system id is found from the existing ICConfigurationDescription we found in the CDTPropertyManager's CProjectDescription.

With this change, there is no phantom configuration created in the .cproject.

I added a case where if the configuration is also not found in the CDTPropertyManager's CProjectDescription, then a default build system id is used.  I do not know if this is a possible scenario or whether the default id would cause a problem.

Please review and let me know if I have missed anything.
Comment 18 Andrew Gvozdev CLA Friend 2008-11-06 23:00:03 EST
Created attachment 117285 [details]
phantom configuration test case

Your analysis coincides with my findings. I tested your patch and took a look at the code and AFAICS it works correctly (dodging the faulty call). Still, as yourself note, createConfiguration() method is not correct and can create phantom configuration under these conditions. Attached is a test case demonstrating that.
Comment 19 James Blackburn CLA Friend 2009-01-11 16:18:52 EST
Created attachment 122216 [details]
patch 1 

Andrew, thanks for another good test!

Jeff unfortunately this issues can't / shouldn't be fixed in the UI.  It's a core problem.  The issue, as you both pointed out, is that the CConfigurationDescription constructor duplicates and imports the new configuration into the wrong project description -- the prjdesc of the original configdesc rather than the requested project description.

Attached is a patch for CDT 5 & 6 which should resolve this issue.  I've added a new createStorage method to CProjectDescriptionManager (next to the other configuration storage creation method).  This isn't the ideal place, though is consistent with the current CProjectDescriptionManager.createStorage(...) method.  This should be re-examined in the context of bug252966.

Andrew and Jeff I'd be interested if you guys have any further comments.
Elena can you review?
Comment 20 Andrew Gvozdev CLA Friend 2009-01-11 18:29:53 EST
(In reply to comment #19)
> Created an attachment (id=122216)
> patch 1
> 
> Andrew and Jeff I'd be interested if you guys have any further comments.

No, I am satisfied with this one. Kudos to you James.
Comment 21 Dave Lewanda CLA Friend 2009-01-15 13:38:25 EST
(In reply to comment #19)
> Attached is a patch for CDT 5 & 6 which should resolve this issue.

I am new to the Eclipse platform, but I encountered this same bug when setting up a C Make project with multiple configurations.  I was wondering what steps I need to take to apply this patch to my installation of Eclipse.  Ideally, I'd like to get an update so that I can point members of my team to a specific version, rather than having to do a custom build of the IDE.  Can anyone share how I might do this, or if it's not yet available, when it might be?  Many thanks in advance!
~Dave~
Comment 22 James Blackburn CLA Friend 2009-01-15 18:19:12 EST
(In reply to comment #21)
> I am new to the Eclipse platform, but I encountered this same bug when setting
> up a C Make project with multiple configurations.  I was wondering what steps I
> need to take to apply this patch to my installation of Eclipse.  Ideally, I'd
> like to get an update so that I can point members of my team to a specific
> version, rather than having to do a custom build of the IDE.  Can anyone share
> how I might do this, or if it's not yet available, when it might be?  Many
> thanks in advance!

The patch isn't yet applied to HEAD.  You should take a look at the FAQs: http://wiki.eclipse.org/CDT/User/FAQ#How_do_I_build_CDT_from_CVS_if_I_want_an_even_more_recent_build_and_I_want_all_the_pieces_and_parts.3F

Having checked out the source, there's an Apply Patch method on Team pop-up menu.  You can then export the updated plugin from the workspace.  If you need more info the Plugin developers guide should point you in the right direction and/or ask on the newsgroup:
news://news.eclipse.org/eclipse.tools.cdt
Comment 23 Elena Laskavaia CLA Friend 2009-01-16 10:04:59 EST
patches (4 and 5) applied on 5.0.2 and head, thanks James and Andrew
Comment 24 Dave Lewanda CLA Friend 2009-01-19 10:00:31 EST
Hi,
    Thanks for applying the patch to the 5.0.2 tree.  When can we expect a 5.0.2 release of CDT?  I searched for a release roadmap, but to no avail...

Thanks,
Dave
Comment 25 Elena Laskavaia CLA Friend 2009-01-19 10:04:35 EST
It will be sometime in February, in the meanwhile you can download nightly build
Comment 26 Jure Ferbezar CLA Friend 2009-02-18 07:19:10 EST
I would like to add just one more thing to the bug description.

If you create a new configuration and you also have environment variables this is what happens depending which buttons you press (CDT version 5.01):

OK:
Configuration is properly saved in .cproject
Environment is NOT saved to .settings/org.eclipse.cdt.core.prefs


Apply & OK:
Extra Default configuration is added at the end of .cproject (corrupt file)
Environment is correctly saved to .settings/org.eclipse.cdt.core.prefs

Apply & Cancel
Configuration is properly saved in .cproject
Environment is correctly saved to .settings/org.eclipse.cdt.core.prefs


So the Apply and Cancel combination is the only one that works correctly.

I did not apply the patch so I do not know if the patch solves the problem with saving the settings in .settings/org.eclipse.cdt.core.prefs.

Comment 27 James Blackburn CLA Friend 2009-02-18 07:34:01 EST
(In reply to comment #26)
> OK:
> Configuration is properly saved in .cproject
> Environment is NOT saved to .settings/org.eclipse.cdt.core.prefs

I've created bug 265282 to track this.  I don't think it's related to this issue of persisting the configuration more than once in the project description.