Skip to content

Commit

Permalink
[#3336] do not add not-found tool paths
Browse files Browse the repository at this point in the history
When tool modules initialize, they check paths to decide if
the underlying tool is actually present.  The current checker adds
any "default paths" the caller may have supplied (locations like
mingw, cygwin, chocolatey install locations, etc.); if there is
match from this list, any previous default paths are also kept.
To avoid keeping these non-matching paths, restore the original PATH;
the caller is responsible for adding to PATH if necessary.
Docstring now says so.

Note lex and yacc tool modules seem to expect the path-modifying
behavior that's being gotten rid of - so they preseve the path
first and restore it after.  The change here won't break those,
but makes the extra behavior unneeded - could remove it.

Signed-off-by: Mats Wichmann <[email protected]>
  • Loading branch information
mwichmann committed Mar 28, 2019
1 parent 607c1a0 commit 0a89de3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

RELEASE VERSION/DATE TO BE FILLED IN LATER

From Mats Wichmann:
- Issue #3336 - paths were being added to PATH even if tools were not
found in those paths.

From John Doe:

- Whatever John Doe did.
Expand Down
25 changes: 14 additions & 11 deletions src/engine/SCons/Tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,28 +1318,31 @@ def tool_list(platform, env):

def find_program_path(env, key_program, default_paths=[]):
"""
Find the location of key_program and then return the path it was located at.
Checking the default install locations.
Mainly for windows where tools aren't all installed in /usr/bin,etc
:param env: Current Environment()
:param key_program: Program we're using to locate the directory to add to PATH.
Find the location of a tool using various means.
Mainly for windows where tools aren't all installed in /usr/bin, etc.
:param env: Current Construction Environment.
:param key_program: Tool to locate.
:param default_paths: List of additional paths this tool might be found in.
"""
# First search in the SCons path
path = env.WhereIs(key_program)
if (path):
if path:
return path
# then the OS path:

# Then in the OS path
path = SCons.Util.WhereIs(key_program)
if (path):
if path:
return path

# If that doesn't work try default location for mingw
# Finally, add the defaults and check again. Do not change
# ['ENV']['PATH'] permananetly, the caller can do that if needed.
save_path = env['ENV']['PATH']
for p in default_paths:
env.AppendENVPath('PATH', p)
path = env.WhereIs(key_program)
if not path:
env['ENV']['PATH'] = save_path
env['ENV']['PATH'] = save_path
return path

# Local Variables:
Expand Down
3 changes: 2 additions & 1 deletion src/engine/SCons/Tool/swig.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ def generate(env):

from SCons.Platform.mingw import MINGW_DEFAULT_PATHS
from SCons.Platform.cygwin import CYGWIN_DEFAULT_PATHS
from SCons.Platform.win32 import CHOCO_DEFAULT_PATH

if sys.platform == 'win32':
swig = SCons.Tool.find_program_path(env, 'swig', default_paths=MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS + [r'C:\ProgramData\chocolatey\bin'] )
swig = SCons.Tool.find_program_path(env, 'swig', default_paths=MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS + CHOCO_DEFAULT_PATH)
if swig:
swig_bin_dir = os.path.dirname(swig)
env.AppendENVPath('PATH', swig_bin_dir)
Expand Down

0 comments on commit 0a89de3

Please sign in to comment.