import shutil
import const
+import codelite_project
import DefineException
def isBertosDir(directory):
string = open(sourcesDir + "/" + key, "r").read()
for parameter, infos in value.items():
value = infos["value"]
+ if "type" in infos["informations"] and infos["informations"]["type"] == "autoenabled":
+ value = "1"
if "unsigned" in infos["informations"].keys() and infos["informations"]["unsigned"]:
value += "U"
if "long" in infos["informations"].keys() and infos["informations"]["long"]:
makefile = open("mktemplates/template.mk", "r").read()
makefile = mkGenerator(projectInfo, makefile)
open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile)
+ ## Destination main.c file
+ main = open("srctemplates/main.c", "r").read()
+ open(prjdir + "/main.c", "w").write(main)
+ if "codelite" in projectInfo.info("OUTPUT"):
+ workspace = codeliteWorkspaceGenerator(projectInfo)
+ open(directory + "/" + os.path.basename(prjdir) + ".workspace", "w").write(workspace)
+ project = codeliteProjectGenerator(projectInfo)
+ open(directory + "/" + os.path.basename(prjdir) + ".project", "w").write(project)
def mkGenerator(projectInfo, makefile):
"""
"""
mkData = {}
mkData["$pname"] = os.path.basename(projectInfo.info("PROJECT_PATH"))
- mkData["$cpuname"] = projectInfo.info("CPU_INFOS")["CPU_NAME"]
+ mkData["$cpuname"] = projectInfo.info("CPU_INFOS")["CORE_CPU"]
mkData["$cflags"] = " ".join(projectInfo.info("CPU_INFOS")["C_FLAGS"])
mkData["$ldflags"] = " ".join(projectInfo.info("CPU_INFOS")["LD_FLAGS"])
- mkData["$csrc"] = csrcGenerator(projectInfo)
+ mkData["$csrc"], mkData["$pcsrc"], mkData["$constants"] = csrcGenerator(projectInfo)
+ mkData["$prefix"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[0]
+ mkData["$suffix"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[1]
+ mkData["$cross"] = projectInfo.info("TOOLCHAIN")["path"].split("gcc")[0]
+ mkData["$main"] = os.path.basename(projectInfo.info("PROJECT_PATH")) + "/main.c"
for key in mkData:
while makefile.find(key) != -1:
makefile = makefile.replace(key, mkData[key])
def csrcGenerator(projectInfo):
modules = projectInfo.info("MODULES")
- files = []
+ files = projectInfo.info("FILES")
+ if "harvard" in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
+ harvard = True
+ else:
+ harvard = False
+ ## file to be included in CSRC variable
+ csrc = []
+ ## file to be included in PCSRC variable
+ pcsrc = []
+ ## constants to be included at the beginning of the makefile
+ constants = {}
+ moduleFiles = set([])
+ dependencyFiles = set([])
+ ## assembly sources
+ asmFiles = set([])
for module, information in modules.items():
if information["enabled"]:
- for filename, path in findDefinitions(module + ".c", projectInfo):
- files.append(path + "/" + filename)
- for filename, path in findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo):
- files.append(path + "/" + filename)
- for tag in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
- for filename, path in findDefinitions(module + "_" + tag + ".c", projectInfo):
- files.append(path + "/" + filename)
- csrc = " \\\n\t".join(files)
- return csrc
+ if "constants" in information:
+ constants.update(information["constants"])
+ cfiles, sfiles = findModuleFiles(module, projectInfo)
+ moduleFiles |= set(cfiles)
+ asmFiles |= set(sfiles)
+ for fileDependency in information["depends"]:
+ if fileDependency in files:
+ dependencyCFiles, dependencySFiles = findModuleFiles(fileDependency, projectInfo)
+ dependencyFiles |= set(dependencyCFiles)
+ asmFiles |= set(dependencySFiles)
+ for file in moduleFiles:
+ if not harvard or "harvard" not in information or information["harvard"] == "both":
+ csrc.append(file)
+ if harvard and "harvard" in information:
+ pcsrc.append(file)
+ for file in dependencyFiles:
+ csrc.append(file)
+ csrc = " \\\n\t".join(csrc) + " \\"
+ pcsrc = " \\\n\t".join(pcsrc) + " \\"
+ constants = "\n".join([os.path.basename(projectInfo.info("PROJECT_PATH")) + "_" + key + " = " + str(value) for key, value in constants.items()])
+ return csrc, pcsrc, constants
+
+def findModuleFiles(module, projectInfo):
+ ## Find the files related to the selected module
+ cfiles = []
+ sfiles = []
+ ## .c files related to the module and the cpu architecture
+ for filename, path in findDefinitions(module + ".c", projectInfo) + \
+ findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ cfiles.append(path + "/" + filename)
+ ## .s files related to the module and the cpu architecture
+ for filename, path in findDefinitions(module + ".s", projectInfo) + \
+ findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".s", projectInfo) + \
+ findDefinitions(module + ".S", projectInfo) + \
+ findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".S", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ sfiles.append(path + "/" + filename)
+ ## .c and .s files related to the module and the cpu tags
+ for tag in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
+ for filename, path in findDefinitions(module + "_" + tag + ".c", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ cfiles.append(path + "/" + filename)
+ for filename, path in findDefinitions(module + "_" + tag + ".s", projectInfo) + \
+ findDefinitions(module + "_" + tag + ".S", projectInfo):
+ path = path.replace(projectInfo.info("SOURCES_PATH") + "/", "")
+ sfiles.append(path + "/" + filename)
+ return cfiles, sfiles
+
+def codeliteProjectGenerator(projectInfo):
+ template = open("cltemplates/bertos.project").read()
+ filelist = "\n".join(codelite_project.clFiles(codelite_project.findSources(projectInfo.info("PROJECT_PATH")), projectInfo.info("PROJECT_PATH")))
+ while template.find("$filelist") != -1:
+ template = template.replace("$filelist", filelist)
+ projectName = os.path.basename(projectInfo.info("PROJECT_PATH"))
+ while template.find("$project") != -1:
+ template = template.replace("$project", projectName)
+ return template
+
+def codeliteWorkspaceGenerator(projectInfo):
+ template = open("cltemplates/bertos.workspace").read()
+ projectName = os.path.basename(projectInfo.info("PROJECT_PATH"))
+ while template.find("$project") != -1:
+ template = template.replace("$project", projectName)
+ return template
def getSystemPath():
path = os.environ["PATH"]
toolchains = []
for element in pathList:
for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
- if not os.path.islink(toolchain):
- toolchains.append(toolchain)
+ toolchains.append(toolchain)
return list(set(toolchains))
def getToolchainInfo(output):
moduleDefinition["module_description"] = line[line.find("\\brief") + len("\\brief "):]
moduleDict = {}
if "module_name" in moduleDefinition.keys():
- moduleDict[moduleDefinition["module_name"]] = {}
- if "module_depends" in moduleDefinition.keys():
- if type(moduleDefinition["module_depends"]) == str:
- moduleDefinition["module_depends"] = (moduleDefinition["module_depends"],)
- moduleDict[moduleDefinition["module_name"]]["depends"] = moduleDefinition["module_depends"]
+ moduleName = moduleDefinition[const.MODULE_DEFINITION["module_name"]]
+ del moduleDefinition[const.MODULE_DEFINITION["module_name"]]
+ moduleDict[moduleName] = {}
+ if const.MODULE_DEFINITION["module_depends"] in moduleDefinition.keys():
+ if type(moduleDefinition[const.MODULE_DEFINITION["module_depends"]]) == str:
+ moduleDefinition[const.MODULE_DEFINITION["module_depends"]] = (moduleDefinition[const.MODULE_DEFINITION["module_depends"]],)
+ moduleDict[moduleName]["depends"] = moduleDefinition[const.MODULE_DEFINITION["module_depends"]]
+ del moduleDefinition[const.MODULE_DEFINITION["module_depends"]]
else:
- moduleDict[moduleDefinition["module_name"]]["depends"] = ()
- if "module_configuration" in moduleDefinition.keys():
- moduleDict[moduleDefinition["module_name"]]["configuration"] = moduleDefinition["module_configuration"]
+ moduleDict[moduleName]["depends"] = ()
+ if const.MODULE_DEFINITION["module_configuration"] in moduleDefinition.keys():
+ moduleDict[moduleName]["configuration"] = moduleDefinition[const.MODULE_DEFINITION["module_configuration"]]
+ del moduleDefinition[const.MODULE_DEFINITION["module_configuration"]]
else:
- moduleDict[moduleDefinition["module_name"]]["configuration"] = ""
+ moduleDict[moduleName]["configuration"] = ""
if "module_description" in moduleDefinition.keys():
- moduleDict[moduleDefinition["module_name"]]["description"] = moduleDefinition["module_description"]
- moduleDict[moduleDefinition["module_name"]]["enabled"] = False
+ moduleDict[moduleName]["description"] = moduleDefinition["module_description"]
+ del moduleDefinition["module_description"]
+ if const.MODULE_DEFINITION["module_harvard"] in moduleDefinition.keys():
+ harvard = moduleDefinition[const.MODULE_DEFINITION["module_harvard"]]
+ if harvard == "both" or harvard == "pgm_memory":
+ moduleDict[moduleName]["harvard"] = harvard
+ del moduleDefinition[const.MODULE_DEFINITION["module_harvard"]]
+ moduleDict[moduleName]["constants"] = moduleDefinition
+ moduleDict[moduleName]["enabled"] = False
return toBeParsed, moduleDict
def loadDefineLists(commentList):
Take the doxygen comment and strip the wizard informations, returning the tuple
(comment, wizard_information)
"""
+ brief = ""
description = ""
information = {}
for num, line in enumerate(comment):
index = line.find("$WIZ$")
if index != -1:
- description += " " + line[:index]
+ if len(brief) == 0:
+ brief += line[:index].strip()
+ else:
+ description += " " + line[:index]
try:
exec line[index + len("$WIZ$ "):] in {}, information
except:
raise ParseError(num, line[index:])
else:
- description += " " + line
- return description.strip(), information
+ if len(brief) == 0:
+ brief += line.strip()
+ else:
+ description += " " + line
+ description = description.strip()
+ return brief.strip(), description.strip(), information
def getDefinitionBlocks(text):
"""
moduleInfoDict = {}
listInfoDict = {}
configurationInfoDict = {}
- for filename, path in findDefinitions("*.h", project):
+ fileDict = {}
+ for filename, path in findDefinitions("*.h", project) + findDefinitions("*.c", project) + findDefinitions("*.s", project) + findDefinitions("*.S", project):
commentList = getCommentList(open(path + "/" + filename, "r").read())
if len(commentList) > 0:
moduleInfo = {}
try:
toBeParsed, moduleDict = loadModuleDefinition(commentList[0])
except ParseError, err:
- print "error in file %s. line: %d - statement %s" % (path + "/" + filename, err.line_number, err.line)
- print err.args
- print err.message
- raise Exception
+ raise DefineException.ModuleDefineException(path, err.line_number, err.line)
for module, information in moduleDict.items():
+ information["category"] = os.path.basename(path)
if "configuration" in information.keys() and len(information["configuration"]):
configuration = moduleDict[module]["configuration"]
- configurationInfo[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration)
+ try:
+ configurationInfo[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration)
+ except ParseError, err:
+ raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line)
moduleInfoDict.update(moduleDict)
configurationInfoDict.update(configurationInfo)
if toBeParsed:
listDict = loadDefineLists(commentList[1:])
listInfoDict.update(listDict)
except ParseError, err:
- print "error in file %s. line: %d - statement %s" % (path + "/" + filename, err.line_number, err.line)
- print err.args
- print err.message
- raise Exception
+ raise DefineException.EnumDefineException(path, err.line_number, err.line)
for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project):
commentList = getCommentList(open(path + "/" + filename, "r").read())
listInfoDict.update(loadDefineLists(commentList))
project.setInfo("MODULES", moduleInfoDict)
project.setInfo("LISTS", listInfoDict)
project.setInfo("CONFIGURATIONS", configurationInfoDict)
+ project.setInfo("FILES", fileDict)
def formatParamNameValue(text):
"""
"min": the minimum value for integer parameters
"max": the maximum value for integer parameters
"long": boolean indicating if the num is a long
+ "unsigned": boolean indicating if the num is an unsigned
"value_list": the name of the enum for enum parameters
"""
- try:
- configurationInfos = {}
- for comment, define in getDefinitionBlocks(open(path, "r").read()):
- name, value = formatParamNameValue(define)
- description, informations = getDescriptionInformations(comment)
- configurationInfos[name] = {}
- configurationInfos[name]["value"] = value
- configurationInfos[name]["informations"] = informations
- if ("type" in configurationInfos[name]["informations"].keys() and
- configurationInfos[name]["informations"]["type"] == "int" and
- configurationInfos[name]["value"].find("L") != -1):
- configurationInfos[name]["informations"]["long"] = True
- configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("L", "")
- if ("type" in configurationInfos[name]["informations"].keys() and
- configurationInfos[name]["informations"]["type"] == "int" and
- configurationInfos[name]["value"].find("U") != -1):
- configurationInfos[name]["informations"]["unsigned"] = True
- configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("U", "")
- configurationInfos[name]["description"] = description
- return configurationInfos
- except ParseError, err:
- print "error in file %s. line: %d - statement %s" % (path, err.line_number, err.line)
- print err.args
- print err.message
- raise Exception
+ configurationInfos = {}
+ for comment, define in getDefinitionBlocks(open(path, "r").read()):
+ name, value = formatParamNameValue(define)
+ brief, description, informations = getDescriptionInformations(comment)
+ configurationInfos[name] = {}
+ configurationInfos[name]["value"] = value
+ configurationInfos[name]["informations"] = informations
+ if not "type" in configurationInfos[name]["informations"]:
+ configurationInfos[name]["informations"]["type"] = findParameterType(configurationInfos[name])
+ if ("type" in configurationInfos[name]["informations"].keys() and
+ configurationInfos[name]["informations"]["type"] == "int" and
+ configurationInfos[name]["value"].find("L") != -1):
+ configurationInfos[name]["informations"]["long"] = True
+ configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("L", "")
+ if ("type" in configurationInfos[name]["informations"].keys() and
+ configurationInfos[name]["informations"]["type"] == "int" and
+ configurationInfos[name]["value"].find("U") != -1):
+ configurationInfos[name]["informations"]["unsigned"] = True
+ configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("U", "")
+ configurationInfos[name]["description"] = description
+ configurationInfos[name]["brief"] = brief
+ return configurationInfos
+
+def findParameterType(parameter):
+ if "value_list" in parameter["informations"]:
+ return "enum"
+ if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
+ return "int"
def sub(string, parameter, value):
"""