From 561a284c512ab262ae669ceb2d26dee77f1c4bc1 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 12 Feb 2020 02:29:09 +0530 Subject: [PATCH] depfixer: Cache searching of install_name_tool This gives a significant speedup in large projects such as gst-build since now we only search for the tool once. Speed-up on Windows: ``` meson install: before: 15.3 seconds after: 5.4 seconds meson install --only-changed: before: 11.6 seconds after: 2.7 seconds ``` --- mesonbuild/scripts/depfixer.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py index 5be7d4038..969f1cc86 100644 --- a/mesonbuild/scripts/depfixer.py +++ b/mesonbuild/scripts/depfixer.py @@ -26,6 +26,9 @@ DT_STRTAB = 5 DT_SONAME = 14 DT_MIPS_RLD_MAP_REL = 1879048245 +# Global cache for tools +INSTALL_NAME_TOOL = False + class DataSizes: def __init__(self, ptrsize, is_le): if is_le: @@ -428,6 +431,7 @@ def fix_jar(fname): subprocess.check_call(['jar', 'ufm', fname, 'META-INF/MANIFEST.MF']) def fix_rpath(fname, new_rpath, final_path, install_name_mappings, verbose=True): + global INSTALL_NAME_TOOL # Static libraries never have rpaths if fname.endswith('.a'): return @@ -445,5 +449,11 @@ def fix_rpath(fname, new_rpath, final_path, install_name_mappings, verbose=True) pass else: raise - if shutil.which('install_name_tool'): + # We don't look for this on import because it will do a useless PATH lookup + # on non-mac platforms. That can be expensive on some Windows machines + # (upto 30ms), which is significant with --only-changed. For details, see: + # https://github.com/mesonbuild/meson/pull/6612#discussion_r378581401 + if INSTALL_NAME_TOOL is False: + INSTALL_NAME_TOOL = shutil.which('install_name_tool') + if INSTALL_NAME_TOOL: fix_darwin(fname, new_rpath, final_path, install_name_mappings)