Skip to content

Use C compiler to help scan for header dependencies #2601

Open

Description

@bdbaddog

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.

Activity

  1. added this to the 2.x milestone on Jan 2, 2018
  2. ajf58 commented on Feb 24, 2018

    @ajf58
    Contributor

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

  3. bdbaddog commented on Mar 2, 2018

    @bdbaddog
    ContributorAuthor

    ParseDepends above is a work around.

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

  4. modified the milestones: 2.x, anytime on Mar 27, 2021
  5. mwichmann commented on Jul 19, 2022

    @mwichmann
    Collaborator

    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.

  6. bdbaddog commented on Jul 19, 2022

    @bdbaddog
    ContributorAuthor

    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?

  7. mwichmann commented on Jul 19, 2022

    @mwichmann
    Collaborator

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

  8. bdbaddog commented on Jul 19, 2022

    @bdbaddog
    ContributorAuthor

    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.

  9. mwichmann commented on Jul 19, 2022

    @mwichmann
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions