forked from bootlin/buildroot-external-st
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_project_config.py
185 lines (149 loc) · 5.7 KB
/
parse_project_config.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import os
import re
import sys
import xml.etree.ElementTree as ET
from sys import argv as arg
#
# the goal is to parse project configs files to get
# list of files to compile
# cflags
# ldflags
#
# convert path and checks that path is valid
#
def fullpath(filename):
# workaround: there is a mistake in some projects
p=filename.replace("STM32_USB_HOST_Library","STM32_USB_Host_Library")
# some path contain windows style
p=p.replace("\\","/")
# contains space at the end
p=p.replace(" ","")
# is enclosed in double quotes
p=filename.replace("\"","")
# get absolute path
p=os.path.abspath(p);
# check if path is valid
#print("check path: "+p)
if os.path.exists(p)!=True:
print("prj: "+prj)
print("original path: "+filename)
sys.stderr.write("error check path: "+p+" fails\n")
exit(1);
return p
print("start")
# arg1: path of the project
prj=arg[1]
# arg2: name of the build configuration
buildconfig=arg[2]
# arg3: root of the compilation
myroot=arg[3]
confdir=myroot+"/out/"+buildconfig+"/conf"
print("prj: "+prj)
print("myroot: "+myroot)
print("confdir: "+confdir)
print("buildconfig: "+buildconfig)
os.chdir(prj)
proj_tree = ET.parse(".project")
cproj_tree = ET.parse(".cproject")
if os.path.exists(confdir)!=True:
os.mkdir(confdir)
if prj.find("(")!=-1:
print("bad prj path")
sys.stderr.write("bad prj path: "+prj+"\n")
exit(1)
#
# get the source code file list
#
print("file list")
f=open(confdir+"/config.in", 'w')
root = proj_tree.getroot()
f.write("CSRC += \\\n")
for i in root.iter('link'):
a=i.find('locationURI')
if a==None:
a=i.find('location')
if a==None:
print("could not find any file")
exit(1)
if a.text is None:
print("no text")
else:
#print("text:"+a.text)
temp=a.text
if ((temp.find(".txt")==-1) & (temp.find(".gdb")==-1) & (temp.find(".launch")==-1) & (temp.find(".sh")==-1) & (temp.find("README")==-1)):
# Format locationURI value
if re.search(r'\$\%7BPARENT-.-PROJECT_LOC\%7D', temp):
temp = re.sub('\$\%7BPARENT-(.)-PROJECT_LOC\%7D', r'PARENT-\1-PROJECT_LOC', temp)
elif re.search(r'\$\%7BPROJECT_LOC\%7D', temp):
temp = re.sub('\$\%7BPROJECT_LOC\%7D', r'PROJECT_LOC', temp)
temp=temp.replace("PARENT-0-PROJECT_LOC/", "./")
temp=temp.replace("PARENT-1-PROJECT_LOC/", "../")
temp=temp.replace("PARENT-2-PROJECT_LOC/", "../../")
temp=temp.replace("PARENT-3-PROJECT_LOC/", "../../../")
temp=temp.replace("PARENT-4-PROJECT_LOC/", "../../../../")
temp=temp.replace("PARENT-5-PROJECT_LOC/", "../../../../../")
temp=temp.replace("PARENT-6-PROJECT_LOC/", "../../../../../../")
temp=temp.replace("PARENT-7-PROJECT_LOC/", "../../../../../../../")
temp=temp.replace("PROJECT_LOC/", "../")
#print(temp)
temp=fullpath(temp)
f.write(temp+" \\\n")
f.write("\n")
cflags=""
ldlibs=""
ldscript=""
root = cproj_tree.getroot()
count=0
for j in root.iter('configuration'):
temp=j.get('name')
if temp == buildconfig:
for i in j.iter('option'):
a=i.get('superClass')
if a == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths':
for j in i.iter('listOptionValue'):
temp=j.get('value')
if temp != "":
temp=temp.replace("\\","/")
# New workaround to override value when configured with ${workspace_loc:/${ProjName}/xxx}
temp = re.sub('\$\{[^:]*:/\$\{[^\}]*\}([^\}]*)\}', r'..\1', temp)
#workaround remove first occurence of "../"
temp=temp.replace("../", "",1)
temp=fullpath(temp)
#print(temp)
cflags=cflags+" -I"+temp+" \\\n"
if a == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols':
for j in i.iter('listOptionValue'):
temp=j.get('value')
if temp != "":
#print(temp)
cflags=cflags+" '-D"+temp+"' \\\n"
if a == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script':
temp=i.get('value')
# New workaround to override value when configured with ${workspace_loc:/${ProjName}/xxx}
temp = re.sub('\$\{[^:]*:/\$\{[^\}]*\}([^\}]*)\}', r'..\1', temp)
temp=temp.replace("../", "",1)
temp=fullpath(temp)
#print(temp)
ldscript=temp
if a == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories':
for j in i.iter('listOptionValue'):
temp=j.get('value')
# New workaround to override value when configured with ${workspace_loc:/${ProjName}/xxx}
temp = re.sub('\$\{[^:]*:/\$\{[^\}]*\}([^\}]*)\}', r'..\1', temp)
temp=temp.replace("../", "",1)
temp=fullpath(temp)
ldlibs=ldlibs+" -L"+temp+"/"
if a == 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries':
for j in i.iter('listOptionValue'):
temp=j.get('value')
ldlibs=ldlibs+" -l"+temp
print("cflags="+cflags)
f.write("CFLAGS += "+cflags+"\n")
f.write("\n")
print("ldlibs="+ldlibs)
f.write("LDLIBS += "+ldlibs+"\n")
f.write("\n")
f.write("LDSCRIPT += "+ldscript+"\n")
f.write("\n")
f.close();
print("exit")