scons icon indicating copy to clipboard operation
scons copied to clipboard

CConditionalScanner does not detect included header from a command line macro

Open mwichmann opened this issue 3 years ago • 2 comments

This issue is generated as a result of investigating using the CConditionalScanner to detect dependencies when the #include uses a macro, after a Discord discussion here: https://discord.com/channels/571796279483564041/571796280146133047/998690474216927345. This base problem has actually been recorded in several past issues, including #344 #2601 #3038.

The investigation shows that if the macro is defined in the source file, like this:

#define HEADER "foo.h"
#include HEADER

then CConditionalScanner indeed produces the dependency, but if it is defined as a compiler command-line option, it is not.

env = Environment(CPPDEFINES=['HEADER=\\"foo.h\\"'])

Attaching a diff to the unit test file for the C scanner, which demonstrates this behavior (unfortunately had to make into a file type github would accept)

CTests-diff.zip

mwichmann avatar Jul 19 '22 16:07 mwichmann

Hi @mwichmann, do you use the latest development version? It should be fixed by https://github.com/SCons/scons/commit/d9192dbf0c4380043759262147e6e06b0caf590e

ivankravets avatar Jul 25 '22 12:07 ivankravets

Doesn't seem to be... which doesn't mean my test isn't faulty. I still get:

AssertionError: False is not true : expect ['f9.h'] != scanned []

mwichmann avatar Jul 25 '22 13:07 mwichmann

I think this may have been fixed by #4263 - not an issue with the conditional scanner, but with the way processDefines emitted a single string-valued macro. I'll need to swing by and check in more detail, but we may be able to close this.

mwichmann avatar Mar 21 '23 15:03 mwichmann

Okay, reran the test case attached here, it still fails, but can be made to pass by:

-        env = DummyEnvironment(CPPDEFINES=['HEADER=\\"f9.h\\"'])
+        env = DummyEnvironment(CPPDEFINES=[('HEADER', '\\"f9.h\\"')])

So there may still be a CPPDEFINES hole here.

mwichmann avatar Mar 21 '23 17:03 mwichmann

The hole is in SCons/Scanner/C/dictifyCPPDEFINES() - it does its own processing of defines, not using the processDefines routine the rest of SCons uses, and did not deal with "NAME=VALUE" strings, either as a solo value, or as a member of a sequence. (note this problem is not related to the large CPPDEFINES refactor, it was always possible to assign a single string or a string-in-a-list to CPPDEFINES, only after type conversion is triggered might you not have those anymore). I have a patch and some additional tests.

mwichmann avatar Mar 21 '23 19:03 mwichmann