#!/usr/bin/env python
# encoding: utf-8
#
+# This file is part of BeRTOS.
+#
+# Bertos is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# As a special exception, you may use this file as part of a free software
+# library without restriction. Specifically, if other files instantiate
+# templates or use macros or inline functions from this file, or you compile
+# this file and link it with other files to produce an executable, this
+# file does not by itself cause the resulting executable to be covered by
+# the GNU General Public License. This exception does not however
+# invalidate any other reasons why the executable file might be covered by
+# the GNU General Public License.
+#
# Copyright 2008 Develer S.r.l. (http://www.develer.com/)
-# All rights reserved.
#
# $Id$
#
import pickle
import const
-from plugins import codelite
+import plugins
import DefineException
+import BProject
def isBertosDir(directory):
return os.path.exists(directory + "/VERSION")
def bertosVersion(directory):
return open(directory + "/VERSION").readline().strip()
+def loadBertosProject(project_file):
+ project_data = pickle.loads(open(project_file, "r").read())
+ project_info = BProject.BProject()
+ project_info.setInfo("PROJECT_PATH", os.path.dirname(project_file))
+ project_info.setInfo("SOURCES_PATH", project_data["SOURCES_PATH"])
+ project_info.setInfo("TOOLCHAIN", project_data["TOOLCHAIN"])
+ 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["CORE_CPU"], infos["TOOLCHAIN"]]:
+ tag_dict[tag] = True
+ else:
+ tag_dict[tag] = False
+ project_info.setInfo("ALL_CPU_TAGS", tag_dict)
+ loadModuleData(project_info, True)
+ return project_info
+
+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")
+ return pickle.dumps(project_data)
+
def createBertosProject(project_info):
directory = project_info.info("PROJECT_PATH")
sources_dir = project_info.info("SOURCES_PATH")
- if not os.path.isdir(directory):
- os.mkdir(directory)
+ if os.path.isdir(directory):
+ shutil.rmtree(directory, True)
+ os.makedirs(directory)
f = open(directory + "/project.bertos", "w")
- f.write(pickle.dumps(project_info))
+ f.write(projectFileGenerator(project_info))
f.close()
# Destination source dir
srcdir = directory + "/bertos"
configurations = project_info.info("CONFIGURATIONS")
configuration = configurations[information["configuration"]]
for start, parameter in configuration["paramlist"]:
- if "type" in configuration[parameter] and configuration[parameter]["type"] == "autoenabled":
+ if "type" in configuration[parameter]["informations"] and configuration[parameter]["informations"]["type"] == "autoenabled":
configuration[parameter]["value"] = "1"
project_info.setInfo("CONFIGURATIONS", configurations)
# Copy all the configuration files
# Destination main.c file
main = open("srctemplates/main.c", "r").read()
open(prjdir + "/main.c", "w").write(main)
- # Codelite project files
- if "codelite" in project_info.info("OUTPUT"):
- codelite.createProject(project_info)
-
+ # Files for selected plugins
+ relevants_files = {}
+ for plugin in project_info.info("OUTPUT"):
+ module = loadPlugin(plugin)
+ relevants_files[plugin] = module.createProject(project_info)
+ project_info.setInfo("RELEVANT_FILES", relevants_files)
+
+def loadPlugin(plugin):
+ """
+ Returns the given plugin module.
+ """
+ return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
+
def mkGenerator(project_info, makefile):
"""
Generates the mk file for the current project.
cppasrc = " \\\n\t".join(cppasrc) + " \\"
cxxsrc = " \\\n\t".join(cxxsrc) + " \\"
asrc = " \\\n\t".join(asrc) + " \\"
- constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + str(value) for key, value in constants.items()])
+ constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + unicode(value) for key, value in constants.items()])
return csrc, pcsrc, cppasrc, cxxsrc, asrc, constants
def findModuleFiles(module, project_info):
info["thread"] = thread[0].split("Thread model: ")[1]
return info
+def getToolchainName(toolchain_info):
+ name = "GCC " + toolchain_info["version"] + " - " + toolchain_info["target"].strip()
+ return name
+
def loadSourceTree(project):
fileList = [f for f in os.walk(project.info("SOURCES_PATH"))]
project.setInfo("FILE_LIST", fileList)
del module_definition["module_description"]
if const.MODULE_DEFINITION["module_harvard"] in module_definition:
harvard = module_definition[const.MODULE_DEFINITION["module_harvard"]]
- if harvard == "both" or harvard == "pgm_memory":
- module_dict[module_name]["harvard"] = harvard
+ module_dict[module_name]["harvard"] = harvard
del module_definition[const.MODULE_DEFINITION["module_harvard"]]
if const.MODULE_DEFINITION["module_hw"] in module_definition:
hw = module_definition[const.MODULE_DEFINITION["module_hw"]]
block.append(([comment], define, start))
return block
-def loadModuleData(project):
+def loadModuleData(project, edit=False):
module_info_dict = {}
list_info_dict = {}
configuration_info_dict = {}
configuration_info[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration)
except ParseError, err:
raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line)
+ if edit:
+ try:
+ path = os.path.basename(project.info("PROJECT_PATH"))
+ directory = project.info("PROJECT_PATH")
+ user_configuration = loadConfigurationInfos(directory + "/" + configuration.replace("bertos", path))
+ configuration_info[configuration] = updateConfigurationValues(configuration_info[configuration], user_configuration)
+ except ParseError, err:
+ raise DefineException.ConfigurationDefineException(directory + "/" + configuration.replace("bertos", path))
module_info_dict.update(module_dict)
configuration_info_dict.update(configuration_info)
if to_be_parsed:
configuration_infos[name]["brief"] = brief
return configuration_infos
+def updateConfigurationValues(def_conf, user_conf):
+ for param in def_conf["paramlist"]:
+ def_conf[param[1]]["value"] = user_conf[param[1]]["value"]
+ return def_conf
+
def findParameterType(parameter):
if "value_list" in parameter["informations"]:
return "enum"
class SupportedException(Exception):
def __init__(self, support_string):
Exception.__init__(self)
- self.support_string = support_string
\ No newline at end of file
+ self.support_string = support_string