summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Gross <grossag@vmware.com>2020-11-16 15:17:58 (GMT)
committerAdam Gross <grossag@vmware.com>2020-11-16 15:17:58 (GMT)
commitfde36127ff949e7efbce321e7ace07707b35e41a (patch)
tree7db19f97751ccc1afafa250f851f00fc6ecda68f
parent28636490512924ce393ce324a61130d9d43fe54a (diff)
downloadSCons-fde36127ff949e7efbce321e7ace07707b35e41a.zip
SCons-fde36127ff949e7efbce321e7ace07707b35e41a.tar.gz
SCons-fde36127ff949e7efbce321e7ace07707b35e41a.tar.bz2
Some initial fixes
-rw-r--r--SCons/Node/FS.py6
-rw-r--r--SCons/Scanner/Python.py57
-rw-r--r--test/Scanner/Python.py2
-rw-r--r--test/Scanner/Python/SConstruct6
4 files changed, 37 insertions, 34 deletions
diff --git a/SCons/Node/FS.py b/SCons/Node/FS.py
index cc2e75a..369ec59 100644
--- a/SCons/Node/FS.py
+++ b/SCons/Node/FS.py
@@ -2664,8 +2664,6 @@ class File(Base):
def _morph(self):
"""Turn a file system node into a File object."""
self.scanner_paths = {}
- if self.abspath.endswith('package1'):
- raise Exception(self.abspath)
if not hasattr(self, '_local'):
self._local = 0
if not hasattr(self, 'released_target_info'):
@@ -3727,7 +3725,7 @@ class FileFinder:
def _find_file_key(self, filename, paths, verbose=None):
# Note: paths could be a list, which is not hashable. If it is, convert
- # it to a tuple.
+ # it to a tuple, which is hashable.
paths_entry = tuple(paths) if isinstance(paths, list) else paths
return (filename, paths_entry)
@@ -3778,8 +3776,6 @@ class FileFinder:
result = node
break
- print('value: %s (%s)' % (result, type(result)))
- print('key: %s (%s)' % (memo_key, type(memo_key)))
memo_dict[memo_key] = result
return result
diff --git a/SCons/Scanner/Python.py b/SCons/Scanner/Python.py
index 965b9c1..63f5035 100644
--- a/SCons/Scanner/Python.py
+++ b/SCons/Scanner/Python.py
@@ -116,33 +116,40 @@ def scan(node, env, path=()):
module_components = search_string.split('.')
module_joined = '/'.join(module_components)
- print('%s - %s' % (module_joined, [str(s) for s in search_paths]))
- node = SCons.Node.FS.find_file(module_joined, search_paths, verbose=True)
- if node:
- # The fact that we were able to find the node without appending .py
- # means that this is a directory import.
- nodes.append(env.Dir(node).File('__init__.py'))
-
- # Take a dependency on all __init__.py files from all imported
- # packages unless it's a relative import. If it's a relative
- # import, we don't need to take the dependency because Python
- # requires that all referenced packages have already been imported,
- # which means that the dependency has already been established.
- # XXX TODO: This part is broken and needs to be fixed.
- if not is_relative and len(module_components) > 1:
- import_dirs = module_components
- for i in range(len(import_dirs)):
- init_path = '/'.join(module_components[:i+1] + ['__init__.py'])
- # TODO: Passing search_paths is not correct.
- init_node = SCons.Node.FS.find_file(init_path, search_paths, verbose=True)
- if init_node:
- nodes.append(init_node)
- else:
- node = SCons.Node.FS.find_file(module_joined + '.py', search_paths, verbose=True)
+
+ # For an import of "p", it could either result in a directory named
+ # p or a file named p.py. We can't do two consecutive searches for p
+ # then p.py because the first search could return a result that is
+ # lower in the search_paths precedence order. As a result, it is safest
+ # to iterate over search_paths and check whether p or p.py exists in
+ # each path. This allows us to cleanly respect the precedence order.
+ for path in search_paths:
+ paths = [path]
+ node = SCons.Node.FS.find_file(module_joined, paths, verbose=True)
if node:
- nodes.append(node)
+ # The fact that we were able to find the node without appending .py
+ # means that this is a directory import.
+ nodes.append(env.Dir(node).File('__init__.py'))
+
+ # Take a dependency on all __init__.py files from all imported
+ # packages unless it's a relative import. If it's a relative
+ # import, we don't need to take the dependency because Python
+ # requires that all referenced packages have already been imported,
+ # which means that the dependency has already been established.
+ # XXX TODO: This part is broken and needs to be fixed.
+ if not is_relative and len(module_components) > 1:
+ import_dirs = module_components
+ for i in range(len(import_dirs)):
+ init_path = '/'.join(module_components[:i+1] + ['__init__.py'])
+ # TODO: Passing search_paths is not correct.
+ init_node = SCons.Node.FS.find_file(init_path, paths, verbose=True)
+ if init_node:
+ nodes.append(init_node)
+ else:
+ node = SCons.Node.FS.find_file(module_joined + '.py', paths, verbose=True)
+ if node:
+ nodes.append(node)
- print('nodes: %s' % [str(n) for n in nodes])
return sorted(nodes)
diff --git a/test/Scanner/Python.py b/test/Scanner/Python.py
index 74c8a87..404967c 100644
--- a/test/Scanner/Python.py
+++ b/test/Scanner/Python.py
@@ -32,7 +32,7 @@ import TestSCons
test = TestSCons.TestSCons()
test.dir_fixture('Python')
-test.run(arguments = '--debug=stacktrace .')
+test.run(arguments = '-n --tree=prune --debug=stacktrace .', stdout='')
test.pass_test()
# Local Variables:
diff --git a/test/Scanner/Python/SConstruct b/test/Scanner/Python/SConstruct
index 0466d37..732b55c 100644
--- a/test/Scanner/Python/SConstruct
+++ b/test/Scanner/Python/SConstruct
@@ -2,10 +2,10 @@ import sys
env = Environment(tools=['python'])
for source, target in [
- ('to_be_copied', 'package1'),
- ('to_be_copied', 'package2'),
+ ('to_be_copied', 'package1'),
+ ('to_be_copied', 'package2'),
]:
- env.Command(target, source, Copy('$TARGET', '$SOURCE'))
+ env.Command(env.Dir(target), env.Dir(source), Copy('$TARGET', '$SOURCE'))
# Don't set a dependency on the copy actions on purpose. Scanner should find
# the dependencies automatically.
env.Command('a.out', 'script.py', '$PYTHON $SOURCE $TARGET', PYTHON=sys.executable) \ No newline at end of file