diff options
author | Daniel <dmoody256@gmail.com> | 2019-02-16 17:10:29 (GMT) |
---|---|---|
committer | Daniel <dmoody256@gmail.com> | 2019-02-16 17:10:29 (GMT) |
commit | 9eb21f94e0490e8e7811f1033ea146acac0b7c34 (patch) | |
tree | 6079fea4ffb2bc0040d13c152107dc04ff1a06b1 | |
parent | f296600dd858fa07ef144fbcbf4ee36bc308abf3 (diff) | |
download | SCons-9eb21f94e0490e8e7811f1033ea146acac0b7c34.zip SCons-9eb21f94e0490e8e7811f1033ea146acac0b7c34.tar.gz SCons-9eb21f94e0490e8e7811f1033ea146acac0b7c34.tar.bz2 |
update lex tool to find paths on windows
-rwxr-xr-x | src/CHANGES.txt | 5 | ||||
-rw-r--r-- | src/engine/SCons/Tool/lex.py | 44 | ||||
-rw-r--r-- | test/LEX/live.py | 18 |
3 files changed, 57 insertions, 10 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 0d02ec0..bfea661 100755 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -19,6 +19,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Change the default for AppendENVPath to delete_existing=0, so path order will not be changed, unless explicitly set (Issue #3276) - Fixed bug which threw error when running SCons on windows system with no MSVC installed. + - Update link tool to convert target to node before accessing node member + - Update mingw tool to remove MSVC like nologo CCFLAG + - Update lex tool to work in mingw environments From Mats Wichmann: - Quiet open file ResourceWarnings on Python >= 3.6 caused by @@ -42,8 +45,6 @@ RELEASE 3.0.4 - Mon, 20 Jan 2019 22:49:27 +0000 Issues #3268 & Issue #3222 - Initial support for ARM targets with Visual Studio 2017 - Issue #3182 (You must set TARGET_ARCH for this to work) - Update TempFileMunge class to use PRINT_CMD_LINE_FUNC - - Update link tool to convert target to node before accessing node member - - Update mingw tool to remove MSVC like nologo CCFLAG From Tobias Herzog - Enhance cpp scanner regex logic to detect if/elif expressions without whitespaces but diff --git a/src/engine/SCons/Tool/lex.py b/src/engine/SCons/Tool/lex.py index 280c768..732c0da 100644 --- a/src/engine/SCons/Tool/lex.py +++ b/src/engine/SCons/Tool/lex.py @@ -34,10 +34,13 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path +import sys import SCons.Action import SCons.Tool import SCons.Util +from SCons.Platform.mingw import MINGW_DEFAULT_PATHS +from SCons.Platform.cygwin import CYGWIN_DEFAULT_PATHS LexAction = SCons.Action.Action("$LEXCOM", "$LEXCOMSTR") @@ -64,10 +67,42 @@ def lexEmitter(target, source, env): target.append(fileName) return (target, source) +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. + """ + # save existing path to reset if we don't want to append any paths + envPath = env['ENV']['PATH'] + + lex = SCons.Tool.find_program_path(env, 'lex', default_paths=MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS ) + if lex: + if not append_paths: + env['ENV']['PATH'] = envPath + else: + lex_bin_dir = os.path.dirname(lex) + env.AppendENVPath('PATH', lex_bin_dir) + return lex + + flex = SCons.Tool.find_program_path(env, 'flex', default_paths=MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS ) + if flex: + if not append_paths: + env['ENV']['PATH'] = envPath + else: + flex_bin_dir = os.path.dirname(flex) + env.AppendENVPath('PATH', flex_bin_dir) + return flex + else: + 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 lex to an Environment.""" c_file, cxx_file = SCons.Tool.createCFileBuilders(env) + if sys.platform == 'win32': + get_lex_path(env, append_paths=True) + # C c_file.add_action(".l", LexAction) c_file.add_emitter(".l", lexEmitter) @@ -82,13 +117,16 @@ def generate(env): # C++ cxx_file.add_action(".ll", LexAction) cxx_file.add_emitter(".ll", lexEmitter) - - env["LEX"] = env.Detect("flex") or "lex" + + env["LEX"] = env.Detect("flex") or "lex" env["LEXFLAGS"] = SCons.Util.CLVar("") env["LEXCOM"] = "$LEX $LEXFLAGS -t $SOURCES > $TARGET" def exists(env): - return env.Detect(["flex", "lex"]) + if sys.platform == 'win32': + return get_lex_path(env) + else: + return env.Detect(["flex", "lex"]) # Local Variables: # tab-width:4 diff --git a/test/LEX/live.py b/test/LEX/live.py index 3d697d5..853e97c 100644 --- a/test/LEX/live.py +++ b/test/LEX/live.py @@ -28,6 +28,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Test LEX and LEXFLAGS with a live lex. """ +import sys + import TestSCons _exe = TestSCons._exe @@ -40,15 +42,24 @@ lex = test.where_is('lex') or test.where_is('flex') if not lex: test.skip_test('No lex or flex found; skipping test.\n') +tools = "'default'" +if sys.platform == 'win32': + # make sure mingw is installed on win32 + if not test.where_is('gcc'): + test.skip_test('No mingw on windows; skipping test.\n') + # lex on win32 has a dependencies on mingw for unix headers + # so add it as a tool to the environment. + tools += ", 'mingw'" test.file_fixture('wrapper.py') test.write('SConstruct', """ -foo = Environment() +foo = Environment(tools=[%(tools)s]) lex = foo.Dictionary('LEX') bar = Environment(LEX = r'%(_python_)s wrapper.py ' + lex, - LEXFLAGS = '-b') + LEXFLAGS = '-b', + tools=[%(tools)s]) foo.Program(target = 'foo', source = 'foo.l') bar.Program(target = 'bar', source = 'bar.l') """ % locals()) @@ -82,9 +93,6 @@ test.must_not_exist(test.workpath('lex.backup')) test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n") - - - test.run(arguments = 'bar' + _exe) test.must_match(test.workpath('wrapper.out'), "wrapper.py\n") |