4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
20 def isBertosDir(directory):
21 return os.path.exists(directory + "/VERSION")
23 def bertosVersion(directory):
24 return open(directory + "/VERSION").readline().strip()
26 def createBertosProject(projectInfos):
27 directory = projectInfos.info("PROJECT_PATH")
28 sourcesDir = projectInfos.info("SOURCES_PATH")
29 if not os.path.isdir(directory):
31 f = open(directory + "/project.bertos", "w")
32 f.write(repr(projectInfos))
34 ## Destination source dir
35 srcdir = directory + "/bertos"
36 shutil.rmtree(srcdir, True)
37 shutil.copytree(sourcesDir + "/bertos", srcdir)
38 ## Destination makefile
39 makefile = directory + "/Makefile"
40 if os.path.exists(makefile):
42 shutil.copy(sourcesDir + "/Makefile", makefile)
43 ## Destination project dir
44 prjdir = directory + "/" + os.path.basename(directory)
45 shutil.rmtree(prjdir, True)
47 ## Destination configurations files
48 cfgdir = prjdir + "/cfg"
49 shutil.rmtree(cfgdir, True)
51 for key, value in projectInfos.info("CONFIGURATIONS").items():
52 string = open(sourcesDir + "/" + key, "r").read()
53 for parameter, infos in value.items():
54 value = infos["value"]
55 if "long" in infos["informations"].keys() and infos["informations"]["long"]:
57 string = sub(string, parameter, value)
58 f = open(cfgdir + "/" + os.path.basename(key), "w")
63 path = os.environ["PATH"]
65 path = path.split(";")
67 path = path.split(":")
70 def findToolchains(pathList):
72 for element in pathList:
73 for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
74 if not os.path.islink(toolchain):
75 toolchains.append(toolchain)
76 return list(set(toolchains))
78 def getToolchainInfo(output):
80 expr = re.compile("Target: .*")
81 target = expr.findall(output)
83 info["target"] = target[0].split("Target: ")[1]
84 expr = re.compile("gcc version [0-9,.]*")
85 version = expr.findall(output)
87 info["version"] = version[0].split("gcc version ")[1]
88 expr = re.compile("gcc version [0-9,.]* \(.*\)")
89 build = expr.findall(output)
91 build = build[0].split("gcc version ")[1]
92 build = build[build.find("(") + 1 : build.find(")")]
94 expr = re.compile("Configured with: .*")
95 configured = expr.findall(output)
96 if len(configured) == 1:
97 info["configured"] = configured[0].split("Configured with: ")[1]
98 expr = re.compile("Thread model: .*")
99 thread = expr.findall(output)
101 info["thread"] = thread[0].split("Thread model: ")[1]
104 def findDefinitions(ftype, path):
107 for filename in element[2]:
108 if fnmatch.fnmatch(filename, ftype):
109 yield (filename, element[0])
111 def loadCpuInfos(path):
113 for definition in findDefinitions(const.CPU_DEFINITION, path):
114 cpuInfos.append(getInfos(definition))
117 def getInfos(definition):
119 D.update(const.CPU_DEF)
120 def include(filename, dict = D, directory=definition[1]):
121 execfile(directory + "/" + filename, {}, D)
122 D["include"] = include
123 include(definition[0], D)
124 D["CPU_NAME"] = definition[0].split(".")[0]
125 D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
129 def getDefinitionBlocks(text):
131 Take a text and return a list of tuple (description, name-value).
134 block_tmp = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
135 for comment, define in block_tmp:
136 block.append((" ".join(re.findall(r"^\s*\*?\s*(.*?)\s*?(?:/{2}.*?)?$", comment, re.MULTILINE)).strip(), define))
137 block += re.findall(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
138 block += [(comment, define) for define, comment in re.findall(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)]
141 def formatParamNameValue(text):
143 Take the given string and return a tuple with the name of the parameter in the first position
144 and the value in the second.
146 block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
149 def getDescriptionInformations(text):
151 Take the doxygen comment and strip the wizard informations, returning the tuple
152 (comment, wizard_informations)
154 index = text.find("$WIZARD")
156 exec(text[index + 1:])
157 informations = WIZARD
158 return text[:index].strip(), informations
160 return text.strip(), {}
162 def loadConfigurationInfos(path):
164 Return the module configurations found in the given file as a dict with the
165 parameter name as key and a dict containig the fields above as value:
166 "value": the value of the parameter
167 "description": the description of the parameter
168 "informations": a dict containig optional informations:
169 "type": "int" | "boolean" | "enum"
170 "min": the minimum value for integer parameters
171 "max": the maximum value for integer parameters
172 "long": boolean indicating if the num is a long
173 "value_list": the name of the enum for enum parameters
175 configurationInfos = {}
176 for comment, define in getDefinitionBlocks(open(path, "r").read()):
177 name, value = formatParamNameValue(define)
178 description, informations = getDescriptionInformations(comment)
179 configurationInfos[name] = {}
180 configurationInfos[name]["value"] = value
181 configurationInfos[name]["informations"] = informations
182 configurationInfos[name]["description"] = description
183 return configurationInfos
185 def loadModuleInfos(path):
187 Return the module infos found in the given file as a dict with the module
188 name as key and a dict containig the fields above as value or an empty dict
189 if the given file is not a BeRTOS module:
190 "depends": a list of modules needed by this module
191 "configuration": the cfg_*.h with the module configurations
192 "description": a string containing the brief description of doxygen
193 "enabled": contains False but the wizard will change if the user select
197 string = open(path, "r").read()
198 commentList = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
199 commentList = [" ".join(re.findall(r"^\s*\*?\s*(.*?)\s*?(?:/{2}.*?)?$", comment, re.MULTILINE)).strip() for comment in commentList]
200 for comment in commentList:
201 index = comment.find("$WIZARD_MODULE")
203 exec(comment[index + 1:])
204 moduleInfos[WIZARD_MODULE["name"]] = {"depends": WIZARD_MODULE["depends"],
205 "configuration": WIZARD_MODULE["configuration"],
211 def loadModuleInfosDict(path):
213 Return the dict containig all the modules
216 for filename, path in findDefinitions("*.h", path):
217 moduleInfosDict.update(loadModuleInfos(path + "/" + filename))
218 return moduleInfosDict
220 def loadDefineLists(path):
222 Return a dict with the name of the list as key and a list of string as value
224 string = open(path, "r").read()
225 commentList = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
226 commentList = [" ".join(re.findall(r"^\s*\*?\s*(.*?)\s*?(?:/{2}.*?)?$", comment, re.MULTILINE)).strip() for comment in commentList]
228 for comment in commentList:
229 index = comment.find("$WIZARD_LIST")
231 exec(comment[index + 1:])
232 listDict.update(WIZARD_LIST)
235 def loadDefineListsDict(path):
237 Return the dict containing all the define lists
240 for filename, path in findDefinitions("*.h", path):
241 defineListsDict.update(loadDefineLists(path + "/" + filename))
242 return defineListsDict
244 def sub(string, parameter, value):
246 Substitute the given value at the given parameter define in the given string
248 return re.sub(r"(?P<define>#define\s+" + parameter + r"\s+)([^\s]+)", r"\g<define>" + value, string)