-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
162 lines (139 loc) · 5.83 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/python3
# This file contains a script that will run the conversion tools on all files in this directory
# replace them, and then diff the output. All the programmer needs to do is run this script
import os
import sys
import fileinput
import subprocess
def update_script_locations(cconv_loc, include_loc, python_loc):
for line in fileinput.input("convert_all.sh", inplace=1):
if "CCONV=" in line:
line = "CCONV=" + cconv_loc
elif "INCLUDES=" in line:
line = "INCUDES=" + include_loc
sys.stdout.write(line)
for line in fileinput.input("update_database.py", inplace=1):
if "#!" in line:
line = "#!" + python_loc
sys.stdout.write(line)
for line in fileinput.input("replace.py", inplace=1):
if "#!" in line:
line = "#!" + python_loc
sys.stdout.write(line)
def run_diff_command(command, filename):
os.system(command)
addon = ""
if filename:
addon = "for the file {}".format(filename)
file = open("GIT_DIFF_GENERATOR.txt", "r")
empty = True
for line in file.readlines():
if(empty):
empty = False
print("\nThe following diffs were generated " + addon + "\n\n")
print(line)
if empty:
print("No diffs to report!")
os.system("rm GIT_DIFF_GENERATOR.txt")
def run_file_by_file(branch):
f = []
for file in os.listdir("./"):
if file.endswith(".c"):
f.extend(file)
for filename in f:
command = "git diff baseline-converted..baseline --output=GIT_DIFF_GENERATOR.txt -- {}".format(filename)
if branch=="sane-baseline": command = "git diff sane-baseline-converted..sane-baseline --output=GIT_DIFF_GENERATOR.txt -- {}".format(filename)
run_diff_command(command, filename)
# asking the user information about their path locations
print("Please provide the path to the cconv-standalone tool:")
cconv_loc = input("[CCONV LOCATION] > ") + "\n"
print("Please provide the path to the checkedc include directory:")
include_loc = input("[INCLUDE LOCATION] > ") + "\n"
print("Please provide the path to checked c's clang:")
clang_loc = input("[CLANG LOCATION] > ") + "\n"
print("Please provide the path to python (which python3 in a new tab)")
python_loc = input("[PYTHON LOCATION] > ") + "\n"
print("##########\t PHASE 1: checking out baseline \t##########")
os.system("git checkout baseline")
print("##########\tupdating scripts with new locations...\t##########")
update_script_locations(cconv_loc, include_loc, python_loc)
print("##########\tupdating the database with your locations...\t##########")
os.system("python3 update_database.py")
print("##########\trunning the conversion tool...\t##########")
os.system("sh convert_all.sh")
print("##########\treplacing the output\t##########")
os.system("python replace.py")
compiles = True
print("##########\tcompiling...\t##########")
out = subprocess.Popen(['make', 'CC={}'.format(clang_loc), '-i'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = out.communicate()
stdout = str(stdout)
if "error:" in stdout:
compiles = False
if not compiles:
print("\nFailure to compile!\n")
os.system("rm *.o")
### Interactive version of the diff checker for regressions : support coming soon
menu = """
####################################################################################
Press
[1]\tfor a raw diff between the latest conversion and your conversion
[2]\tfor a diff that goes through the files individually (skips files without diffs)
[<filename>]\tif you'd like to view a diff for a specific file
[q]\tto quit
####################################################################################
"""
print(menu)
choice = input("[CHOICE] > ").rstrip()
if choice=="1":
command = "git diff baseline-converted..baseline --output=GIT_DIFF_GENERATOR.txt -- '*.c' '*.h'"
run_diff_command(command, None)
elif choice=="2":
run_file_by_file("baseline")
elif choice=="q":
print("All done!")
print("OK, resetting everything now:")
# reset everything
os.system("git reset --HARD")
print("##########\t PHASE 2 : sane-baseline \t##########")
os.system("git checkout sane-baseline")
update_script_locations(cconv_loc, include_loc, python_loc)
print("##########\tupdating the database with your locations...\t##########")
os.system("python3 update_database.py")
print("##########\trunning the conversion tool...\t##########")
os.system("sh convert_all.sh")
print("##########\treplacing the output\t##########")
os.system("python replace.py")
compiles = True
print("##########\tcompiling...\t##########")
out = subprocess.Popen(['make', 'CC={}'.format(clang_loc), '-i'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = out.communicate()
stdout = str(stdout)
if "error:" in stdout:
compiles = False
if not compiles:
print("\nFailure to compile!\n")
os.system("rm *.o")
# reset everything
os.system("git reset --HARD")
print("##########\t PHASE 3 : sane-baseline with alltypes \t##########")
update_script_locations(cconv_loc, include_loc, python_loc)
for line in fileinput.input("convert_all.sh", inplace=1):
if "output-postfix" in line:
line = "-output-postfix=checked \\\n-alltypes \\"
sys.stdout.write(line)
print("##########\tupdating the database with your locations...\t##########")
os.system("python3 update_database.py")
print("##########\trunning the conversion tool...\t##########")
os.system("sh convert_all.sh")
print("##########\treplacing the output\t##########")
os.system("python replace.py")
print(menu)
choice = input("[CHOICE] > ").rstrip()
if choice=="1":
command = "git diff sane-baseline-converted..sane-baseline --output=GIT_DIFF_GENERATOR.txt -- '*.c' '*.h'"
run_diff_command(command, None)
elif choice=="2":
run_file_by_file("sane-baseline")
elif choice=="q":
print("All done!")