From ecc5dd6d71f6c67f7eea2a44facfac7a8871a635 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 3 Jul 2019 16:18:27 -0700 Subject: [PATCH] getdeps: move the guts of _compute_env to a helper in buildopts Summary: I want to use this logic outside of a builder implementation Reviewed By: pkaush Differential Revision: D16101914 fbshipit-source-id: db3c9ac6c84a92ab84a18dddb931953b0a51f127 --- build/fbcode_builder/getdeps/builder.py | 34 +------------------ build/fbcode_builder/getdeps/buildopts.py | 40 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index 9a7a899bf..fbdfd6b0a 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -86,39 +86,7 @@ class BuilderBase(object): def _compute_env(self, install_dirs): # CMAKE_PREFIX_PATH is only respected when passed through the # environment, so we construct an appropriate path to pass down - env = self.env.copy() - - lib_path = None - if self.build_opts.is_darwin(): - lib_path = "DYLD_LIBRARY_PATH" - elif self.build_opts.is_linux(): - lib_path = "LD_LIBRARY_PATH" - else: - lib_path = None - - for d in install_dirs: - add_path_entry(env, "CMAKE_PREFIX_PATH", d) - - pkgconfig = os.path.join(d, "lib/pkgconfig") - if os.path.exists(pkgconfig): - add_path_entry(env, "PKG_CONFIG_PATH", pkgconfig) - - # Allow resolving shared objects built earlier (eg: zstd - # doesn't include the full path to the dylib in its linkage - # so we need to give it an assist) - if lib_path: - for lib in ["lib", "lib64"]: - libdir = os.path.join(d, lib) - if os.path.exists(libdir): - add_path_entry(env, lib_path, libdir) - - # Allow resolving binaries (eg: cmake, ninja) and dlls - # built by earlier steps - bindir = os.path.join(d, "bin") - if os.path.exists(bindir): - add_path_entry(env, "PATH", bindir, append=False) - - return env + return self.build_opts.compute_env_for_install_dirs(install_dirs, env=self.env) class MakeBuilder(BuilderBase): diff --git a/build/fbcode_builder/getdeps/buildopts.py b/build/fbcode_builder/getdeps/buildopts.py index 9ea21e8fd..712c44bbc 100644 --- a/build/fbcode_builder/getdeps/buildopts.py +++ b/build/fbcode_builder/getdeps/buildopts.py @@ -16,7 +16,7 @@ import os import subprocess import tempfile -from .envfuncs import path_search +from .envfuncs import Env, add_path_entry, path_search from .platform import HostType, is_windows @@ -190,6 +190,44 @@ class BuildOptions(object): return {"build_dir": build_dir, "inst_dir": inst_dir, "hash": hash} + def compute_env_for_install_dirs(self, install_dirs, env=None): + if env: + env = env.copy() + else: + env = Env() + + lib_path = None + if self.is_darwin(): + lib_path = "DYLD_LIBRARY_PATH" + elif self.is_linux(): + lib_path = "LD_LIBRARY_PATH" + else: + lib_path = None + + for d in install_dirs: + add_path_entry(env, "CMAKE_PREFIX_PATH", d) + + pkgconfig = os.path.join(d, "lib/pkgconfig") + if os.path.exists(pkgconfig): + add_path_entry(env, "PKG_CONFIG_PATH", pkgconfig) + + # Allow resolving shared objects built earlier (eg: zstd + # doesn't include the full path to the dylib in its linkage + # so we need to give it an assist) + if lib_path: + for lib in ["lib", "lib64"]: + libdir = os.path.join(d, lib) + if os.path.exists(libdir): + add_path_entry(env, lib_path, libdir) + + # Allow resolving binaries (eg: cmake, ninja) and dlls + # built by earlier steps + bindir = os.path.join(d, "bin") + if os.path.exists(bindir): + add_path_entry(env, "PATH", bindir, append=False) + + return env + def list_win32_subst_letters(): output = subprocess.check_output(["subst"]).decode("utf-8")