forked from greensoftwarelab/Energy-Languages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_all.py
54 lines (47 loc) · 1.69 KB
/
compile_all.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
import sys, os
from subprocess import call, check_output, Popen, PIPE
from lazyme.string import color_print
path = '.'
action = 'compile'
def file_exists(file_path):
if not file_path:
return False
else:
return os.path.isfile(file_path)
def main():
for root, dirs, files in os.walk(path):
print('Checking ' + root)
makefile = os.path.join(root, "Makefile")
if file_exists(makefile):
cmd = 'cd ' + root + '; make ' + action
#cmd = 'ls -la'
pipes = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
std_out, std_err = pipes.communicate()
if (action == 'compile') | (action == 'run'):
if pipes.returncode != 0:
# an error happened!
err_msg = "%s. Code: %s" % (std_err.strip(), pipes.returncode)
color_print('[E] Error on ' + root + ': ', color='red', bold=True)
print(err_msg)
elif len(std_err):
# return code is 0 (no error), but we may want to
# do something with the info on std_err
# i.e. logger.warning(std_err)
color_print('[OK]', color='green')
else:
color_print('[OK]', color='green')
if action == 'measure':
call(['sleep', '5'])
if __name__ == '__main__':
if len(sys.argv) == 2:
act = sys.argv[1]
if (act == 'compile') | (act == 'run') | (act == 'clean') | (act == 'measure'):
color_print('Performing \"' + act + '\" action...', color='yellow', bold=True)
action = act
else:
color_print('Error: Unrecognized action \"' + act + '\"', color='red')
sys.exit(1)
else:
color_print('Performing \"compile\" action...', color='yellow', bold=True)
action = 'compile'
main()