In editing mode when the user selects a project that was created with older versions...
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 27 Apr 2010 09:30:28 +0000 (09:30 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 27 Apr 2010 09:30:28 +0000 (09:30 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3526 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BProject.py
wizard/compatibility.py
wizard/mktemplates/old/Makefile [new file with mode: 0644]
wizard/mktemplates/old/template.mk [new file with mode: 0644]
wizard/mktemplates/old/template_wiz.mk [new file with mode: 0644]

index 32fa159caeb4a0a7e50bbec7b35554620bb758b5..eadf9a7c784737861bc96d776664cb6a2034b209 100644 (file)
@@ -53,12 +53,13 @@ from bertos_utils import (
                             getCommentList, sub,
 
                             # Project creation functions
-                            projectFileGenerator, versionFileGenerator, makefileGenerator,
-                            userMkGenerator, mkGenerator, loadPlugin, mergeSources,
+                            projectFileGenerator, versionFileGenerator, loadPlugin, 
+                            mergeSources,
 
                             # Custom exceptions
                             ParseError, SupportedException
                         )
+import bertos_utils
 
 from compatibility import updateProject
 
@@ -390,13 +391,13 @@ class BProject(object):
         f.close()
 
     def _writeMakefile(self, filename):
-        makefileGenerator(self, filename)
+        bertos_utils.makefileGenerator(self, filename)
 
     def _writeUserMkFile(self, filename):
-        userMkGenerator(self, filename)
+        bertos_utils.userMkGenerator(self, filename)
 
     def _writeWizardMkFile(self, filename):
-        mkGenerator(self, filename)
+        bertos_utils.mkGenerator(self, filename)
 
     def _writeMainFile(self, filename):
         main = open(os.path.join(const.DATA_DIR, "srctemplates/main.c"), "r").read()
index 8f1b0742c4399329995eee907ec5bd0fab1357d9..22cd4f70f4372aab06f344d1c95948d889d4d54f 100644 (file)
 # Author: Lorenzo Berni <duplo@develer.com>
 #
 
+import const
+import os
+from bertos_utils import replaceSeparators, csrcGenerator
+
+def _userMkGenerator(project_info, destination):
+    makefile = open(os.path.join(const.DATA_DIR, "mktemplates/old/template.mk"), "r").read()
+    # Deadly performances loss was here :(
+    mk_data = {}
+    mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
+    mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
+    for key in mk_data:
+        while makefile.find(key) != -1:
+            makefile = makefile.replace(key, mk_data[key])
+    open(destination, "w").write(makefile)
+
+def _mkGenerator(project_info, destination):
+    """
+    Generates the mk file for the current project.
+    """
+    makefile = open(os.path.join(const.DATA_DIR, "mktemplates/old/template_wiz.mk"), "r").read()
+    mk_data = {}
+    mk_data["$pname"] = project_info.info("PROJECT_NAME")
+    mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
+    cpu_mk_parameters = []
+    for key, value in project_info.info("CPU_INFOS").items():
+        if key.startswith(const.MK_PARAM_ID):
+            cpu_mk_parameters.append("%s = %s" %(key.replace("MK", mk_data["$pname"]), value))
+    mk_data["$cpuparameters"] = "\n".join(cpu_mk_parameters)
+    mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
+    mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
+    mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
+    mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
+    for key in mk_data:
+        while makefile.find(key) != -1:
+            makefile = makefile.replace(key, mk_data[key])
+    open(destination, "w").write(makefile)
+
+def _makefileGenerator(project_info, destination):
+    """
+    Generate the Makefile for the current project.
+    """
+    makefile = open(os.path.join(const.DATA_DIR, "mktemplates/old/Makefile"), "r").read()
+    # TODO write a general function that works for both the mk file and the Makefile
+    while makefile.find("$pname") != -1:
+        makefile = makefile.replace("$pname", project_info.info("PROJECT_NAME"))
+    open(destination, "w").write(makefile)
+
 def updateProject(project_data):
     """
     Update incrementally the project_data loaded from a BeRTOS Wizard project
@@ -45,5 +92,11 @@ def updateProject(project_data):
     if wizard_version < 2:
         # Use SOURCES_PATH instead of BERTOS_PATH for backward compatibility
         project_data["BERTOS_PATH"] = project_data["SOURCES_PATH"]
+    if wizard_version < 3:
+        # Use older makefile templates and generators using monkey patching
+        import bertos_utils
+        bertos_utils.mkGenerator = _mkGenerator
+        bertos_utils.userMkGenerator = _userMkGenerator
+        bertos_utils.makefileGenerator = _makefileGenerator
     return project_data
 
diff --git a/wizard/mktemplates/old/Makefile b/wizard/mktemplates/old/Makefile
new file mode 100644 (file)
index 0000000..d266fc9
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+# All rights reserved.
+#
+# Author: Lorenzo Berni <duplo@develer.com>
+#
+
+# Set to 1 for verbose build output, 0 for terse output
+V := 0
+
+default: all
+
+include bertos/config.mk
+
+include $pname/$pname.mk
+
+include bertos/rules.mk
diff --git a/wizard/mktemplates/old/template.mk b/wizard/mktemplates/old/template.mk
new file mode 100644 (file)
index 0000000..4e1b844
--- /dev/null
@@ -0,0 +1,51 @@
+#
+# Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+# All rights reserved.
+#
+# Makefile template for BeRTOS wizard.
+#
+# Author: Lorenzo Berni <duplo@develer.com>
+#
+#
+
+# Programmer interface configuration, see http://dev.bertos.org/wiki/ProgrammerInterface for help
+$pname_PROGRAMMER_TYPE = none
+$pname_PROGRAMMER_PORT = none
+
+# Files included by the user.
+$pname_USER_CSRC = \
+       $main \
+       #
+
+# Files included by the user.
+$pname_USER_PCSRC = \
+       #
+
+# Files included by the user.
+$pname_USER_CPPASRC = \
+       #
+
+# Files included by the user.
+$pname_USER_CXXSRC = \
+       #
+
+# Files included by the user.
+$pname_USER_ASRC = \
+       #
+
+# Flags included by the user.
+$pname_USER_LDFLAGS = \
+       #
+
+# Flags included by the user.
+$pname_USER_CPPAFLAGS = \
+       #
+
+# Flags included by the user.
+$pname_USER_CPPFLAGS = \
+       -fno-strict-aliasing \
+       -fwrapv \
+       #
+
+# Include the mk file generated by the wizard
+include $pname/$pname_wiz.mk
diff --git a/wizard/mktemplates/old/template_wiz.mk b/wizard/mktemplates/old/template_wiz.mk
new file mode 100644 (file)
index 0000000..8edc07c
--- /dev/null
@@ -0,0 +1,71 @@
+#
+# Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+# All rights reserved.
+#
+# Makefile template for BeRTOS wizard.
+#
+# Author: Lorenzo Berni <duplo@develer.com>
+#
+#
+
+# Constants automatically defined by the selected modules
+$constants
+
+# Our target application
+TRG += $pname
+
+$pname_PREFIX = "$prefix"
+
+$pname_SUFFIX = "$suffix"
+
+# Files automatically generated by the wizard. DO NOT EDIT, USE $pname_USER_CSRC INSTEAD!
+$pname_WIZARD_CSRC = \
+       $csrc
+       #
+
+# Files automatically generated by the wizard. DO NOT EDIT, USE $pname_USER_PCSRC INSTEAD!
+$pname_WIZARD_PCSRC = \
+       $pcsrc
+       #
+
+# Files automatically generated by the wizard. DO NOT EDIT, USE $pname_USER_CPPASRC INSTEAD!
+$pname_WIZARD_CPPASRC = \
+       $cppasrc
+       #
+
+# Files automatically generated by the wizard. DO NOT EDIT, USE $pname_USER_CXXSRC INSTEAD!
+$pname_WIZARD_CXXSRC = \
+       $cxxsrc
+       #
+
+# Files automatically generated by the wizard. DO NOT EDIT, USE $pname_USER_ASRC INSTEAD!
+$pname_WIZARD_ASRC = \
+       $asrc
+       #
+
+$pname_CPPFLAGS = -D'CPU_FREQ=($cpuclockfreqUL)' -D'ARCH=(ARCH_DEFAULT)' -D'WIZ_AUTOGEN' -I$pname/ $($pname_CPU_CPPFLAGS) $($pname_USER_CPPFLAGS)
+
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$pname_LDFLAGS = $($pname_CPU_LDFLAGS) $($pname_WIZARD_LDFLAGS) $($pname_USER_LDFLAGS)
+
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$pname_CPPAFLAGS = $($pname_CPU_CPPAFLAGS) $($pname_WIZARD_CPPAFLAGS) $($pname_USER_CPPAFLAGS)
+
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$pname_CSRC = $($pname_CPU_CSRC) $($pname_WIZARD_CSRC) $($pname_USER_CSRC)
+
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$pname_PCSRC = $($pname_CPU_PCSRC) $($pname_WIZARD_PCSRC) $($pname_USER_PCSRC)
+
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$pname_CPPASRC = $($pname_CPU_CPPASRC) $($pname_WIZARD_CPPASRC) $($pname_USER_CPPASRC)
+
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$pname_CXXSRC = $($pname_CPU_CXXSRC) $($pname_WIZARD_CXXSRC) $($pname_USER_CXXSRC)
+
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$pname_ASRC = $($pname_CPU_ASRC) $($pname_WIZARD_ASRC) $($pname_USER_ASRC)
+
+# CPU specific flags and options, defined in the CPU definition files.
+# Automatically generated by the wizard. PLEASE DO NOT EDIT!
+$cpuparameters