Added project linking, and plugin init,cleanup,retrive and publish method calls in main
authoretisserant
Mon, 24 Sep 2007 17:06:36 +0200
changeset 51 c31c55601556
parent 50 447b7706a5b6
child 52 eaffcd0a2f03
Added project linking, and plugin init,cleanup,retrive and publish method calls in main
Added plugin deletion
plugger.py
--- a/plugger.py	Mon Sep 24 17:05:07 2007 +0200
+++ b/plugger.py	Mon Sep 24 17:06:36 2007 +0200
@@ -155,14 +155,14 @@
         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
         """
         logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing yo do\n")
-        return [],""
+        return [],"",False
     
     def _Generate_C(self, buildpath, locations, logger):
         # Generate plugins [(Cfiles, CFLAGS)], LDFLAGS
-        PlugCFilesAndCFLAGS, PlugLDFLAGS = self.PlugGenerate_C(buildpath, locations, logger)
+        PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = self.PlugGenerate_C(buildpath, locations, logger)
         # if some files heve been generated put them in the list with their location
         if PlugCFilesAndCFLAGS:
-            LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS)]
+            LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)]
         else:
             LocationCFilesAndCFLAGS = []
 
@@ -354,11 +354,11 @@
         self.PluggedChilds[PlugInstance.PlugType].remove(PlugInstance)
         # Forget it... (View have to refresh)
 
-    def PlugRemoveChild(self, PlugName):
+    def PlugRemove(self):
         # Fetch the plugin
-        PlugInstance = self.GetChildByName(PlugName)
+        #PlugInstance = self.GetChildByName(PlugName)
         # Ask to his parent to remove it
-        PlugInstance.PlugParent._doRemoveChild(PlugInstance)
+        self.PlugParent._doRemoveChild(self)
 
     def PlugAddChild(self, PlugName, PlugType, logger):
         """
@@ -587,12 +587,15 @@
 
     def GetProjectPath(self):
         return self.ProjectPath
+
+    def GetProjectName(self):
+        return os.path.split(self.ProjectPath)[1]
     
     def GetPlugInfos(self):
         childs = []
         for child in self.IterChilds():
             childs.append(child.GetPlugInfos())
-        return {"name" : "PLC (%s)"%os.path.split(self.ProjectPath)[1], "type" : None, "values" : childs}
+        return {"name" : "PLC (%s)"%self.GetProjectName(), "type" : None, "values" : childs}
     
     def NewProject(self, ProjectPath):
         """
@@ -681,7 +684,7 @@
             ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...]
         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
         """
-        return [(C_file_name, self.CFLAGS) for C_file_name in self.PLCGeneratedCFiles ] , ""
+        return [(C_file_name, self.CFLAGS) for C_file_name in self.PLCGeneratedCFiles ] , "", False
     
     def _getBuildPath(self):
         return os.path.join(self.ProjectPath, "build")
@@ -795,21 +798,15 @@
         #logger.write("LDFLAGS :\n"+pp.pformat(LDFLAGS)+"\n")
         
         # Generate main
-        locstrs = map(lambda x:"_".join(map(str,x)), [loc for loc in zip(*LocationCFilesAndCFLAGS)[0] if loc])
+        locstrs = map(lambda x:"_".join(map(str,x)), [loc for loc,Cfiles,DoCalls in LocationCFilesAndCFLAGS if loc and DoCalls])
         plc_main = runtime.code("plc_common_main") % {
-            "calls_prototypes":"".join(["""
-void __init%(s)s();
-void __cleanup%(s)s();
-void __retrive%(s)s();
-void __publish%(s)s();"""%{'s':locstr} for locstr in locstrs]),
-            "retrive_calls":"".join(["""
-    __retrive%(s)s();"""%{'s':locstr} for locstr in locstrs]),
-            "publish_calls":"".join(["""
-    __publish%(s)s();"""%{'s':locstr} for locstr in locstrs]),
-            "init_calls":"".join(["""
-    __init%(s)s();"""%{'s':locstr} for locstr in locstrs]),
-            "cleanup_calls":"".join(["""
-    __cleanup%(s)s();"""%{'s':locstr} for locstr in locstrs])}
+            "calls_prototypes":"".join(
+               ["void __init_%(s)s();\nvoid __cleanup_%(s)s();\nvoid __retrive_%(s)s();\nvoid __publish_%(s)s();"%
+                {'s':locstr} for locstr in locstrs]),
+            "retrive_calls":"".join(["    __retrive_%(s)s();"%{'s':locstr} for locstr in locstrs]),
+            "publish_calls":"".join(["    __publish_%(s)s();"%{'s':locstr} for locstr in locstrs]),
+            "init_calls":"".join(["    __init_%(s)s();"%{'s':locstr} for locstr in locstrs]),
+            "cleanup_calls":"".join(["    __cleanup_%(s)s();"%{'s':locstr} for locstr in locstrs])}
         target_name = self.BeremizRoot.TargetType.content["name"]
         plc_main += runtime.code("plc_%s_main"%target_name)
 
@@ -822,7 +819,9 @@
         
         # Compile the resulting code into object files.
         compiler = self.BeremizRoot.getCompiler()
-        for Location, CFilesAndCFLAGS in LocationCFilesAndCFLAGS:
+        obns = []
+        objs = []
+        for Location, CFilesAndCFLAGS, DoCalls in LocationCFilesAndCFLAGS:
             if Location:
                 logger.write("Plugin : " + self.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n")
             else:
@@ -830,13 +829,28 @@
                 
             for CFile, CFLAGS in CFilesAndCFLAGS:
                 bn = os.path.basename(CFile)
-                logger.write("   [CC]  "+bn+" -> "+os.path.splitext(bn)[0]+".o\n")
+                obn = os.path.splitext(bn)[0]+".o"
+                obns.append(obn)
+                logger.write("   [CC]  "+bn+" -> "+obn+"\n")
                 objectfilename = os.path.splitext(CFile)[0]+".o"
                 status, result, err_result = logger.LogCommand("%s -c %s -o %s %s"%(compiler, CFile, objectfilename, CFLAGS))
                 if status != 0:
                     logger.write_error("Build failed\n")
                     return False
-                    
+                objs.append(objectfilename)
+        # Link all the object files into one executable
+        logger.write("Linking :\n")
+        exe = self.GetProjectName()
+        if target_name == "Win32":
+            exe += ".exe"
+        exe_path = os.path.join(buildpath, exe)
+        logger.write("   [CC]  " + ' '.join(obns)+" -> " + exe + "\n")
+        status, result, err_result = logger.LogCommand("%s %s -o %s %s"%(compiler, " ".join(objs), exe_path, ' '.join(LDFLAGS)))
+        if status != 0:
+            logger.write_error("Build failed\n")
+            return False
+        
+        
         return True