scons icon indicating copy to clipboard operation
scons copied to clipboard

Use C compiler to help scan for header dependencies

Open bdbaddog opened this issue 7 years ago • 7 comments

This issue was originally created at: 2010-04-01 16:36:16. This issue was reported by: witkamp.

witkamp said at 2010-04-01 16:36:16

The current scanner implementation uses some partial macro expansion. This is not good enough especially when using the C preproccessor for configuration.

For example:

#define HEADER "foo.h"
#include HEADER

The current scanner does not detect "foo.h" as a dependency, and you can imagine more sophisticated macros will not work as well.

This is not that big of a problem until someone tried to build variants. Because the scanner does not find the dependency, it is not copied to the variant_dir and the build fails.

Suggested Solution:

Why not run the compiler in preprocessor only mode and scan that output? This guarantees scons will generate correct dependencies.

gregnoel said at 2010-04-30 17:08:38

Bug party triage. The experimental C/C++ scanner will do this, but its use is undocumented. Steven to document how to use it.

bdbaddog avatar Jan 02 '18 14:01 bdbaddog

The ParseDepends function caters for this exact use case. I suggest closing this as "fixed".

ajf58 avatar Feb 24 '18 11:02 ajf58

ParseDepends above is a work around.

Pull request #3053 implements a fuller scanner which should handle the above fully.

bdbaddog avatar Mar 02 '18 19:03 bdbaddog

Updating the set of related issues. Yes, the CConditionalScanner handles the specific case stated here.

Since not every compilation system would behave the same way trying to use "the preprocessor" to detect header dependencies, it would be hard to do what this issue requests in a portable way. Recommend rejecting (wontfix) this one.

mwichmann avatar Jul 19 '22 16:07 mwichmann

Updating the set of related issues. Yes, the CConditionalScanner handles the specific case stated here.

Since not every compilation system would behave the same way trying to use "the preprocessor" to detect header dependencies, it would be hard to do what this issue requests in a portable way. Recommend rejecting (wontfix) this one.

Which C compilers wouldn't handle this?

bdbaddog avatar Jul 19 '22 16:07 bdbaddog

I have no idea how you invoke msvc to spit out header dependencies, I'm not saying it can't.

mwichmann avatar Jul 19 '22 16:07 mwichmann

I have no idea how you invoke msvc to spit out header dependencies, I'm not saying it can't.

/showIncludes but it goes to stdout while running the compiler.

bdbaddog avatar Jul 19 '22 16:07 bdbaddog

Ah, ok. I see a new option, /sourceDependencies, which is much more sophisticated and writes a json file (which must be given as the option-argument). That was introduced, according to an MS blog post, with VS 2019 version 16.7.

mwichmann avatar Jul 19 '22 16:07 mwichmann