summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Gross <grossag@vmware.com>2020-11-17 02:17:33 (GMT)
committerAdam Gross <grossag@vmware.com>2020-11-17 02:17:33 (GMT)
commita6fdbf0aa1320f4c2b6f4daa5b9496108d22e0cd (patch)
tree490e3e0526d7eb9f31832073bf5907700dffae49
parent55b41b5841aaf1f86d8a8380e0f8603b45bcc49f (diff)
downloadSCons-a6fdbf0aa1320f4c2b6f4daa5b9496108d22e0cd.zip
SCons-a6fdbf0aa1320f4c2b6f4daa5b9496108d22e0cd.tar.gz
SCons-a6fdbf0aa1320f4c2b6f4daa5b9496108d22e0cd.tar.bz2
Fix all tests
This change fixes all tests. It's still a a WIP change because I think the "imports" logic is wrong for file imports.
-rw-r--r--SCons/Scanner/Python.py22
-rw-r--r--test/Scanner/Python.py9
-rw-r--r--test/Scanner/Python/SConstruct15
-rw-r--r--test/Scanner/Python/to_be_copied/sconstest.skip0
4 files changed, 26 insertions, 20 deletions
diff --git a/SCons/Scanner/Python.py b/SCons/Scanner/Python.py
index ada575e..2d4a211 100644
--- a/SCons/Scanner/Python.py
+++ b/SCons/Scanner/Python.py
@@ -136,26 +136,24 @@ def scan(node, env, path=()):
# This allows us to cleanly respect the precedence order.
for search_path in search_paths:
paths = [search_path]
- # See if p/__init__.py exists.
- node = SCons.Node.FS.find_file(package_path, paths, verbose=True)
+ node = SCons.Node.FS.find_file(package_path, paths)
+ if not node:
+ node = SCons.Node.FS.find_file(module_path, paths)
+
if node:
nodes.append(node)
- else:
- node = SCons.Node.FS.find_file(module_path, paths, verbose=True)
- if node:
- nodes.append(node)
- if node:
# 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.
- if not is_relative and len(module_components) > 1:
- for i in range(len(module_components[:-1])):
- init_path = '/'.join(module_components[:i+1] + ['__init__.py'])
- init_node = SCons.Node.FS.find_file(init_path, paths, verbose=True)
- if init_node:
+ if not is_relative:
+ import_dirs = module_components
+ for i in range(len(import_dirs)):
+ init_path = '/'.join(import_dirs[:i+1] + ['__init__.py'])
+ init_node = SCons.Node.FS.find_file(init_path, paths)
+ if init_node and init_node not in nodes:
nodes.append(init_node)
# The import was found, so no need to keep iterating through
diff --git a/test/Scanner/Python.py b/test/Scanner/Python.py
index bb6e2c7..b5b3ae5 100644
--- a/test/Scanner/Python.py
+++ b/test/Scanner/Python.py
@@ -24,15 +24,18 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
-Template for end-to-end test file.
-Replace this with a description of the test.
+Functional test for the Python scanner. Validates that the scanner is able to
+find dynamically generated dependencies. The SConstruct copies in the
+dependencies and runs a script. The expected behavior is that the scanner
+picks up these dependencies, so SCons understands that the script shouldn't
+be run until the files are copied.
"""
import TestSCons
test = TestSCons.TestSCons()
test.dir_fixture('Python')
-test.run(arguments = '--debug=stacktrace .', stdout='')
+test.run(arguments = '.')
test.pass_test()
# Local Variables:
diff --git a/test/Scanner/Python/SConstruct b/test/Scanner/Python/SConstruct
index 732b55c..988cf60 100644
--- a/test/Scanner/Python/SConstruct
+++ b/test/Scanner/Python/SConstruct
@@ -1,11 +1,16 @@
import sys
env = Environment(tools=['python'])
-for source, target in [
- ('to_be_copied', 'package1'),
- ('to_be_copied', 'package2'),
-]:
- env.Command(env.Dir(target), env.Dir(source), Copy('$TARGET', '$SOURCE'))
+
+# Copy each file individually instead of copying the dir. This has the benefit
+# of establishing nodes in-memory for each of the resulting files, which helps
+# the scanner work correctly.
+srcDir = env.Dir('to_be_copied')
+for srcNode in srcDir.glob('*'):
+ for destDir in [env.Dir('package1'), env.Dir('package2')]:
+ env.Command(destDir.File(srcNode.name), srcNode,
+ 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
diff --git a/test/Scanner/Python/to_be_copied/sconstest.skip b/test/Scanner/Python/to_be_copied/sconstest.skip
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Scanner/Python/to_be_copied/sconstest.skip