Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue causing scanners to receive incorrect paths #3494

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/engine/SCons/PathList.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ def subst_path(self, env, target, source):
result = []
for type, value in self.pathlist:
if type == TYPE_STRING_SUBST:
value = env.subst(value, target=target, source=source,
conv=node_conv)
# We override conv below to use absolute paths when possible.
grossag marked this conversation as resolved.
Show resolved Hide resolved
# This avoids problems with relative paths when the target's
# working directory is different than the FS object's working
# directory.
value = env.subst(
value, target=target, source=source,
conv=lambda x: x.abspath if hasattr(x, 'abspath') else x)
if SCons.Util.is_Sequence(value):
result.extend(SCons.Util.flatten(value))
elif value:
Expand Down
42 changes: 42 additions & 0 deletions test/ScannerAbsPathCheck/fixture/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import sys
import SCons.Scanner

sdk_root = None

def verify_paths(node, env, scanpaths, arg):
"""Verifies that the paths provided are as expected."""
global sdk_root
sdk_root_subdir = os.path.join(sdk_root, 'sdk_subdir')
if len(scanpaths) != 2:
raise Exception('Expected two entries in scanpaths')
if scanpaths[0].abspath != sdk_root:
raise Exception('Expected first scanpath=%s, got %s.' %
(sdk_root, scanpaths[0].abspath))
if scanpaths[1].abspath != sdk_root_subdir:
raise Exception('Expected second scanpath=%s, got %s.' %
(sdk_root_subdir, scanpaths[1].abspath))
return []

# Create a scanner that generates a path using the variables in env['PYPATH'].
pyscan = Scanner(name='pythonfile',
function=verify_paths,
argument=None,
path_function=SCons.Scanner.FindPathDirs('PYPATH'),
skeys=['.py'])

# Create a builder that uses that scanner.
b = Builder(action='$PYTHON $SOURCE', source_scanner=pyscan)

env = Environment(BUILDERS={'DummyPythonBuilder': b})

# Now set some variables that are needed by the scanner and/or the SConscript.
env.Replace(
PYTHON=sys.executable,
PYPATH=['$SDKROOT', '$SDKROOT/sdk_subdir'],
SDKROOT=env.Dir('sdk'),
)
sdk_root = env['SDKROOT'].abspath

Export('env')
SConscript('subdir/SConscript', exports='env')
2 changes: 2 additions & 0 deletions test/ScannerAbsPathCheck/fixture/subdir/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Import('env')
env.DummyPythonBuilder(target=['foo'], source=['empty.py'])
Empty file.
Empty file.
46 changes: 46 additions & 0 deletions test/ScannerAbsPathCheck/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

"""
This test verifies that a scanner retrieves the correct paths when
path_function is set to SCons.Scanner.FindPathDirs(some_var) and env[some_var]
contains paths relative to the SConstruct root.
"""

import TestSCons

test = TestSCons.TestSCons()

test.dir_fixture('fixture')
test.run()

test.pass_test()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4: