summaryrefslogtreecommitdiff
path: root/SCons/Scanner/C.py
diff options
context:
space:
mode:
Diffstat (limited to 'SCons/Scanner/C.py')
-rw-r--r--SCons/Scanner/C.py68
1 files changed, 54 insertions, 14 deletions
diff --git a/SCons/Scanner/C.py b/SCons/Scanner/C.py
index a066104e5..5fa1bbb9f 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
@@ -36,11 +41,11 @@ class SConsCPPScanner(SCons.cpp.PreProcessor):
by Nodes, not strings; 2) we can keep track of the files that are
missing.
"""
- def __init__(self, *args, **kwargs):
+ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.missing = []
- def initialize_result(self, fname):
+ def initialize_result(self, fname) -> None:
self.result = SCons.Util.UniqueList([fname])
def finalize_result(self, fname):
@@ -62,25 +67,60 @@ 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 {}
+ 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):
- result = {}
for c in cppdefines:
if SCons.Util.is_Sequence(c):
try:
result[c[0]] = c[1]
except IndexError:
- # it could be a one-item sequence
+ # could be a one-item sequence
result[c[0]] = None
+ elif SCons.Util.is_String(c):
+ try:
+ name, value = c.split('=')
+ result[name] = value
+ except ValueError:
+ result[c] = None
else:
+ # don't really know what to do here
result[c] = None
return result
- if not SCons.Util.is_Dict(cppdefines):
- return {cppdefines : None}
- return cppdefines
+
+ if SCons.Util.is_String(cppdefines):
+ try:
+ name, value = cppdefines.split('=')
+ return {name: value}
+ except ValueError:
+ return {cppdefines: None}
+
+ if SCons.Util.is_Dict(cppdefines):
+ return cppdefines
+
+ return {cppdefines: None}
class SConsCPPScannerWrapper:
"""The SCons wrapper around a cpp.py scanner.
@@ -91,7 +131,7 @@ class SConsCPPScannerWrapper:
evaluation of #if/#ifdef/#else/#elif lines.
"""
- def __init__(self, name, variable):
+ def __init__(self, name, variable) -> None:
self.name = name
self.path = FindPathDirs(variable)
@@ -145,12 +185,12 @@ class SConsCPPConditionalScanner(SCons.cpp.PreProcessor):
missing.
"""
- def __init__(self, *args, **kwargs):
+ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.missing = []
self._known_paths = []
- def initialize_result(self, fname):
+ def initialize_result(self, fname) -> None:
self.result = SCons.Util.UniqueList([fname])
def find_include_file(self, t):
@@ -188,7 +228,7 @@ class SConsCPPConditionalScannerWrapper:
evaluation of #if/#ifdef/#else/#elif lines.
"""
- def __init__(self, name, variable):
+ def __init__(self, name, variable) -> None:
self.name = name
self.path = FindPathDirs(variable)