def __init__(self, build_root):
        self.build_root = build_root

        self.pg_build_root = os.path.join(build_root, 'postgres_build')
        self.pg_build_root_aliases = get_absolute_path_aliases(
            self.pg_build_root)

        self.postgres_src_root = os.path.join(YB_SRC_ROOT, 'src', 'postgres')
Esempio n. 2
0
    def __init__(self, build_root: str, extra_args: List[str],
                 add_original_dir_to_path_for_files: Set[str]) -> None:
        self.build_root = build_root

        self.pg_build_root = os.path.join(build_root, 'postgres_build')
        self.pg_build_root_aliases = get_absolute_path_aliases(
            self.pg_build_root)

        self.postgres_src_root = os.path.join(YB_SRC_ROOT, 'src', 'postgres')

        self.extra_args = extra_args

        self.add_original_dir_to_path_for_files = add_original_dir_to_path_for_files
Esempio n. 3
0
    def set_env_vars(self, step: str) -> None:
        if step not in BUILD_STEPS:
            raise RuntimeError(
                ("Invalid step specified for setting env vars: must be in {}"
                 ).format(BUILD_STEPS))
        is_make_step = step == 'make'
        is_clang = self.compiler_type.startswith('clang')
        is_gcc = self.compiler_type.startswith('gcc')

        self.set_env_var('YB_PG_BUILD_STEP', step)
        self.set_env_var('YB_THIRDPARTY_DIR', self.thirdparty_dir)
        self.set_env_var('YB_SRC_ROOT', YB_SRC_ROOT)

        for var_name in ['CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'LDFLAGS_EX']:
            arg_value = getattr(self.args, var_name.lower())
            self.set_env_var(var_name, arg_value)

        additional_c_cxx_flags = [
            '-Wimplicit-function-declaration',
            '-Wno-error=unused-function',
            '-DHAVE__BUILTIN_CONSTANT_P=1',
            '-std=c11',
            '-Werror=implicit-function-declaration',
            '-Werror=int-conversion',
        ]

        if self.is_clang():
            additional_c_cxx_flags += [
                '-Wno-builtin-requires-header',
                '-Wno-shorten-64-to-32',
            ]

        if is_make_step:
            additional_c_cxx_flags += [
                '-Wall', '-Werror', '-Wno-error=unused-function'
            ]

            if self.build_type == 'release':
                if self.is_clang():
                    additional_c_cxx_flags += [
                        '-Wno-error=array-bounds',
                        '-Wno-error=gnu-designator',
                    ]
                if self.is_gcc():
                    additional_c_cxx_flags += ['-Wno-error=strict-overflow']

            if self.build_type == 'asan':
                additional_c_cxx_flags += [
                    '-fsanitize-recover=signed-integer-overflow',
                    '-fsanitize-recover=shift-base',
                    '-fsanitize-recover=shift-exponent'
                ]

        # Tell gdb to pretend that we're compiling the code in the $YB_SRC_ROOT/src/postgres
        # directory.
        additional_c_cxx_flags += [
            '-fdebug-prefix-map=%s=%s' % (build_path, source_path)
            for build_path in get_absolute_path_aliases(self.pg_build_root)
            for source_path in get_absolute_path_aliases(self.postgres_src_dir)
        ]

        if self.is_gcc():
            additional_c_cxx_flags.append('-Wno-error=maybe-uninitialized')

        for var_name in ['CFLAGS', 'CXXFLAGS']:
            os.environ[var_name] = filter_compiler_flags(
                os.environ.get(var_name, '') + ' ' +
                ' '.join(additional_c_cxx_flags),
                step,
                language='c' if var_name == 'CFLAGS' else 'c++')
        if step == 'make':
            self.adjust_cflags_in_makefile()

        for env_var_name in ['MAKEFLAGS']:
            if env_var_name in os.environ:
                del os.environ[env_var_name]

        compiler_wrappers_dir = os.path.join(YB_SRC_ROOT, 'build-support',
                                             'compiler-wrappers')
        self.set_env_var('CC', os.path.join(compiler_wrappers_dir, 'cc'))
        self.set_env_var('CXX', os.path.join(compiler_wrappers_dir, 'c++'))

        self.set_env_var(
            'LDFLAGS', re.sub(r'-Wl,--no-undefined', ' ',
                              os.environ['LDFLAGS']))
        self.set_env_var(
            'LDFLAGS',
            re.sub(r'-Wl,--no-allow-shlib-undefined', ' ',
                   os.environ['LDFLAGS']))

        self.append_to_env_var(
            'LDFLAGS', '-Wl,-rpath,' + os.path.join(self.build_root, 'lib'))

        if sys.platform != 'darwin':
            for ldflags_var_name in ['LDFLAGS', 'LDFLAGS_EX']:
                self.append_to_env_var(ldflags_var_name, '-lm')

        if is_verbose_mode():
            # CPPFLAGS are C preprocessor flags, CXXFLAGS are C++ flags.
            for env_var_name in [
                    'CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'LDFLAGS_EX',
                    'LIBS'
            ]:
                if env_var_name in os.environ:
                    logging.info("%s: %s", env_var_name,
                                 os.environ[env_var_name])

        self.remote_compilation_allowed = ALLOW_REMOTE_COMPILATION and is_make_step

        self.set_env_var(
            'YB_REMOTE_COMPILATION', '1' if
            (self.remote_compilation_allowed
             and self.build_uses_remote_compilation and step == 'make') else
            '0')

        self.set_env_var('YB_BUILD_TYPE', self.build_type)

        # Do not try to make rpaths relative during the configure step, as that may slow it down.
        self.set_env_var('YB_DISABLE_RELATIVE_RPATH',
                         '1' if step == 'configure' else '0')

        # We need to add this directory to PATH so Postgres build could find Bison.
        thirdparty_installed_common_bin_path = os.path.join(
            self.thirdparty_dir, 'installed', 'common', 'bin')
        os.environ['PATH'] = ':'.join([thirdparty_installed_common_bin_path] +
                                      self.original_path)

        if self.build_type == 'tsan':
            self.set_env_var('TSAN_OPTIONS',
                             os.getenv('TSAN_OPTIONS', '') + ' report_bugs=0')
            logging.info("TSAN_OPTIONS for Postgres build: %s",
                         os.getenv('TSAN_OPTIONS'))