def prepare(compile_command_json, sources_root):
    """
    Read a compile cmd json file and change all paths with a prefix
    (sources_root).  Returns the modified json data.
    """
    json_data = lib.load_json_file(compile_command_json)
    result_json = []
    sources_root_abs = os.path.abspath(sources_root)
    for entry in json_data:
        if not existsInSourcesRoot(entry, sources_root):
            continue

        entry['directory'] =\
            lib.change_paths(entry['directory'],
                             lib.IncludePathModifier(sources_root_abs))

        cmd = entry['command']
        compiler, compilerEnd = lib.find_path_end(cmd.lstrip(), 0)
        entry['command'] = compiler +\
            lib.change_paths(cmd[compilerEnd:],
                             lib.IncludePathModifier(sources_root_abs))

        entry['file'] =\
            lib.change_paths(entry['file'],
                             lib.IncludePathModifier(sources_root_abs))

        result_json.append(entry)
    return result_json
def prepare(compiler_includes_file, sources_root):
    json_data = lib.load_json_file(compiler_includes_file)
    new_json_data = dict()
    sources_root_abs = os.path.abspath(sources_root)
    for key, value in json_data.items():
        lines = value.split("\n")
        changed_lines = []
        for line in lines:
            changed_lines.append(
                lib.change_paths(line,
                                 lib.IncludePathModifier(sources_root_abs)))
        new_json_data[key] = "\n".join(changed_lines)
    return new_json_data
Exemple #3
0
def prepare(compile_command_json, sources_root):
    """
    Read a compile cmd json file and change all paths with a prefix
    (sources_root).  Returns the modified json data.
    """
    json_data = lib.load_json_file(compile_command_json)
    result_json = []
    sources_root_abs = os.path.abspath(sources_root)
    for entry in json_data:
        if not existsInSourcesRoot(entry, sources_root):
            continue

        entry['directory'] =\
            lib.change_paths(entry['directory'],
                             lib.IncludePathModifier(sources_root_abs))

        try:
            # This directory may not have been collected by the "failed log
            # collectory" script if it is empty. However the existence of this
            # directory is necessary for analysis.
            os.makedirs(entry['directory'])
        except OSError:
            pass

        cmd = entry['command']
        compiler, compilerEnd = lib.find_path_end(cmd.lstrip(), 0)
        entry['command'] = compiler +\
            lib.change_paths(cmd[compilerEnd:],
                             lib.IncludePathModifier(sources_root_abs))

        entry['file'] =\
            lib.change_paths(entry['file'],
                             lib.IncludePathModifier(sources_root_abs))

        result_json.append(entry)
    return result_json
def prepare(compiler_info_file, sources_root):
    json_data = lib.load_json_file(compiler_info_file)
    sources_root_abs = os.path.abspath(sources_root)
    new_json_data = dict()
    for compiler in json_data:
        lines = json_data[compiler]['includes']
        changed_lines = []
        for line in lines:
            changed_lines.append(
                lib.change_paths(line,
                                 lib.IncludePathModifier(sources_root_abs)))
        new_json_data[compiler] = {
            'includes': changed_lines,
            'target': json_data[compiler]['target'],
            'default_standard': json_data[compiler]['default_standard']
        }
    return new_json_data
def prepare(compiler_info_file, sources_root):
    json_data = lib.load_json_file(compiler_info_file)
    sources_root_abs = os.path.abspath(sources_root)
    new_json_data = dict()
    for compiler in json_data:
        lines = json_data[compiler]['includes']
        changed_lines = []
        for line in lines:
            changed_lines.append(
                lib.change_paths(line,
                                 lib.IncludePathModifier(sources_root_abs)))
        new_json_data[compiler] = {
            'includes': changed_lines,
            'target': json_data[compiler]['target'],
            'default_standard': json_data[compiler]['default_standard']
        }
    return new_json_data
def _try_prepare_as_new_format(compiler_info_file, sources_root):
    json_data = lib.load_json_file(compiler_info_file)
    sources_root_abs = os.path.abspath(sources_root)
    new_json_data = dict()

    for compiler_id_string in json_data:
        new_json_data[compiler_id_string] = dict()
        include_paths = json_data[compiler_id_string]['compiler_includes']
        changed_includes = [
            lib.change_paths(p, lib.IncludePathModifier(sources_root_abs))
            for p in include_paths
        ]

        new_json_data[compiler_id_string] = {
            'compiler_includes': changed_includes,
            'target': json_data[compiler_id_string]['target'],
            'compiler_standard':
            json_data[compiler_id_string]['compiler_standard']
        }
    return new_json_data
def _try_prepare_as_old_format(compiler_info_file, sources_root):
    json_data = lib.load_json_file(compiler_info_file)
    sources_root_abs = os.path.abspath(sources_root)
    new_json_data = dict()
    for compiler in json_data:
        new_json_data[compiler] = dict()
        for language in json_data[compiler]:
            lines = json_data[compiler][language]['compiler_includes']
            changed_lines = []
            for line in lines:
                changed_lines.append(
                    lib.change_paths(
                        line, lib.IncludePathModifier(sources_root_abs)))
            new_json_data[compiler][language] = {
                'compiler_includes':
                changed_lines,
                'target':
                json_data[compiler][language]['target'],
                'compiler_standard':
                json_data[compiler][language]['compiler_standard']
            }
    return new_json_data
def prepare(analyzer_command_file, pathOptions):
    res = lib.change_paths(get_first_line_of_file(analyzer_command_file),
                           AnalyzerCommandPathModifier(pathOptions))

    if '-nobuiltininc' not in res:
        return res

    # Find Clang include path
    clang_include_path = lib.get_resource_dir(pathOptions.clang) + '/include'

    if clang_include_path is None:
        clang_lib_path = os.path.dirname(pathOptions.clang) + '/../lib'
        clang_include_path = ''
        for path, _, files in os.walk(clang_lib_path):
            if 'stddef.h' in files:
                clang_include_path = path
                break

    if clang_include_path is None:
        return res

    return res.replace('-nobuiltininc',
                       '-nobuiltininc -isystem ' + clang_include_path)
def prepare(analyzer_command_file, pathOptions):
    res = lib.change_paths(get_first_line_of_file(analyzer_command_file),
                           AnalyzerCommandPathModifier(pathOptions))

    if '-nobuiltininc' not in res:
        return res

    # Find Clang include path
    clang_include_path = lib.get_resource_dir(pathOptions.clang) + '/include'

    if clang_include_path is None:
        clang_lib_path = os.path.dirname(pathOptions.clang) + '/../lib'
        clang_include_path = ''
        for path, _, files in os.walk(clang_lib_path):
            if 'stddef.h' in files:
                clang_include_path = path
                break

    if clang_include_path is None:
        return res

    return res.replace('-nobuiltininc',
                       '-nobuiltininc -isystem ' + clang_include_path)
def prepare(analyzer_command_file, pathOptions):
    res = lib.change_paths(get_first_line_of_file(analyzer_command_file),
                           AnalyzerCommandPathModifier(pathOptions))
    return res