diff options
Diffstat (limited to 'SCons/Scanner/C.py')
-rw-r--r-- | SCons/Scanner/C.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/SCons/Scanner/C.py b/SCons/Scanner/C.py index 418454ff6..31ab7e62e 100644 --- a/SCons/Scanner/C.py +++ b/SCons/Scanner/C.py @@ -21,7 +21,12 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -"""Dependency scanner for C/C++ code.""" +"""Dependency scanner for C/C++ code. + +Two scanners are defined here: the default CScanner, and the optional +CConditionalScanner, which must be explicitly selected by calling +add_scanner() for each affected suffix. +""" import SCons.Node.FS import SCons.cpp @@ -62,11 +67,30 @@ class SConsCPPScanner(SCons.cpp.PreProcessor): return '' def dictify_CPPDEFINES(env) -> dict: - """Returns CPPDEFINES converted to a dict.""" + """Returns CPPDEFINES converted to a dict. + + This should be similar to :func:`~SCons.Defaults.processDefines`. + Unfortunately, we can't do the simple thing of calling that routine and + passing the result to the dict() constructor, because it turns the defines + into a list of "name=value" pairs, which the dict constructor won't + consume correctly. Also cannot just call dict on CPPDEFINES itself - it's + fine if it's stored in the converted form (currently deque of tuples), but + CPPDEFINES could be in other formats too. + + So we have to do all the work here - keep concepts in sync with + ``processDefines``. + """ cppdefines = env.get('CPPDEFINES', {}) result = {} if cppdefines is None: return result + + if SCons.Util.is_Tuple(cppdefines): + try: + return {cppdefines[0]: cppdefines[1]} + except IndexError: + return {cppdefines[0]: None} + if SCons.Util.is_Sequence(cppdefines): for c in cppdefines: if SCons.Util.is_Sequence(c): @@ -85,15 +109,18 @@ def dictify_CPPDEFINES(env) -> dict: # don't really know what to do here result[c] = None return result + if SCons.Util.is_String(cppdefines): try: name, value = cppdefines.split('=') return {name: value} except ValueError: return {cppdefines: None} - if not SCons.Util.is_Dict(cppdefines): - return {cppdefines: None} - return cppdefines + + if SCons.Util.is_Dict(cppdefines): + return cppdefines + + return {cppdefines: None} class SConsCPPScannerWrapper: """The SCons wrapper around a cpp.py scanner. |