Exemple #1
0
def executeClangCheckOnFile(clang_tidy_path, database_path, file_path):
    error_count = 0
    log.LOG(log.Level.LOG, "Analyzing '{}' ...\n".format(file_path))
    process = Popen([clang_tidy_path, "-p", database_path, "--quiet", file_path], stdout=PIPE, stderr=PIPE)
    (output, err) = process.communicate()
    res = process.wait()

    buf = io.StringIO(output.decode('ascii'))
    output_lines = []

    line_str = buf.readline()
    while line_str:
        if line_str.isspace() or ("warnings generated" in line_str) or ("-header-filter=" in line_str):
            continue
        if ("warning:" in line_str) or ("error:" in line_str):
            error_count += 1
        output_lines.append(line_str) 
        line_str = buf.readline()

    if error_count != 0:
        log.LOG(log.Level.LOG, '\n'.join(output_lines))

    if res != 0:
        logProcessError(err)

    return error_count
Exemple #2
0
def ExecuteClangFormatOnDir(clang_format, dir_path, excludes):
    if os.path.isdir(dir_path):
        files = []
        extensions_with_dot = ["." + ext for ext in code.CPP_FILE_EXTENSIONS]
        file_system.FindFiles(files,
                              dirs=[dir_path],
                              extensions=extensions_with_dot)
        for file_iter in files:
            err = ExecuteClangFormatOnFile(clang_format_path, file_iter,
                                           excludes)
            if 0 != err:
                log.LOG(log.Level.ERROR,
                        "Failed to format {}".format(file_iter))
    else:
        log.LOG(log.Level.ERROR,
                "Cannot find engine source directory: {}".format(dir_path))
Exemple #3
0
def executeClangCheckOnDir(clang_tidy_path, database_path, dir_path, excludes):
    error_count = 0
    if os.path.isdir(dir_path):
        files = []
        file_system.FindFiles( files, dirs=[dir_path], extensions=['.cpp'] )

        for file_iter in files:
            matches = [exclude for exclude in excludes if re.match(exclude, file_iter, re.I) != None]
            if len(matches) == 0:
                error_count += executeClangCheckOnFile(clang_tidy_path, database_path, file_iter)
    else:
        log.LOG(log.Level.ERROR, "Cannot find directory '{}'".format(dir_path))

    return error_count
Exemple #4
0
def logProcessError(error):
    buf = io.StringIO(error.decode('unicode_escape'))
    lineStr = buf.readline()
    while lineStr:
        log.LOG(log.Level.ERROR, lineStr + "\n")
        lineStr = buf.readline()
Exemple #5
0
    if not options.excludes is None:
        excludes = options.excludes

    error_count = 0
    if os.path.isfile(clang_tidy_path):
        if options.analyze_engine :
            error_count += executeClangCheckOnDir(clang_tidy_path, options.database_path, host.GetEngineSrcDirPath(), excludes)
        if options.analyze_sample :
            error_count += executeClangCheckOnDir(clang_tidy_path, options.database_path, host.GetSampleSrcDirPath(), excludes)
        if options.analyze_test :
            error_count += executeClangCheckOnDir(clang_tidy_path, options.database_path, host.GetTestSrcDirPath(), excludes)
        if (not options.input_path is None):
            if os.path.exists(options.input_path):
                if os.path.isfile(options.input_path):
                    error_count += executeClangCheckOnFile(clang_tidy_path, options.database_path, options.input_path)
                elif os.path.isdir(options.input_path):
                    ExecuteClangFormatOnDir(options.input_path)
                else:
                    log.LOG(log.Level.ERROR, "{} is not a supported input path".format(options.input_path))
            else:
                log.LOG(log.Level.ERROR, "{} does not exist".format(options.input_path))
    else:
        log.LOG(log.Level.ERROR, "Cannot find clang-check executable: {}".format(clang_tidy_path))

    if error_count == 0:
        log.LOG(log.Level.LOG, "Clang static analyzis has finished successfully\n")
    else:
        log.LOG(log.Level.LOG, "Clang static analyzis has finished with {} error(s)\n", error_count)

    log.Exit()
Exemple #6
0
                                 host.GetEngineSrcDirPath(), excludes)
     if options.format_test:
         ExecuteClangFormatOnDir(clang_format_path,
                                 host.GetTestSrcDirPath(), excludes)
     if options.format_sample:
         ExecuteClangFormatOnDir(clang_format_path,
                                 host.GetSampleSrcDirPath(), excludes)
     if (not options.input_path is None):
         if os.path.exists(options.input_path):
             if os.path.isfile(options.input_path):
                 err = ExecuteClangFormatOnFile(clang_format_path,
                                                options.input_path,
                                                excludes)
                 if 0 != err:
                     log.LOG(
                         log.Level.ERROR,
                         "Failed to format {}".format(options.input_path))
             elif os.path.isdir(options.input_path):
                 ExecuteClangFormatOnDir(options.input_path, excludes)
             else:
                 log.LOG(
                     log.Level.ERROR,
                     "{} is not a supported input path".format(
                         options.input_path))
         else:
             log.LOG(log.Level.ERROR,
                     "{} does not exist".format(options.input_path))
 else:
     log.LOG(
         log.Level.ERROR, "Cannot find clang-format executable: {}".format(
             clang_format_path))