Beispiel #1
0
def detect_clang_compilation_opts(source_files):
    opts = ""
    for source_file in source_files:
        test_compile = exe + " -c " + source_file + " -v"
        (out, er, ex, t) = system.system_call(test_compile, ".")
        if (ex == 0):
            return extract_opts(er.decode('utf-8'))
    return opts
Beispiel #2
0
source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(
    tmpdir_path, '.cpp')
dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path,
                                                       "invalid_extern_1.c")
    infer = exe + " run -- gcc -c " + source_file
    (output, err, exit, time) = system.system_call(infer, tmpdir_path)
    dirutils.tool_exec_log(temp_path, infer, output, err, exit)
    sys.stdout = open(csv, "a")
    report_file = os.path.join(tmpdir_path, "infer-out", "report.json")
    if (os.path.exists(report_file)):
        with open(report_file) as json_report_file:
            data = json.load(json_report_file)
        for d in data:
            print(d['file'].strip(), ",", str(d['line']), ",",
                  "\"" + d['qualifier'] + "\"")
    sys.stdout = sys.__stdout__
    shutil.rmtree(os.path.dirname(report_file))

print("[CLEANUP]: removing ", tmpdir_path)
shutil.rmtree(tmpdir_path)
print("======[DONE WITH INFER]=======")
Beispiel #3
0
dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(
    tmpdir_path, '.cpp')
for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path,
                                                       "invalid_extern_1.c")
    uno = exe + " " + opts + " " + source_file
    (output, err, exit, time) = system.system_call(uno, tmpdir_path)
    dirutils.tool_exec_log(temp_path, uno, output, err, exit)
    lines = output.splitlines()
    sys.stdout = open(csv, "a")
    for line in lines:
        a = line.decode("utf-8").strip().split(":")
        if (len(a) >= 4) and (a[0] == 'uno'):
            if len(
                    a[2]
            ) > 10:  # hack to work around bug in printint wrong array indexing
                print(os.path.basename(a[1]), ",",
                      ''.join(takewhile(str.isdigit, a[2].strip())), ",", a[2])
            else:
                print(os.path.basename(a[1]), ",", a[2], ",", a[3])
    sys.stdout = sys.__stdout__
Beispiel #4
0
print("[EXE OPTIONS]:", opts)

source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(
    tmpdir_path, '.cpp')
dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path,
                                                       "invalid_extern_1.c")
    cpplint = exe + " " + source_file
    (output, err, exit, time) = system.system_call(cpplint, tmpdir_path)
    dirutils.tool_exec_log(temp_path, cpplint, output, err, exit)
    sys.stdout = open(csv, "a")
    lines = err.splitlines()
    for line in lines:
        a = line.decode("utf-8").strip().split(":")
        if (len(a) >= 3):
            message = a[2]
            print(os.path.basename(a[0]), ",", a[1], ",", message)
    sys.stdout = sys.__stdout__

print("[CLEANUP]: removing ", tmpdir_path)
shutil.rmtree(tmpdir_path)
print("======[DONE WITH CPPLINT]=======")
Beispiel #5
0
source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(
    tmpdir_path, '.cpp')

dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path,
                                                       "invalid_extern_1.c")
    framac = exe + " -val -quiet " + source_file + " main.c"
    (output, err, exit, time) = system.system_call(framac, tmpdir_path)
    dirutils.tool_exec_log(temp_path, framac, output, err, exit)
    sys.stdout = open(csv, "a")
    lines = output.splitlines()
    i = 0
    while i < len(lines):
        line = lines[i].decode("utf-8")
        if (line[0] == '['):
            j = line.find("]")
            if (j != -1):
                parsed = line[j + 1:].split(':')
                if (len(parsed) >= 3):
                    fname = parsed[0].strip()
                    line_no = parsed[1].strip()
                    message = parsed[2].strip()
                    if (i + 1 < len(lines)):
Beispiel #6
0
hfile2 = os.path.join(tmpdir_path, "HeaderFile.hx")
copyfile(hfile2, hfile1);

dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(tmpdir_path, '.cpp')
for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path, "invalid_extern_1.c")
    sparse = exe + " " + source_file + " " + opts;
    (output, err, exit, time) = system.system_call(sparse, tmpdir_path)
    dirutils.tool_exec_log(temp_path, sparse, output, err, exit)
    lines = err.splitlines();
    sys.stdout = open(csv, "a")
    for line in lines:
        a = line.decode("utf-8").strip().split(":")
        if (len(a) >= 4):
            message = a[3]
            i = 4
            while (i < len(a)):
                message = message + ":" + a[i]
                i = i + 1
            print(os.path.basename(a[0]), ",", a[1], ",", message)
    sys.stdout = sys.__stdout__
    
print("[CLEANUP]: removing ", tmpdir_path)
source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(
    tmpdir_path, '.cpp')

dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path,
                                                       "invalid_extern_1.c")
    cppcheck = exe + opts + " " + source_file + " --output-file=" + xml_report_path
    (output, err, exit, time) = system.system_call(cppcheck, ".")
    dirutils.tool_exec_log(temp_path, cppcheck, output, err, exit)
    tree = ET.parse(xml_report_path)
    root = tree.getroot()
    errors = root[1]
    sys.stdout = open(csv, "a")
    for error in errors:
        msg = "\"" + error.attrib['verbose'] + "\""
        for location in error:
            if (location.tag == "location"):
                print(
                    os.path.basename(location.attrib['file']) + ",",
                    location.attrib['line'] + ",", msg)
    sys.stdout = sys.__stdout__

print("[CLEANUP]: removing ", tmpdir_path)
Beispiel #8
0
print("[EXE OPTIONS]:", opts)

source_files = dirutils.list_files(tmpdir_path, '.cpp')
sys_opts = "" if (platform.system() != 'Linux') else " -I /usr/include -I /usr/include/x86_64-linux-gnu/ -I /usr/lib/clang/6.0/include"

dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path, "invalid_extern_1.c")
    clang = exe + " " + opts + " " + sys_opts + " " + source_file
    (output, err, exit, time) = system.system_call(clang, ".")
    dirutils.tool_exec_log(temp_path, clang, output, err, exit)
    sys.stdout = open(csv, "a")
    lines = err.splitlines()
    for line in lines:
        parsed = line.decode("utf-8").strip().split(":")
        if (len(parsed) >= 4):
            print(os.path.basename(parsed[0]), ",", parsed[1], ",", parsed[3] + ":" + parsed[4])
    sys.stdout = sys.__stdout__


print("[CLEANUP]: removing ", tmpdir_path)
shutil.rmtree(tmpdir_path)
print("======[DONE WITH CLANG++]=======")
Beispiel #9
0
source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(
    tmpdir_path, '.cpp')
dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path,
                                                       "invalid_extern_1.c")
    flawfinder = exe + " " + source_file
    (output, err, exit, time) = system.system_call(flawfinder, tmpdir_path)
    dirutils.tool_exec_log(temp_path, flawfinder, output, err, exit)

    all_lines = output.splitlines()
    lines = []
    line_codes = []
    collect_flag = False
    for line in all_lines:
        dec = line.decode("utf-8").strip()
        if (collect_flag):
            lines.append(dec)
            if (len(dec.split(":")) >= 3):
                line_codes.append(True)
            else:
                line_codes.append(False)
        if dec == "FINAL RESULTS:":
Beispiel #10
0
print("[EXE OPTIONS]:", opts)

source_files = dirutils.list_files(tmpdir_path, '.c') + dirutils.list_files(
    tmpdir_path, '.cpp')
dirutils.file_line_error_header(csv)
dirutils.reset_file(temp_path)

for source_file in source_files:
    if source_file.endswith("main.c"):
        continue
    if source_file.endswith("invalid_extern_1.c"):
        continue
    if source_file.endswith("invalid_extern.c"):
        source_file = source_file + " " + os.path.join(tmpdir_path,
                                                       "invalid_extern_1.c")
    flintpp = exe + " " + opts + " " + source_file
    (output, err, exit, time) = system.system_call(flintpp, tmpdir_path)
    dirutils.tool_exec_log(temp_path, flintpp, output, err, exit)
    data = json.loads(output.decode("utf-8"))
    sys.stdout = open(csv, "a")
    for f in data['files']:
        filename = f['path']
        for error in f['reports']:
            print(os.path.basename(filename), ",", error['line'], ",",
                  error['title'])
    sys.stdout = sys.__stdout__

print("[CLEANUP]: removing ", tmpdir_path)
shutil.rmtree(tmpdir_path)
print("======[DONE WITH FLINT++]=======")