Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324816 - GnuMakefileGenerator does not properly handle tools which have more than one primary input type
Summary: GnuMakefileGenerator does not properly handle tools which have more than one ...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 7.0.1   Edit
Assignee: Chris Recoskie CLA
QA Contact: Chris Recoskie CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-08 23:33 EDT by Chris Recoskie CLA
Modified: 2010-09-13 14:09 EDT (History)
2 users (show)

See Also:


Attachments
proposed patch (1.07 KB, text/plain)
2010-09-08 23:33 EDT, Chris Recoskie CLA
recoskie: iplog-
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Recoskie CLA 2010-09-08 23:33:44 EDT
Created attachment 178475 [details]
proposed patch

If a tool has more than one input type which has it's primaryInput attribute set to true (e.g., you have a C++ compiler that compiles both C and C++ files, which is how the xlC toolchain is setup), then GnuMakefileGenerator generates an incorrect subdir.mk

In GnuMakefileGenerator.getAdditionalResourcesForSource(ITool), the code looks for "additional inputs" to the tool, and adds these as command line parameters to the pattern rule for the given input type.  The problem is the way that it determines whether a given input type is a primary or secondary input.  The way it does this is by calling ITool.getPrimaryInput() and comparing that to the input type.  This doesn't account for the fact that a tool may have more than one primary input type, so any resources in the project that are of an input type marked as primary, but not returned by ITool.getPrimaryInput(), will be assumed to be secondary inputs.

So, if for example the C input type happens to be what is returned from ITool.getPrimaryInput(), then all C++ files will be considered secondary inputs, and this means they will be added as command line parameters to the pattern rule for the tool.

E.g., if you have a.cpp, b.cpp, c.cpp, then the rule looks something like:

%.o : %.cpp
     your_cpp_compiler "$>" -o"$@" a.cpp b.cpp c.cpp

Obviously this is bad, because you end up recompiling every file in the project in one command line.  Not all tools are able to handle that.  Furthermore, each operating system generally has a fixed limit on the length (and possibly, number) of command line parameters that can be used in a command.  For a large project, it is easy to imagine exceeding that limit.  Furthermore, compiling all files in one step ruins the ability to parallelize the build, e.g. with make's -j option.

The solution I propose is fairly simple.  Instead of just querying the tool for its primary input type and comparing to it, also ask the input type whether it is a primary input.  This way all input types that are set to be primary inputs will be treated as such, and the makefile is generated correctly.  Unfortunately it seems a lot of input types do not specify that they are primary inputs, as if there is only one input then it's assumed to be the primary input.  This means that we can't rely only upon whether an input type is primary or not.  We also need to ask the tool for its primary input and compare to that as well.

The one-line patch is attached.
Comment 1 Chris Recoskie CLA 2010-09-10 17:19:19 EDT
Applied to cdt_7_0 and HEAD.