From 577ea7fccda5427e98b530cbedbdb5e42084cf7a Mon Sep 17 00:00:00 2001 From: Mathew Robinson Date: Tue, 10 Dec 2019 18:26:43 +0000 Subject: [PATCH] SERVER-44729 Remove unneeded WhereIs IO from ninja generator --- site_scons/site_tools/ninja.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/site_scons/site_tools/ninja.py b/site_scons/site_tools/ninja.py index c4829dd22bc..3b9fc268226 100644 --- a/site_scons/site_tools/ninja.py +++ b/site_scons/site_tools/ninja.py @@ -29,6 +29,7 @@ NINJA_RULES = "__NINJA_CUSTOM_RULES" NINJA_CUSTOM_HANDLERS = "__NINJA_CUSTOM_HANDLERS" NINJA_BUILD = "NINJA_BUILD" NINJA_OUTPUTS = "__NINJA_OUTPUTS" +NINJA_WHEREIS_MEMO = {} __NINJA_RULE_MAPPING = {} # These are the types that get_command can do something with @@ -888,7 +889,25 @@ def ninja_noop(*_args, **_kwargs): def ninja_whereis(thing, *_args, **_kwargs): """Replace env.WhereIs with a much faster version""" - return shutil.which(thing) + global NINJA_WHEREIS_MEMO + + # Optimize for success, this gets called significantly more often + # when the value is already memoized than when it's not. + try: + return NINJA_WHEREIS_MEMO[thing] + except KeyError: + # We do not honor any env['ENV'] or env[*] variables in the + # generated ninja ile. Ninja passes your raw shell environment + # down to it's subprocess so the only sane option is to do the + # same during generation. At some point, if and when we try to + # upstream this, I'm sure a sticking point will be respecting + # env['ENV'] variables and such but it's actually quite + # complicated. I have a naive version but making it always work + # with shell quoting is nigh impossible. So I've decided to + # cross that bridge when it's absolutely required. + path = shutil.which(thing) + NINJA_WHEREIS_MEMO[thing] = path + return path class NinjaEternalTempFile(SCons.Platform.TempFileMunge):