- shutil.copytree(sourcesDir + "/bertos", srcdir)
- ## Destination makefile
- makefile = directory + "/Makefile"
- if os.path.exists(makefile):
- os.remove(makefile)
- makefile = open("mktemplates/Makefile").read()
- makefile = makefileGenerator(projectInfo, makefile)
- open(directory + "/Makefile", "w").write(makefile)
- ## Destination project dir
- prjdir = directory + "/" + os.path.basename(directory)
- shutil.rmtree(prjdir, True)
- os.mkdir(prjdir)
- ## Destination configurations files
- cfgdir = prjdir + "/cfg"
- shutil.rmtree(cfgdir, True)
- os.mkdir(cfgdir)
- for key, value in projectInfo.info("CONFIGURATIONS").items():
- string = open(sourcesDir + "/" + key, "r").read()
- for parameter, infos in value.items():
- value = infos["value"]
- if "unsigned" in infos["informations"].keys() and infos["informations"]["unsigned"]:
- value += "U"
- if "long" in infos["informations"].keys() and infos["informations"]["long"]:
- value += "L"
- string = sub(string, parameter, value)
- f = open(cfgdir + "/" + os.path.basename(key), "w")
- f.write(string)
- f.close()
- ## Destinatio mk file
- 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):
+ copytree.copytree(os.path.join(new_sources, "bertos"), srcdir, ignore_list=const.IGNORE_LIST)
+
+def projectFileGenerator(project_info):
+ directory = project_info.info("PROJECT_PATH")
+ project_data = {}
+ enabled_modules = []
+ for module, information in project_info.info("MODULES").items():
+ if information["enabled"]:
+ enabled_modules.append(module)
+ project_data["ENABLED_MODULES"] = sorted(enabled_modules)
+ if project_info.info("PRESET"):
+ # For presets save again the BERTOS_PATH into project file
+ project_data["PRESET"] = True
+ project_data["BERTOS_PATH"] = relpath.relpath(project_info.info("BERTOS_PATH"), directory)
+ elif project_info.edit:
+ # If in editing mode the BERTOS_PATH is maintained
+ project_data["BERTOS_PATH"] = relpath.relpath(project_info.info("BERTOS_PATH"), directory)
+ else:
+ # Use the local BeRTOS version instead of the original one
+ # project_data["BERTOS_PATH"] = project_info.info("BERTOS_PATH")
+ project_data["BERTOS_PATH"] = "."
+ project_data["PROJECT_NAME"] = project_info.info("PROJECT_NAME", os.path.basename(directory))
+ project_src_relpath = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), directory)
+ project_data["PROJECT_SRC_PATH"] = project_src_relpath
+ project_data["PROJECT_SRC_PATH_FROM_MAKEFILE"] = project_info.info("PROJECT_SRC_PATH_FROM_MAKEFILE")
+ project_data["TOOLCHAIN"] = {'path': project_info.info("TOOLCHAIN")['path']}
+ project_data["CPU_NAME"] = project_info.info("CPU_NAME")
+ project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ")
+ project_data["OUTPUT"] = project_info.info("OUTPUT")
+ project_data["WIZARD_VERSION"] = WIZARD_VERSION
+ project_data["PRESET"] = project_info.info("PRESET")
+ project_data["PROJECT_HW_PATH"] = relpath.relpath(project_info.info("PROJECT_HW_PATH"), directory)
+ project_data["PROJECT_HW_PATH_FROM_MAKEFILE"] = project_info.info("PROJECT_HW_PATH_FROM_MAKEFILE")
+ return pickle.dumps(project_data)
+
+def loadPlugin(plugin):
+ """
+ Returns the given plugin module.
+ """
+ return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
+
+def versionFileGenerator(project_info, version_file):
+ version = bertosVersion(project_info.info("BERTOS_PATH"))
+ return version_file.replace('$version', version)
+
+def userMkGeneratorFromPreset(project_info):
+ project_name = project_info.info("PROJECT_NAME")
+ preset_path = project_info.info("PRESET_PATH")
+ preset_name = project_info.info("PRESET_NAME")
+ preset_src_dir = project_info.info("PRESET_SRC_PATH")
+ makefile = open(os.path.join(preset_path, preset_src_dir, "%s_user.mk" %preset_name), 'r').read()
+ destination = os.path.join(project_info.prjdir, "%s_user.mk" %project_info.info("PROJECT_NAME"))
+ # Temporary code.
+ # TODO: write it using regular expressions to secure this function
+ makefile = makefile.replace(preset_name + "_", project_name + "_")
+ open(destination, "w").write(makefile)
+
+def userMkGenerator(project_info):
+ makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template_user.mk"), "r").read()
+ destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + "_user.mk")
+ # Deadly performances loss was here :(
+ mk_data = {}
+ mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
+ mk_data["$ppath"] = project_info.info("PROJECT_SRC_PATH_FROM_MAKEFILE")
+ mk_data["$main"] = "/".join(["$(%s_SRC_PATH)" %project_info.info("PROJECT_NAME"), "main.c"])
+ for key in mk_data:
+ makefile = makefile.replace(key, mk_data[key])
+ open(destination, "w").write(makefile)
+
+def mkGenerator(project_info):