Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 315187 - Unknown tool option silently breaks all other options => gives broken build
Summary: Unknown tool option silently breaks all other options => gives broken build
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux-GTK
: P3 major (vote)
Target Milestone: 7.0   Edit
Assignee: James Blackburn CLA
QA Contact: Chris Recoskie CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-01 06:49 EDT by James Blackburn CLA
Modified: 2010-06-01 10:23 EDT (History)
1 user (show)

See Also:


Attachments
patch 1 (6.95 KB, patch)
2010-06-01 09:24 EDT, James Blackburn CLA
jamesblackburn+eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Blackburn CLA 2010-06-01 06:49:27 EDT
If a new option is added to a tool in a toolchain.  Opening the .cproject in an older Eclipse leads to corruption / breaking of the .cproject. 

For example:

In 7.0 a -include option was added to the Compiler Tool.  This results in an option entry like:

   <option id="gnu.c.compiler.option.include.files.19755955" name="Include files (-include)" superClass="gnu.c.compiler.option.include.files"/>

If you open a .cproject in a previous CDT with this option, and change the build settings, this option gets changed to:

   <option id="gnu.c.compiler.option.include.files.19755955" name="Include files (-include)"/>

Note its dropped the superClass attribute.

There are two problems with the .cproject now:
  - No other options work: -Ds, -Is, etc. are all ignored by MBS and not passed to the compiler tool
  - There are no errors / warnings, so there's no way for the user to resolve.

A few things should be fixed:
  - If we don't know about an option type, we should ignore it, and preserve the element if we can
  - We should warn the user when we don't know about a particular option type, but still continue to process other options
  - We shouldn't emit option entries when they're identical to the default value (in this case the empty list).
Comment 1 James Blackburn CLA 2010-06-01 07:18:02 EDT
Option#getValueType can throw a buildException. This is thrown all the way out to GnuMakefileGenerator:

Option.getValueType() line: 1469	
Tool.getToolCommandFlags(IPath, IPath, SupplierBasedCdtVariableSubstitutor, IMacroContextInfoProvider) line: 2545	
Tool.getToolCommandFlags(IPath, IPath) line: 2682	
GnuMakefileGenerator.addRuleForSource(String, StringBuffer, IResource, IPath, IResourceInfo, boolean, Vector<IPath>, Vector<IPath>) line: 2637	
GnuMakefileGenerator.addFragmentMakefileEntriesForSource(LinkedHashMap<String,String>, StringBuffer, IFolder, String, IResource, IPath, IResourceInfo, String, boolean) line: 2080	

This is then silently eaten by the GnuMakefileGenerator:

// Get the tool command line options
try {
	flags = tool.getToolCommandFlags(sourceLocation, outputLocation);
} catch( BuildException ex ) {
	// TODO add some routines to catch this
	flags = EMPTY_STRING_ARRAY;
}

This is pretty bad.  #getToolCommandFlags iterates over all the tool options. So one bad option breaks all the others...
Comment 2 James Blackburn CLA 2010-06-01 07:33:10 EDT
Chris, Andrew: AFAICS #getToolCommandFlags(IPath, IPath, ...) should never throw BuildException as *all* 21 indirect callers (as viewed by show call hierarchy) _silently_ eat this exception. 

So for fixing point 2, I'd say that getToolCaommandFlags shouldn't throw a build exception but rather should log the exception and carry on processing other options.
Comment 3 James Blackburn CLA 2010-06-01 09:24:45 EDT
Created attachment 170632 [details]
patch 1

The attached patch fixes issues 1 & 2. The warning emitted to the error log, looks like:

   Problem discovering arguments for Tool option: Include files (-include) (gnu.c.compiler.option.include.files.953373612)
    <backtrace>


The patch is straightforward; I'll target 7.0.1.

Detailed changes:
 - ManagedBuildCorePlugin: Incorrectly logs CoreExceptions (see CoreException#getStatus()
 - Option.java: attempt to preserve superClassId even if superClass == null
 - Tool.java#getToolCommandFlags(... SupplierBasedCdtVariableSubstitutor ...)
     + no longer throws BuildException.
     + Logs exceptions (like above is something goes wrong)

The 3rd issue mentioned in comment 0: it seems that options are only emitted in the .cproject if they're ever changed. Unfortunately, resetting them to defaultValue doesn't remove them. This is a less severe issue, so not tackling this.
Comment 4 Elena Laskavaia CLA 2010-06-01 09:40:06 EDT
Why not fix it 7.0? it seems safe. People often switch between versions...
Comment 5 James Blackburn CLA 2010-06-01 09:43:22 EDT
(In reply to comment #4)
> Why not fix it 7.0? it seems safe. People often switch between versions...

Ok. I just needed review.  This is pretty serious for us, so I've put the fix into our product, will commit to CDT.
Comment 6 James Blackburn CLA 2010-06-01 09:48:32 EDT
Fixed in 7.0
Comment 7 CDT Genie CLA 2010-06-01 10:23:06 EDT
*** cdt cvs genie on behalf of jblackburn ***
Bug 315187 Unknown tool option silently breaks ManagedBuild tool command line generation

[*] PluginResources.properties 1.58 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties?root=Tools_Project&r1=1.57&r2=1.58
[*] Option.java 1.47 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java?root=Tools_Project&r1=1.46&r2=1.47
[*] Tool.java 1.98 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java?root=Tools_Project&r1=1.97&r2=1.98

[*] BuildMacroProvider.java 1.10 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/BuildMacroProvider.java?root=Tools_Project&r1=1.9&r2=1.10

[*] ManagedBuilderCorePlugin.java 1.28 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java?root=Tools_Project&r1=1.27&r2=1.28

[*] ToolSettingsPrefStore.java 1.7 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolSettingsPrefStore.java?root=Tools_Project&r1=1.6&r2=1.7