Ejemplo n.º 1
0
def filter_compile_commands(input_path, output_path, file_name_regex_str):
    compiled_re = re.compile(file_name_regex_str)
    input_cmds = read_json_file(input_path)
    output_cmds = [
        item for item in input_cmds
        if compiled_re.match(os.path.basename(item['file']))
    ]
    logging.info(
        "Filtered compilation commands from %d to %d entries using the regex %s",
        len(input_cmds), len(output_cmds), file_name_regex_str)
    write_json_file(output_cmds,
                    output_path,
                    description_for_log="filtered compilation commands file")
Ejemplo n.º 2
0
    def combine_compile_commands(self, compile_commands_files):
        """
        Combine compilation commands files from main and contrib subtrees of PostgreSQL, patch them
        so that they point to the original source directory, and concatenate with the main
        compilation commands file.
        """
        all_compile_commands_paths = compile_commands_files + [
            os.path.join(self.build_root, 'compile_commands.json')
        ]

        # -----------------------------------------------------------------------------------------
        # Combine raw compilation commands in a single file.
        # -----------------------------------------------------------------------------------------

        combined_raw_compile_commands = []
        for compile_commands_path in all_compile_commands_paths:
            combined_raw_compile_commands += read_json_file(
                compile_commands_path)

        write_json_file(
            combined_raw_compile_commands,
            os.path.join(self.build_root,
                         COMBINED_RAW_COMPILE_COMMANDS_FILE_NAME),
            description_for_log='combined raw compilation commands file')

        # -----------------------------------------------------------------------------------------
        # Combine post-processed compilation commands in a single file.
        # -----------------------------------------------------------------------------------------

        compile_command_processor = CompileCommandProcessor(self.build_root)
        combined_postprocessed_compile_commands = [
            compile_command_processor.postprocess_compile_command(item)
            for item in combined_raw_compile_commands
        ]

        combined_postprocessed_compile_commands_path = os.path.join(
            self.build_root, COMBINED_POSTPROCESSED_COMPILE_COMMANDS_FILE_NAME)

        write_json_file(combined_postprocessed_compile_commands,
                        combined_postprocessed_compile_commands_path,
                        description_for_log=
                        'combined postprocessed compilation commands file')

        create_compile_commands_symlink(
            combined_postprocessed_compile_commands_path, self.build_type)
Ejemplo n.º 3
0
    def write_compile_commands_files(
            self, pg_compile_commands_paths: List[str]) -> None:
        """
        Write various types of compilation command files across the following dimensions:
        - YugabyteDB distributed system C++ code ("YB") vs. PostgreSQL C code ("PG")
        - Raw vs. postprocessed. Postprocessed means the paths are adjusted to refer to the original
          source directory as opposed to equivalent files in the build directory, and the format is
          unified.
        """

        # Write files with raw compilation commands

        yb_compile_commands_path = os.path.join(self.build_root,
                                                'compile_commands.json')
        yb_raw_compile_commands = read_json_file(yb_compile_commands_path)
        self.write_compile_commands_file(yb_raw_compile_commands,
                                         compile_commands.YB_RAW_DIR_NAME)

        pg_raw_compile_commands = []
        for compile_commands_path in pg_compile_commands_paths:
            pg_raw_compile_commands += read_json_file(compile_commands_path)

        self.write_compile_commands_file(pg_raw_compile_commands,
                                         compile_commands.PG_RAW_DIR_NAME)

        combined_raw_compile_commands = yb_raw_compile_commands + pg_raw_compile_commands
        self.write_compile_commands_file(
            combined_raw_compile_commands,
            compile_commands.COMBINED_RAW_DIR_NAME)

        # Write similar files with postprocessed compilation commands.
        compile_command_processor = CompileCommandProcessor(
            self.build_root,
            extra_args=[f'-DDLSUFFIX="{self.args.shared_library_suffix}"'],
            add_original_dir_to_path_for_files=set(
                FILES_INCLUDING_GENERATED_FILES_FROM_SAME_DIR))

        yb_postprocessed_compile_commands = [
            compile_command_processor.postprocess_compile_command(item)
            for item in yb_raw_compile_commands
        ]
        self.write_compile_commands_file(
            yb_postprocessed_compile_commands,
            compile_commands.YB_POSTPROCESSED_DIR_NAME)

        pg_postprocessed_compile_commands = [
            compile_command_processor.postprocess_compile_command(item)
            for item in pg_raw_compile_commands
        ]
        self.write_compile_commands_file(
            pg_postprocessed_compile_commands,
            compile_commands.PG_POSTPROCESSED_DIR_NAME)

        combined_postprocessed_compile_commands = (
            yb_postprocessed_compile_commands +
            pg_postprocessed_compile_commands)
        combined_postprocessed_compile_commands_path = self.write_compile_commands_file(
            combined_postprocessed_compile_commands,
            compile_commands.COMBINED_POSTPROCESSED_DIR_NAME)

        create_compile_commands_symlink(
            combined_postprocessed_compile_commands_path)