Exemple #1
0
    def __init__(self, build_root: Optional[str] = None) -> None:
        self.linuxbrew_dir = None
        self.linuxbrew_link_target = None
        self.cellar_glibc_dir = None
        self.ldd_path = None
        self.ld_so_path = None
        self.patchelf_path = None

        find_linuxbrew_cmd_line = [
            os.path.join(YB_SRC_ROOT, 'build-support', 'find_linuxbrew.sh')
        ]
        if build_root:
            find_linuxbrew_cmd_line.extend(['--build-root', build_root])

        linuxbrew_dir = subprocess.check_output(
            find_linuxbrew_cmd_line).decode('utf-8').strip()
        # If the find_linuxbrew.sh script returns nothing, Linuxbrew is not being used.
        if not linuxbrew_dir:
            return

        if not os.path.isdir(linuxbrew_dir):
            raise IOError(
                f"Linuxbrew directory does not exist: {linuxbrew_dir}. "
                f"Command used to find it: {find_linuxbrew_cmd_line}")
        self.linuxbrew_dir = os.path.realpath(linuxbrew_dir)

        # Directories derived from the Linuxbrew top-level one.
        self.linuxbrew_link_target = os.path.realpath(linuxbrew_dir)
        self.cellar_glibc_dir = safe_path_join(
            [self.linuxbrew_dir, 'Cellar', 'glibc'])
        self.ldd_path = safe_path_join([self.linuxbrew_dir, 'bin', 'ldd'])
        self.ld_so_path = safe_path_join([self.linuxbrew_dir, 'lib', 'ld.so'])
        self.patchelf_path = safe_path_join(
            [self.linuxbrew_dir, 'bin', 'patchelf'])
Exemple #2
0
    def __init__(self, build_root=None):
        old_build_root = os.environ.get('BUILD_ROOT')
        if build_root is not None:
            os.environ['BUILD_ROOT'] = build_root
        else:
            build_root = os.environ.get('BUILD_ROOT')
        self.linuxbrew_dir = None
        self.linuxbrew_link_target = None
        self.cellar_glibc_dir = None
        self.ldd_path = None
        self.ld_so_path = None
        self.patchelf_path = None

        try:
            find_script_result = run_program(
                os.path.join(YB_SRC_ROOT, 'build-support',
                             'find_linuxbrew.sh'))
            linuxbrew_dir = find_script_result.stdout.strip()
            if not linuxbrew_dir:
                return
            if not os.path.isdir(linuxbrew_dir) and os.path.exists(
                    '/etc/centos-release'):
                raise RuntimeError((
                    "Directory returned by the '{}' script does not exist: '{}'. "
                    + "This is only an error on CentOS. Details: {}").format(
                        find_script_result.program_path, linuxbrew_dir,
                        find_script_result))
            self.linuxbrew_dir = os.path.realpath(linuxbrew_dir)

            # Directories derived from the Linuxbrew top-level one.
            self.linuxbrew_link_target = os.path.realpath(linuxbrew_dir)
            self.cellar_glibc_dir = safe_path_join(self.linuxbrew_dir,
                                                   'Cellar', 'glibc')
            self.ldd_path = safe_path_join(self.linuxbrew_dir, 'bin', 'ldd')
            self.ld_so_path = safe_path_join(self.linuxbrew_dir, 'lib',
                                             'ld.so')
            self.patchelf_path = safe_path_join(self.linuxbrew_dir, 'bin',
                                                'patchelf')
        finally:
            if old_build_root is None:
                if 'BUILD_ROOT' in os.environ:
                    del os.environ['BUILD_ROOT']
            else:
                os.environ['BUILD_ROOT'] = old_build_root
RESOLVED_DEP_RE = re.compile(r'^\s*(\S+)\s+=>\s+(\S.*\S)\s+[(]')

SYSTEM_LIBRARY_PATH_RE = re.compile(r'^/(usr|lib|lib64)/.*')
SYSTEM_LIBRARY_PATHS = [
    '/usr/lib',
    '/usr/lib64',
    '/lib',
    '/lib64',
    # This is used on Ubuntu
    '/usr/lib/x86_64-linux-gnu',
    '/lib/x86_64-linux-gnu'
]

HOME_DIR = os.path.expanduser('~')
LINUXBREW_HOME = get_linuxbrew_dir()
LINUXBREW_CELLAR_GLIBC_DIR = safe_path_join(LINUXBREW_HOME, 'Cellar', 'glibc')
ADDITIONAL_LIB_NAME_GLOBS = ['libnss_*', 'libresolv*']
LINUXBREW_LDD_PATH = safe_path_join(LINUXBREW_HOME, 'bin', 'ldd')

YB_SCRIPT_BIN_DIR = os.path.join(YB_SRC_ROOT, 'bin')
YB_BUILD_SUPPORT_DIR = os.path.join(YB_SRC_ROOT, 'build-support')

PATCHELF_NOT_AN_ELF_EXECUTABLE = 'not an ELF executable'
PATCHELF_PATH = safe_path_join(LINUXBREW_HOME, 'bin', 'patchelf')

LIBRARY_PATH_RE = re.compile('^(.*[.]so)(?:$|[.].*$)')
LIBRARY_CATEGORIES = ['system', 'yb', 'yb-thirdparty', 'linuxbrew']

# This is an alternative to global variables, bundling a few commonly used things.
DistributionContext = collections.namedtuple(
    'DistributionContext', ['build_dir', 'dest_dir', 'verbose_mode'])
# A resolved shared library dependency shown by ldd.
# Example (split across two lines):
#   libmaster.so => /home/mbautin/code/yugabyte/build/debug-gcc-dynamic/lib/libmaster.so
#   (0x00007f941fa5f000)
RESOLVED_DEP_RE = re.compile(r'^\s*(\S+)\s+=>\s+(\S.*\S)\s+[(]')

SYSTEM_LIBRARY_PATH_RE = re.compile(r'^/(usr|lib|lib64)/.*')
SYSTEM_LIBRARY_PATHS = ['/usr/lib', '/usr/lib64', '/lib', '/lib64',
                        # This is used on Ubuntu
                        '/usr/lib/x86_64-linux-gnu',
                        '/lib/x86_64-linux-gnu']

HOME_DIR = os.path.expanduser('~')
LINUXBREW_HOME = get_linuxbrew_dir()
LINUXBREW_CELLAR_GLIBC_DIR = safe_path_join(LINUXBREW_HOME, 'Cellar', 'glibc')
ADDITIONAL_LIB_NAME_GLOBS = ['libnss_*', 'libresolv*']
LINUXBREW_LDD_PATH = safe_path_join(LINUXBREW_HOME, 'bin', 'ldd')

YB_SCRIPT_BIN_DIR = os.path.join(YB_SRC_ROOT, 'bin')
YB_BUILD_SUPPORT_DIR = os.path.join(YB_SRC_ROOT, 'build-support')

PATCHELF_NOT_AN_ELF_EXECUTABLE = 'not an ELF executable'
PATCHELF_PATH = safe_path_join(LINUXBREW_HOME, 'bin', 'patchelf')

LIBRARY_PATH_RE = re.compile('^(.*[.]so)(?:$|[.].*$)')
LIBRARY_CATEGORIES = ['system', 'yb', 'yb-thirdparty', 'linuxbrew']


# This is an alternative to global variables, bundling a few commonly used things.
DistributionContext = collections.namedtuple(