Skip to content

Commit

Permalink
[PR #3337] clean up lex and yacc tools
Browse files Browse the repository at this point in the history
Remove now unneeded code to save/restore the path, since
the routine now does not modify the path.

Signed-off-by: Mats Wichmann <[email protected]>
  • Loading branch information
mwichmann committed Apr 13, 2019
1 parent 0a89de3 commit a8ab6af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
19 changes: 11 additions & 8 deletions src/engine/SCons/Tool/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ def lexEmitter(target, source, env):

def get_lex_path(env, append_paths=False):
"""
Find the a path containing the lex or flex binaries. If a construction
environment is passed in then append the path to the ENV PATH.
Find the path to the lex tool, searching several possible names
Only called in the Windows case, so the default_path
can be Windows-specific
:param env: current construction environment
:param append_paths: if set, add the path to the tool to PATH
:return: path to lex tool, if found
"""
# save existing path to reset if we don't want to append any paths
envPath = env['ENV']['PATH']
bins = ['flex', 'lex', 'win_flex']

for prog in bins:
Expand All @@ -83,9 +87,7 @@ def get_lex_path(env, append_paths=False):
prog,
default_paths=CHOCO_DEFAULT_PATH + MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS )
if bin_path:
if not append_paths:
env['ENV']['PATH'] = envPath
else:
if append_paths:
env.AppendENVPath('PATH', os.path.dirname(bin_path))
return bin_path
SCons.Warnings.Warning('lex tool requested, but lex or flex binary not found in ENV PATH')
Expand Down Expand Up @@ -113,7 +115,8 @@ def generate(env):
env["LEXFLAGS"] = SCons.Util.CLVar("")

if sys.platform == 'win32':
get_lex_path(env, append_paths=True)
# ignore the return - we do not need the full path here
_ = get_lex_path(env, append_paths=True)
env["LEX"] = env.Detect(['flex', 'lex', 'win_flex'])
if not env.get("LEXUNISTD"):
env["LEXUNISTD"] = SCons.Util.CLVar("")
Expand Down
27 changes: 17 additions & 10 deletions src/engine/SCons/Tool/yacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ def yyEmitter(target, source, env):

def get_yacc_path(env, append_paths=False):
"""
Find the a path containing the lex or flex binaries. If a construction
environment is passed in then append the path to the ENV PATH.
Find the path to the yacc tool, searching several possible names
Only called in the Windows case, so the default_path
can be Windows-specific
:param env: current construction environment
:param append_paths: if set, add the path to the tool to PATH
:return: path to yacc tool, if found
"""
# save existing path to reset if we don't want to append any paths
envPath = env['ENV']['PATH']
bins = ['bison', 'yacc', 'win_bison']

for prog in bins:
Expand All @@ -113,12 +117,11 @@ def get_yacc_path(env, append_paths=False):
prog,
default_paths=CHOCO_DEFAULT_PATH + MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS )
if bin_path:
if not append_paths:
env['ENV']['PATH'] = envPath
else:
if append_paths:
env.AppendENVPath('PATH', os.path.dirname(bin_path))
return bin_path
SCons.Warnings.Warning('lex tool requested, but lex or flex binary not found in ENV PATH')
SCons.Warnings.Warning('yacc tool requested, but yacc or bison binary not found in ENV PATH')


def generate(env):
"""Add Builders and construction variables for yacc to an Environment."""
Expand Down Expand Up @@ -148,7 +151,8 @@ def generate(env):
SCons.Warnings.Warning('yacc tool requested, but bison binary not found in ENV PATH')

if sys.platform == 'win32':
get_yacc_path(env, append_paths=True)
# ignore the return - we do not need the full path here
_ = get_yacc_path(env, append_paths=True)
env["YACC"] = env.Detect(['bison', 'yacc', 'win_bison'])
else:
env["YACC"] = env.Detect(["bison", "yacc"])
Expand All @@ -162,7 +166,10 @@ def generate(env):
env['YACCVCGFILESUFFIX'] = '.vcg'

def exists(env):
return env.Detect(['bison', 'yacc'])
if sys.platform == 'win32':
return get_yacc_path(env)
else:
return env.Detect(['bison', 'yacc'])

# Local Variables:
# tab-width:4
Expand Down
2 changes: 1 addition & 1 deletion test/LEX/live_mingw.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
test.skip_test('Not windows environment; skipping test.\n')

if not test.where_is('gcc'):
test.skip_test('No mingw or cygwin on windows; skipping test.\n')
test.skip_test('No mingw or cygwin build environment found; skipping test.\n')

lex = test.where_is('lex') or test.where_is('flex')

Expand Down

0 comments on commit a8ab6af

Please sign in to comment.