X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2Fbertos_utils.py;h=b872cf1501986baacbdd101199241a1b712d2cfc;hb=5caada91ff327558e599950dcf058d516ed88cb7;hp=bc60860bae7063148b4dd97e6ca1681bccdc3c6b;hpb=06b54dcaeaa1bb368a4f3542c3f6911e5187dcf5;p=bertos.git diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index bc60860b..b872cf15 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,14 @@ def createBertosProject(projectInfo): 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): """ @@ -74,10 +83,14 @@ 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"] = projectInfo.info("PROJECT_PATH") + "/" + os.path.basename(projectInfo.info("PROJECT_PATH")) + "/main.c" for key in mkData: while makefile.find(key) != -1: makefile = makefile.replace(key, mkData[key]) @@ -94,18 +107,57 @@ def makefileGenerator(projectInfo, makefile): def csrcGenerator(projectInfo): modules = projectInfo.info("MODULES") - files = [] + if "harvard" in projectInfo.info("CPU_INFOS")["CPU_TAGS"]: + harvard = True + else: + harvard = False + csrc = [] + pcsrc = [] + constants = {} for module, information in modules.items(): if information["enabled"]: + if "constants" in information: + constants.update(information["constants"]) for filename, path in findDefinitions(module + ".c", projectInfo): - files.append(path + "/" + filename) + path = path.replace(projectInfo.info("SOURCES_PATH"), projectInfo.info("PROJECT_PATH")) + if not harvard or "harvard" not in information or information["harvard"] == "both": + csrc.append(path + "/" + filename) + if harvard and "harvard" in information: + 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")) + if not harvard or "harvard" not in information or information["harvard"] == "both": + csrc.append(path + "/" + filename) + if harvard and "harvard" in information: + 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")) + if not harvard or "harvard" not in information or information["harvard"] == "both": + csrc.append(path + "/" + filename) + if harvard and "harvard" in information: + pcsrc.append(path + "/" + filename) + 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 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"] @@ -199,20 +251,31 @@ def loadModuleDefinition(first_comment): 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):