Use os.path.normpath for normalize the file paths with native separator
[bertos.git] / wizard / bertos_utils.py
index ceb75ab4306f106e6e954cba3ce9e51b9eae0d9c..805519419374ac3274744f52ac522e77cd4137b5 100644 (file)
@@ -52,9 +52,10 @@ def createBertosProject(project_info):
     cfgdir = prjdir + "/cfg"
     shutil.rmtree(cfgdir, True)
     os.mkdir(cfgdir)
-    for key, value in project_info.info("CONFIGURATIONS").items():
-        string = open(sources_dir + "/" + key, "r").read()
-        for parameter, infos in value.items():
+    for configuration, information in project_info.info("CONFIGURATIONS").items():
+        string = open(sources_dir + "/" + configuration, "r").read()
+        for start, parameter in information["paramlist"]:
+            infos = information[parameter]
             value = infos["value"]
             if "type" in infos["informations"] and infos["informations"]["type"] == "autoenabled":
                 value = "1"
@@ -63,7 +64,7 @@ def createBertosProject(project_info):
             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 = open(cfgdir + "/" + os.path.basename(configuration), "w")
         f.write(string)
         f.close()
     ## Destinatio mk file
@@ -88,7 +89,7 @@ def mkGenerator(project_info, makefile):
     mk_data["$cpuname"] = project_info.info("CPU_INFOS")["CORE_CPU"]
     mk_data["$cflags"] = " ".join(project_info.info("CPU_INFOS")["C_FLAGS"])
     mk_data["$ldflags"] = " ".join(project_info.info("CPU_INFOS")["LD_FLAGS"])
-    mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$constants"] = csrcGenerator(project_info)
+    mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
     mk_data["$prefix"] = project_info.info("TOOLCHAIN")["path"].split("gcc")[0]
     mk_data["$suffix"] = project_info.info("TOOLCHAIN")["path"].split("gcc")[1]
     mk_data["$cross"] = project_info.info("TOOLCHAIN")["path"].split("gcc")[0]
@@ -118,13 +119,15 @@ def csrcGenerator(project_info):
     csrc = []
     ## file to be included in PCSRC variable
     pcsrc = []
+    ## files to be included in CPPASRC variable
+    asrc = []
     ## constants to be included at the beginning of the makefile
     constants = {}
-    module_files = set([])
-    dependency_files = set([])
-    ## assembly sources
-    asm_files = set([])
     for module, information in modules.items():
+        module_files = set([])
+        dependency_files = set([])
+        ## assembly sources
+        asm_files = set([])
         if information["enabled"]:
             if "constants" in information:
                 constants.update(information["constants"])
@@ -138,15 +141,18 @@ def csrcGenerator(project_info):
                     asm_files |= set(dependencySFiles)
             for file in module_files:
                 if not harvard or "harvard" not in information or information["harvard"] == "both":
-                    csrc.append(file)
+                    csrc.append(os.path.normpath(file))
                 if harvard and "harvard" in information:
-                    pcsrc.append(file)
+                    pcsrc.append(os.path.normpath(file))
             for file in dependency_files:
-                csrc.append(file)
+                csrc.append(os.path.normpath(file))
+            for file in asm_files:
+                asrc.append(os.path.normpath(file))
     csrc = " \\\n\t".join(csrc) + " \\"
     pcsrc = " \\\n\t".join(pcsrc) + " \\"
+    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()])
-    return csrc, pcsrc, constants
+    return csrc, pcsrc, asrc, constants
     
 def findModuleFiles(module, project_info):
     ## Find the files related to the selected module
@@ -358,14 +364,23 @@ def getDefinitionBlocks(text):
     Take a text and return a list of tuple (description, name-value).
     """
     block = []
-    block_tmp = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
-    for comment, define in block_tmp:
+    block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
+    for match in block_tmp:
         # Only the first element is needed
-        block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define))
-    for comment, define in re.findall(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
-        block.append(([comment], define))
-    for define, comment in re.findall(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
-        block.append(([comment], define))
+        comment = match.group(1)
+        define = match.group(2)
+        start = match.start()
+        block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start))
+    for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
+        comment = match.group(1)
+        define = match.group(2)
+        start = match.start()
+        block.append(([comment], define, start))
+    for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
+        comment = match.group(2)
+        define = match.group(1)
+        start = match.start()
+        block.append(([comment], define, start))
     return block
 
 def loadModuleData(project):
@@ -383,6 +398,9 @@ def loadModuleData(project):
             except ParseError, err:
                 raise DefineException.ModuleDefineException(path, err.line_number, err.line)
             for module, information in module_dict.items():
+                if "depends" not in information:
+                    information["depends"] = ()
+                information["depends"] += (filename.split(".")[0],)
                 information["category"] = os.path.basename(path)
                 if "configuration" in information.keys() and len(information["configuration"]):
                     configuration = module_dict[module]["configuration"]
@@ -433,9 +451,11 @@ def loadConfigurationInfos(path):
             "value_list": the name of the enum for enum parameters
     """
     configuration_infos = {}
-    for comment, define in getDefinitionBlocks(open(path, "r").read()):
+    configuration_infos["paramlist"] = []
+    for comment, define, start in getDefinitionBlocks(open(path, "r").read()):
         name, value = formatParamNameValue(define)
         brief, description, informations = getDescriptionInformations(comment)
+        configuration_infos["paramlist"].append((start, name))
         configuration_infos[name] = {}
         configuration_infos[name]["value"] = value
         configuration_infos[name]["informations"] = informations