diff options
author | William Deegan <bill@baddogconsulting.com> | 2019-03-03 00:59:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-03 00:59:30 (GMT) |
commit | ae0960e31030bf7c5e3a5bd2c1c543867fbc5f8b (patch) | |
tree | 10594aee7339bfc6b1aa39f1c3301542a9190270 /src/engine | |
parent | 87445ef897104a15f42be27cf9773d9fd11dca96 (diff) | |
parent | 7b192e7b4c92606ffe1b07adbb82bda039a17975 (diff) | |
download | SCons-ae0960e31030bf7c5e3a5bd2c1c543867fbc5f8b.zip SCons-ae0960e31030bf7c5e3a5bd2c1c543867fbc5f8b.tar.gz SCons-ae0960e31030bf7c5e3a5bd2c1c543867fbc5f8b.tar.bz2 |
Merge pull request #3290 from dmoody256/make_lex_tool_cross_platform
Add windows default paths to lex tool
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Platform/win32.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Tool/lex.py | 44 | ||||
-rw-r--r-- | src/engine/SCons/Tool/lex.xml | 9 | ||||
-rw-r--r-- | src/engine/SCons/Tool/msvc.py | 4 |
4 files changed, 58 insertions, 3 deletions
diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py index 2d40fb8..be30546 100644 --- a/src/engine/SCons/Platform/win32.py +++ b/src/engine/SCons/Platform/win32.py @@ -43,6 +43,10 @@ from SCons.Platform.virtualenv import ImportVirtualenv from SCons.Platform.virtualenv import ignore_virtualenv, enable_virtualenv import SCons.Util +CHOCO_DEFAULT_PATH = [ + r'C:\ProgramData\chocolatey\bin' +] + try: import msvcrt import win32api diff --git a/src/engine/SCons/Tool/lex.py b/src/engine/SCons/Tool/lex.py index 280c768..a63ddc9 100644 --- a/src/engine/SCons/Tool/lex.py +++ b/src/engine/SCons/Tool/lex.py @@ -34,10 +34,14 @@ 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 +from SCons.Platform.win32 import CHOCO_DEFAULT_PATH LexAction = SCons.Action.Action("$LEXCOM", "$LEXCOMSTR") @@ -64,6 +68,29 @@ 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'] + bins = ['flex', 'lex', 'win_flex'] + + 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 lex to an Environment.""" c_file, cxx_file = SCons.Tool.createCFileBuilders(env) @@ -83,12 +110,23 @@ def generate(env): cxx_file.add_action(".ll", LexAction) cxx_file.add_emitter(".ll", lexEmitter) - env["LEX"] = env.Detect("flex") or "lex" env["LEXFLAGS"] = SCons.Util.CLVar("") - env["LEXCOM"] = "$LEX $LEXFLAGS -t $SOURCES > $TARGET" + + if sys.platform == 'win32': + 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("") + env["LEXCOM"] = "$LEX $LEXUNISTD $LEXFLAGS -t $SOURCES > $TARGET" + else: + env["LEX"] = env.Detect(["flex", "lex"]) + 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/src/engine/SCons/Tool/lex.xml b/src/engine/SCons/Tool/lex.xml index 0388ee3..f933451 100644 --- a/src/engine/SCons/Tool/lex.xml +++ b/src/engine/SCons/Tool/lex.xml @@ -33,6 +33,7 @@ Sets construction variables for the &lex; lexical analyser. <item>LEX</item> <item>LEXFLAGS</item> <item>LEXCOM</item> +<item>LEXUNISTD</item> </sets> <uses> <item>LEXCOMSTR</item> @@ -78,4 +79,12 @@ General options passed to the lexical analyzer generator. </summary> </cvar> +<cvar name="LEXUNISTD"> +<summary> +<para> +Used only on windows environments to set a lex flag to prevent 'unistd.h' from being included. The default value is '--nounistd'. +</para> +</summary> +</cvar> + </sconsdoc> diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index 9f3c1fa..2352088 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -271,6 +271,10 @@ def generate(env): env['SHOBJPREFIX'] = '$OBJPREFIX' env['SHOBJSUFFIX'] = '$OBJSUFFIX' + # MSVC probably wont support unistd.h so default + # without it for lex generation + env["LEXUNISTD"] = SCons.Util.CLVar("--nounistd") + # Set-up ms tools paths msvc_setup_env_once(env) |