+def loadBertosProject(project_file, info_dict):
+ project_data = pickle.loads(open(project_file, "r").read())
+ project_info = BProject.BProject()
+ project_info.setInfo("PROJECT_PATH", os.path.dirname(project_file))
+ if "SOURCES_PATH" in info_dict:
+ project_data["SOURCES_PATH"] = info_dict["SOURCES_PATH"]
+ if os.path.exists(project_data["SOURCES_PATH"]):
+ project_info.setInfo("SOURCES_PATH", project_data["SOURCES_PATH"])
+ else:
+ raise VersionException(project_info)
+ loadSourceTree(project_info)
+ cpu_name = project_data["CPU_NAME"]
+ project_info.setInfo("CPU_NAME", cpu_name)
+ cpu_info = loadCpuInfos(project_info)
+ for cpu in cpu_info:
+ if cpu["CPU_NAME"] == cpu_name:
+ project_info.setInfo("CPU_INFOS", cpu)
+ break
+ tag_list = getTagSet(cpu_info)
+ # Create, fill and store the dict with the tags
+ tag_dict = {}
+ for element in tag_list:
+ tag_dict[element] = False
+ infos = project_info.info("CPU_INFOS")
+ for tag in tag_dict:
+ if tag in infos["CPU_TAGS"] + [infos["CPU_NAME"], infos["TOOLCHAIN"]]:
+ tag_dict[tag] = True
+ else:
+ tag_dict[tag] = False
+ project_info.setInfo("ALL_CPU_TAGS", tag_dict)
+ if "TOOLCHAIN" in info_dict:
+ project_data["TOOLCHAIN"] = info_dict["TOOLCHAIN"]
+ if os.path.exists(project_data["TOOLCHAIN"]["path"]):
+ project_info.setInfo("TOOLCHAIN", project_data["TOOLCHAIN"])
+ else:
+ raise ToolchainException(project_info)
+ project_info.setInfo("SELECTED_FREQ", project_data["SELECTED_FREQ"])
+ project_info.setInfo("OUTPUT", project_data["OUTPUT"])
+ loadModuleData(project_info, True)
+ setEnabledModules(project_info, project_data["ENABLED_MODULES"])
+ return project_info
+
+def setEnabledModules(project_info, enabled_modules):
+ modules = project_info.info("MODULES")
+ files = {}
+ for module, information in modules.items():
+ information["enabled"] = module in enabled_modules
+ for dependency in information["depends"]:
+ if not dependency in modules:
+ if dependency in files:
+ files[dependency] += 1
+ else:
+ files[dependency] = 1
+ project_info.setInfo("MODULES", modules)
+ project_info.setInfo("FILES", files)
+
+def enabledModules(project_info):
+ enabled_modules = []
+ for name, module in project_info.info("MODULES").items():
+ if module["enabled"]:
+ enabled_modules.append(name)
+ return enabled_modules
+
+def mergeSources(srcdir, new_sources, old_sources):
+ # The current mergeSources function provide only a raw copy of the sources in the
+ # created project.
+ #
+ # TODO: implement the three way merge algorithm
+ #
+ shutil.rmtree(srcdir, True)
+ 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"] = enabled_modules
+ project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH")
+ project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN")
+ 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")
+ return pickle.dumps(project_data)
+
+def createBertosProject(project_info, edit=False):