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

Bug 330204

Summary: Headless build always cleans active configuration
Product: [Tools] CDT Reporter: Nobody - feel free to take it <nobody>
Component: cdt-buildAssignee: Torbjörn Svensson <torbjorn.svensson>
Status: RESOLVED FIXED QA Contact: Andrew Gvozdev <angvoz.dev>
Severity: normal    
Priority: P3 CC: cdtdoug, heamuasi, jamesblackburn+eclipse, jonah, mistria, torbjorn.svensson, torbjorn.svensson, william.riley, yevshif, zulliger
Version: 8.0   
Target Milestone: 9.5.0   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/119602
https://git.eclipse.org/r/119605
https://git.eclipse.org/r/119915
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=4881a2ecd42d20dbb5e785801b122daa27f36799
https://bugs.eclipse.org/bugs/show_bug.cgi?id=552606
https://git.eclipse.org/r/c/platform/eclipse.platform.resources/+/119602
Whiteboard:
Bug Depends on:    
Bug Blocks: 571134    
Attachments:
Description Flags
[Patch 1/2] Add method preserving builder specific arguments to base class
torbjorn.svensson: review?
[Patch 2/2] Implement the argument preserving clean torbjorn.svensson: review?

Description Nobody - feel free to take it CLA 2010-11-14 17:57:30 EST
Headless build ignores <configuration> argument for -cleanBuild <project>/<configuration> and always cleans the active configuration.
Comment 1 Henry CLA 2011-03-07 04:41:55 EST
Mikhail is right: I discovered this bug too.  Anybody knows how to fix this?
Comment 2 Torbjörn Svensson CLA 2016-12-04 08:16:49 EST
Created attachment 265712 [details]
[Patch 1/2] Add method preserving builder specific arguments to base class

In order to clean the correct configuration, the builder specific arguments needs to be preserved when calling clean. If the builder specific arguments are lost, the active configuration will be cleaned and this is usually not what the user expects if a non-active configuration was selected for the clean operation.
Comment 3 Torbjörn Svensson CLA 2016-12-04 08:21:23 EST
Created attachment 265713 [details]
[Patch 2/2] Implement the argument preserving clean

The 2'nd part implements the clean method with builder specific arguments preserved so that the correct project/configuration is cleaned rather than the active configuration for the project.
Comment 4 Torbjörn Svensson CLA 2016-12-04 08:29:04 EST
Steps to reproduce:
1. Create a new "Hello World ANSI C Project" with default settings, call it "helloc" for simplicity.
2. Make sure "Debug" is the active build configuration for the newly created project.
3. Run the headless builder application with the following arguments: -importAll /path/to/helloc -cleanAll helloc/Debug
4. Verify that the configuration Debug in helloc is both cleaned and compiled.
5. Run the headless builder application with the following arguments: -importAll /path/to/helloc -cleanAll helloc/Release
6. Verify that the configuration Release in helloc is both cleaned and compiled.


Without the attached set of patches, step 6 above will clean configuration "Debug" but build configuration "Release" and that's obviously not what the user expected to happen.
Comment 5 Eclipse Genie CLA 2018-03-16 17:56:19 EDT
New Gerrit change created: https://git.eclipse.org/r/119602
Comment 6 Eclipse Genie CLA 2018-03-16 18:21:59 EDT
New Gerrit change created: https://git.eclipse.org/r/119605
Comment 7 Mickael Istria CLA 2018-03-21 10:00:47 EDT
Is there a workaround possible somewhere, such as storing in the builder state or project state what are the files to be cleaned?
Couldn't/Shouldn't the clean operation perform a full clean which would be independent of args?
Comment 8 Eclipse Genie CLA 2018-03-21 16:22:37 EDT
New Gerrit change created: https://git.eclipse.org/r/119915
Comment 9 Torbjörn Svensson CLA 2018-03-21 16:36:18 EDT
Thanks for the comments on both the Gerrit review and here.

I've debugged this a bit further and came up with another solution that does not require an API change, but will instead rely on a race condition (nothing new since the UI is already using it) by switching the "active configuration" when invoking builder to clean a configuration.
In the ManagedBuildManager.buildConfigrations method, there is a comment about clean not taking arguments and I think the solution there should be considered a workaround, but not actually a proper solution for the problem. (https://git.eclipse.org/r/plugins/gitiles/cdt/org.eclipse.cdt/+/master/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java#4591)

With https://git.eclipse.org/r/119915 the HeadlessBuilder can at least reach the same functionality as the UI although not optimal. I think this is a good compromise for the short run, but I really think that the argument to clean should be considered for future releases since it is more flexible than this solution.
Comment 10 Jonah Graham CLA 2018-04-18 17:31:50 EDT
Lets see if we can make sure this gets reviewed in time for 9.5. It looks promising, but I want to have a closer look.