Esempio n. 1
0
 def write_compile_commands_file(self, compile_commands: List[Dict[str,
                                                                   Any]],
                                 subdir_name: str) -> str:
     out_path = get_compile_commands_file_path(self.build_root, subdir_name)
     pathlib.Path(os.path.dirname(out_path)).mkdir(parents=True,
                                                   exist_ok=True)
     write_json_file(
         json_data=compile_commands,
         output_path=out_path,
         description_for_log=f'{subdir_name} compilation commands')
     return out_path
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")
Esempio n. 3
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)