From 701ffd2746fbabe4d1908abbcb4a2d29eaf688f4 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 2 Mar 2019 17:27:31 -0800 Subject: copy logic from lex to find win_bison if installed via chocolatey --- src/engine/SCons/Tool/yacc.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/engine/SCons/Tool/yacc.py b/src/engine/SCons/Tool/yacc.py index cd9b9a8..5db49d3 100644 --- a/src/engine/SCons/Tool/yacc.py +++ b/src/engine/SCons/Tool/yacc.py @@ -41,6 +41,7 @@ import SCons.Tool import SCons.Util from SCons.Platform.mingw import MINGW_DEFAULT_PATHS from SCons.Platform.cygwin import CYGWIN_DEFAULT_PATHS +from SCons.Platform.win32 import CHOCO_DEFAULT_PATH YaccAction = SCons.Action.Action("$YACCCOM", "$YACCCOMSTR") @@ -97,6 +98,28 @@ def ymEmitter(target, source, env): def yyEmitter(target, source, env): return _yaccEmitter(target, source, env, ['.yy'], '$YACCHXXFILESUFFIX') +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. + """ + # 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: + bin_path = SCons.Tool.find_program_path( + env, + prog, + default_paths=CHOCO_DEFAULT_PATH + MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS ) + if bin_path: + if not append_paths: + env['ENV']['PATH'] = envPath + else: + 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') + def generate(env): """Add Builders and construction variables for yacc to an Environment.""" c_file, cxx_file = SCons.Tool.createCFileBuilders(env) @@ -124,7 +147,12 @@ def generate(env): else: SCons.Warnings.Warning('yacc tool requested, but bison binary not found in ENV PATH') - env['YACC'] = env.Detect('bison') or 'yacc' + if sys.platform == 'win32': + get_yacc_path(env, append_paths=True) + env["YACC"] = env.Detect(['bison', 'yacc', 'win_bison']) + else: + env["YACC"] = env.Detect(["bison", "yacc"]) + env['YACCFLAGS'] = SCons.Util.CLVar('') env['YACCCOM'] = '$YACC $YACCFLAGS -o $TARGET $SOURCES' env['YACCHFILESUFFIX'] = '.h' -- cgit v0.12