X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2Fbertos_utils.py;h=7c3b687ae58934a43f539fe9325d456187d286f8;hb=947fa269915f08922989a0faf971c216594ababf;hp=82b4ab7d607f854962973ddc53bd5eb706477720;hpb=54a6a413dbfba6ddcf43d20329f77605b5544f64;p=bertos.git diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 82b4ab7d..7c3b687a 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -16,6 +16,7 @@ import re import shutil import const +import codelite_project import DefineException def isBertosDir(directory): @@ -67,6 +68,11 @@ def createBertosProject(projectInfo): makefile = open("mktemplates/template.mk", "r").read() makefile = mkGenerator(projectInfo, makefile) open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile) + 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): """ @@ -74,10 +80,13 @@ 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"] = 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] for key in mkData: while makefile.find(key) != -1: makefile = makefile.replace(key, mkData[key]) @@ -94,18 +103,53 @@ def makefileGenerator(projectInfo, makefile): def csrcGenerator(projectInfo): modules = projectInfo.info("MODULES") - files = [] + if "harvard" in projectInfo.info("CPU_INFOS")["CPU_TAGS"]: + pcsrc_need = projectInfo.info("CPU_INFOS")["PC_SRC"] + else: + pcsrc_need = [] + csrc = [] + pcsrc = [] for module, information in modules.items(): if information["enabled"]: for filename, path in findDefinitions(module + ".c", projectInfo): - files.append(path + "/" + filename) + path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH")) + print path + csrc.append(path + "/" + filename) + if module in pcsrc_need: + pcsrc.append(path + "/" + filename) for filename, path in findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo): - files.append(path + "/" + filename) + path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH")) + print path + csrc.append(path + "/" + filename) + if module in pcsrc_need: + pcsrc.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 + path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH")) + print path + csrc.append(path + "/" + filename) + if module in pcsrc_need: + pcsrc.append(path + "/" + filename) + csrc = " \\\n\t".join(csrc) + " \\" + pcsrc = " \\\n\t".join(pcsrc) + " \\" + return csrc, pcsrc + +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"] @@ -119,8 +163,7 @@ def findToolchains(pathList): 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): @@ -285,14 +328,15 @@ def loadModuleData(project): 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: @@ -300,10 +344,7 @@ def loadModuleData(project): 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)) @@ -336,32 +377,26 @@ def loadConfigurationInfos(path): "long": boolean indicating if the num is a long "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) - brief, 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 - configurationInfos[name]["brief"] = brief - 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 ("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 sub(string, parameter, value): """