From a8ab6af25819e27befe94ea38857f684f501a00c Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sat, 13 Apr 2019 11:38:28 -0600 Subject: [PATCH] [PR #3337] clean up lex and yacc tools Remove now unneeded code to save/restore the path, since the routine now does not modify the path. Signed-off-by: Mats Wichmann --- src/engine/SCons/Tool/lex.py | 19 +++++++++++-------- src/engine/SCons/Tool/yacc.py | 27 +++++++++++++++++---------- test/LEX/live_mingw.py | 2 +- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/engine/SCons/Tool/lex.py b/src/engine/SCons/Tool/lex.py index a63ddc9f25..91d50fda1c 100644 --- a/src/engine/SCons/Tool/lex.py +++ b/src/engine/SCons/Tool/lex.py @@ -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: @@ -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') @@ -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("") diff --git a/src/engine/SCons/Tool/yacc.py b/src/engine/SCons/Tool/yacc.py index 5db49d3509..07ba8dacdd 100644 --- a/src/engine/SCons/Tool/yacc.py +++ b/src/engine/SCons/Tool/yacc.py @@ -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: @@ -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.""" @@ -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"]) @@ -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 diff --git a/test/LEX/live_mingw.py b/test/LEX/live_mingw.py index 13e23429b7..d535065000 100644 --- a/test/LEX/live_mingw.py +++ b/test/LEX/live_mingw.py @@ -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')