maui.py
3.9 KB
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
import os, sys
import os.path
#
# To speed up the peroformance, we will cache the mcu folder.
#
mcu_path = ''
#
# This function print error message and exit the program with error code -1.
#
def error_exit(*msg):
print >> sys.stderr, '-' * 79
print >> sys.stderr, "Error:", " ".join(msg)
print >> sys.stderr, '-' * 79
sys.exit(-1)
#
# This function return project root path,
# for example: T:\_Dbg\LIBRA35_DEMO_gprs(FTE).09B_W10.07\mcu
#
def get_mcu_path():
global mcu_path
if mcu_path:
return mcu_path
try:
folder = os.path.dirname(__file__)
except:
folder = os.path.abspath('.')
paths = folder.split('\\')
while paths:
if paths[-1].lower() == 'mcu' or os.path.exists(os.path.join("\\".join(paths), "plutommi")):
mcu_path = "\\".join(paths)
return mcu_path
paths = paths[:-1]
# there is no mcu folder, check there are plutommi folder
root = folder[:3]
if os.path.exists(os.path.join(root, "plutommi")):
return root
error_exit('Cannot find root path:', folder)
#
# This function return the custom name,
# for example: LIBRA35_DEMO
#
def get_custom_name():
# check ENV first
try:
value = os.environ['MTK_PROJECT_PATH']
if value != '':
return value
except KeyError:
pass
# check 'make.ini'
mcu = get_mcu_path()
make_ini = os.path.join(mcu, "make.ini")
if not os.path.exists(make_ini):
error_exit('Cannot find make.ini')
for ln in file(make_ini):
try:
key, value = [i.strip() for i in ln.strip().split("=")]
except:
continue
if (not key) or (not value):
continue
if key == 'custom':
return value
error_exit('Cannot detect custom name')
#
# This function return the project name,
# for example: LIBRA35_DEMO
#
def get_project_name():
mcu = get_mcu_path()
make_ini = os.path.join(mcu, "make.ini")
if not os.path.exists(make_ini):
error_exit('Cannot find make.ini')
for ln in file(make_ini):
try:
key, value = [i.strip() for i in ln.strip().split("=")]
except:
continue
if (not key) or (not value):
continue
if key == 'project':
return value
error_exit('Cannot detect project name')
#
# This function will detect the project setting (make.ini) and return the build path,
# for example: T:\_Dbg\LIBRA35_DEMO_gprs(FTE).09B_W10.07\mcu\build\LIBRA35_DEMO
#
def get_build_path():
mcu = get_mcu_path()
custom_path = os.path.join(mcu, 'build', get_custom_name())
if not os.path.exists(custom_path):
error_exit('Build path is not existed:', custom_path)
return custom_path
#
# This function will detect the project setting (make.ini) and return the project path,
# for example: T:\_Dbg\LIBRA35_DEMO_gprs(FTE).09B_W10.07\mcu\build\LIBRA35_DEMO\gprs
#
def get_project_path():
mcu = get_mcu_path()
project_path = os.path.join(mcu, 'build', get_custom_name(), get_project_name())
if not os.path.exists(project_path):
error_exit('Project path is not existed:', project_path)
return project_path
#
# This function will detect timestamp, check whether need to rebuild the output file.
#
def check_need_rebuild(output, inputs):
try:
# in windows, the min modify time resolution is 2 sec, we need to fix it.
output_mtime = os.path.getmtime(output) + 1
except WindowsError:
# Cannot find output file
return True
for fn in inputs:
try:
if os.path.getmtime(fn) > output_mtime:
return True
except WindowsError:
# the input file is not exist? rebuild it.
return True
return False