From 17601b4d9891849640a8f11f1d39baf35f1a54ce Mon Sep 17 00:00:00 2001 From: duplo Date: Thu, 19 Feb 2009 09:41:30 +0000 Subject: [PATCH] Add the generation of the csrc git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2353 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/bertos_utils.py | 48 ++++++++++++++++++++++++---------- wizard/const.py | 2 +- wizard/mktemplates/template.mk | 22 ++++++++-------- wizard/test/testModulePage.py | 3 ++- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 700a6653..b27c754e 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -24,13 +24,13 @@ def isBertosDir(directory): def bertosVersion(directory): return open(directory + "/VERSION").readline().strip() -def createBertosProject(projectInfos): - directory = projectInfos.info("PROJECT_PATH") - sourcesDir = projectInfos.info("SOURCES_PATH") +def createBertosProject(projectInfo): + directory = projectInfo.info("PROJECT_PATH") + sourcesDir = projectInfo.info("SOURCES_PATH") if not os.path.isdir(directory): os.mkdir(directory) f = open(directory + "/project.bertos", "w") - f.write(repr(projectInfos)) + f.write(repr(projectInfo)) f.close() ## Destination source dir srcdir = directory + "/bertos" @@ -41,7 +41,7 @@ def createBertosProject(projectInfos): if os.path.exists(makefile): os.remove(makefile) makefile = open("mktemplates/Makefile").read() - makefile = makefileGenerator(projectInfos, makefile) + makefile = makefileGenerator(projectInfo, makefile) open(directory + "/Makefile", "w").write(makefile) ## Destination project dir prjdir = directory + "/" + os.path.basename(directory) @@ -51,7 +51,7 @@ def createBertosProject(projectInfos): cfgdir = prjdir + "/cfg" shutil.rmtree(cfgdir, True) os.mkdir(cfgdir) - for key, value in projectInfos.info("CONFIGURATIONS").items(): + for key, value in projectInfo.info("CONFIGURATIONS").items(): string = open(sourcesDir + "/" + key, "r").read() for parameter, infos in value.items(): value = infos["value"] @@ -65,32 +65,48 @@ def createBertosProject(projectInfos): f.close() ## Destinatio mk file makefile = open("mktemplates/template.mk", "r").read() - makefile = mkGenerator(projectInfos, makefile) + makefile = mkGenerator(projectInfo, makefile) open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile) -def mkGenerator(projectInfos, makefile): +def mkGenerator(projectInfo, makefile): """ Generates the mk file for the current project. """ mkData = {} - mkData["pname"] = os.path.basename(projectInfos.info("PROJECT_PATH")) - mkData["cpuname"] = projectInfos.info("CPU_INFOS")["CPU_NAME"] - mkData["cflags"] = " ".join(projectInfos.info("CPU_INFOS")["C_FLAGS"]) - mkData["ldflags"] = " ".join(projectInfos.info("CPU_INFOS")["LD_FLAGS"]) + mkData["$pname"] = os.path.basename(projectInfo.info("PROJECT_PATH")) + mkData["$cpuname"] = projectInfo.info("CPU_INFOS")["CPU_NAME"] + mkData["$cflags"] = " ".join(projectInfo.info("CPU_INFOS")["C_FLAGS"]) + mkData["$ldflags"] = " ".join(projectInfo.info("CPU_INFOS")["LD_FLAGS"]) + mkData["$csrc"] = csrcGenerator(projectInfo) for key in mkData: while makefile.find(key) != -1: makefile = makefile.replace(key, mkData[key]) return makefile -def makefileGenerator(projectInfos, makefile): +def makefileGenerator(projectInfo, makefile): """ Generate the Makefile for the current project. """ # TODO: write a general function that works for both the mk file and the Makefile while makefile.find("project_name") != -1: - makefile = makefile.replace("project_name", os.path.basename(projectInfos.info("PROJECT_PATH"))) + makefile = makefile.replace("project_name", os.path.basename(projectInfo.info("PROJECT_PATH"))) return makefile +def csrcGenerator(projectInfo): + modules = projectInfo.info("MODULES") + files = [] + 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 + def getSystemPath(): path = os.environ["PATH"] if os.name == "nt": @@ -283,6 +299,10 @@ def loadModuleData(project): for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project): commentList = getCommentList(open(path + "/" + filename, "r").read()) listInfoDict.update(loadDefineLists(commentList)) + for tag in project.info("CPU_INFOS")["CPU_TAGS"]: + for filename, path in findDefinitions("*_" + tag + ".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) diff --git a/wizard/const.py b/wizard/const.py index 31b1c7cb..d66c479a 100644 --- a/wizard/const.py +++ b/wizard/const.py @@ -14,7 +14,7 @@ CPU_DEF = { "CPU_DIR": "", "DEFINITION_PATH": "", "TOOLCHAIN": "", - "CPU_TAGS": "", + "CPU_TAGS": [], "CORE_CPU": "", "SCRIPT_DIR": "", "HW_DIR": "", diff --git a/wizard/mktemplates/template.mk b/wizard/mktemplates/template.mk index 281b772a..e55bd89b 100644 --- a/wizard/mktemplates/template.mk +++ b/wizard/mktemplates/template.mk @@ -9,25 +9,25 @@ # # Set to 1 for debug builds -pname_DEBUG = 1 +$pname_DEBUG = 1 # Our target application -TRG += pname -CPU = cpuname +TRG += $pname +CPU = $cpuname BOOT_ADDR_START = 0x1E000 -pname_PREFIX = prefix +$pname_PREFIX = $prefix -pname_SUFFIX = suffix +$pname_SUFFIX = $suffix -pname_MCU = $(CPU) +$pname_MCU = $(CPU) -pname_CSRC = \ - csrc +$pname_CSRC = \ + $csrc # -pname_PCSRC += pcsrc +$pname_PCSRC += $pcsrc -pname_CFLAGS = cflags -pname_LDFLAGS = ldflags +$pname_CFLAGS = $cflags +$pname_LDFLAGS = $ldflags diff --git a/wizard/test/testModulePage.py b/wizard/test/testModulePage.py index 6c4f8dc7..dc416b8a 100644 --- a/wizard/test/testModulePage.py +++ b/wizard/test/testModulePage.py @@ -29,11 +29,12 @@ def main(): app.project = BProject.BProject() page = BModulePage.BModulePage() page._projectInfoStore("SOURCES_PATH", "../../") - page._projectInfoStore("CPU_INFOS", {"TOOLCHAIN": "avr"}) + page._projectInfoStore("CPU_INFOS", {"TOOLCHAIN": "avr", "CPU_TAGS": []}) bertos_utils.loadSourceTree(page._project()) page.reloadData() page.show() app.exec_() + bertos_utils.csrcGenerator(app.project) if __name__ == '__main__': -- 2.25.1