153 "LOC" : tuple of interger for IEC location (0,1,2,...) |
153 "LOC" : tuple of interger for IEC location (0,1,2,...) |
154 }, ...] |
154 }, ...] |
155 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
155 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
156 """ |
156 """ |
157 logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing yo do\n") |
157 logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing yo do\n") |
158 return [],"" |
158 return [],"",False |
159 |
159 |
160 def _Generate_C(self, buildpath, locations, logger): |
160 def _Generate_C(self, buildpath, locations, logger): |
161 # Generate plugins [(Cfiles, CFLAGS)], LDFLAGS |
161 # Generate plugins [(Cfiles, CFLAGS)], LDFLAGS |
162 PlugCFilesAndCFLAGS, PlugLDFLAGS = self.PlugGenerate_C(buildpath, locations, logger) |
162 PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = self.PlugGenerate_C(buildpath, locations, logger) |
163 # if some files heve been generated put them in the list with their location |
163 # if some files heve been generated put them in the list with their location |
164 if PlugCFilesAndCFLAGS: |
164 if PlugCFilesAndCFLAGS: |
165 LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS)] |
165 LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)] |
166 else: |
166 else: |
167 LocationCFilesAndCFLAGS = [] |
167 LocationCFilesAndCFLAGS = [] |
168 |
168 |
169 # plugin asks some some LDFLAGS |
169 # plugin asks some some LDFLAGS |
170 if PlugLDFLAGS: |
170 if PlugLDFLAGS: |
352 shutil.rmtree(PlugInstance.PlugPath()) |
352 shutil.rmtree(PlugInstance.PlugPath()) |
353 # Remove child of PluggedChilds |
353 # Remove child of PluggedChilds |
354 self.PluggedChilds[PlugInstance.PlugType].remove(PlugInstance) |
354 self.PluggedChilds[PlugInstance.PlugType].remove(PlugInstance) |
355 # Forget it... (View have to refresh) |
355 # Forget it... (View have to refresh) |
356 |
356 |
357 def PlugRemoveChild(self, PlugName): |
357 def PlugRemove(self): |
358 # Fetch the plugin |
358 # Fetch the plugin |
359 PlugInstance = self.GetChildByName(PlugName) |
359 #PlugInstance = self.GetChildByName(PlugName) |
360 # Ask to his parent to remove it |
360 # Ask to his parent to remove it |
361 PlugInstance.PlugParent._doRemoveChild(PlugInstance) |
361 self.PlugParent._doRemoveChild(self) |
362 |
362 |
363 def PlugAddChild(self, PlugName, PlugType, logger): |
363 def PlugAddChild(self, PlugName, PlugType, logger): |
364 """ |
364 """ |
365 Create the plugins that may be added as child to this node self |
365 Create the plugins that may be added as child to this node self |
366 @param PlugType: string desining the plugin class name (get name from PlugChildsTypes) |
366 @param PlugType: string desining the plugin class name (get name from PlugChildsTypes) |
585 def _GetCurrentName(self): |
585 def _GetCurrentName(self): |
586 return "" |
586 return "" |
587 |
587 |
588 def GetProjectPath(self): |
588 def GetProjectPath(self): |
589 return self.ProjectPath |
589 return self.ProjectPath |
|
590 |
|
591 def GetProjectName(self): |
|
592 return os.path.split(self.ProjectPath)[1] |
590 |
593 |
591 def GetPlugInfos(self): |
594 def GetPlugInfos(self): |
592 childs = [] |
595 childs = [] |
593 for child in self.IterChilds(): |
596 for child in self.IterChilds(): |
594 childs.append(child.GetPlugInfos()) |
597 childs.append(child.GetPlugInfos()) |
595 return {"name" : "PLC (%s)"%os.path.split(self.ProjectPath)[1], "type" : None, "values" : childs} |
598 return {"name" : "PLC (%s)"%self.GetProjectName(), "type" : None, "values" : childs} |
596 |
599 |
597 def NewProject(self, ProjectPath): |
600 def NewProject(self, ProjectPath): |
598 """ |
601 """ |
599 Create a new project in an empty folder |
602 Create a new project in an empty folder |
600 @param ProjectPath: path of the folder where project have to be created |
603 @param ProjectPath: path of the folder where project have to be created |
679 @param locations: List of complete variables locations \ |
682 @param locations: List of complete variables locations \ |
680 [(IEC_loc, IEC_Direction, IEC_Type, Name)]\ |
683 [(IEC_loc, IEC_Direction, IEC_Type, Name)]\ |
681 ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...] |
684 ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...] |
682 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
685 @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
683 """ |
686 """ |
684 return [(C_file_name, self.CFLAGS) for C_file_name in self.PLCGeneratedCFiles ] , "" |
687 return [(C_file_name, self.CFLAGS) for C_file_name in self.PLCGeneratedCFiles ] , "", False |
685 |
688 |
686 def _getBuildPath(self): |
689 def _getBuildPath(self): |
687 return os.path.join(self.ProjectPath, "build") |
690 return os.path.join(self.ProjectPath, "build") |
688 |
691 |
689 def _getIECcodepath(self): |
692 def _getIECcodepath(self): |
793 #pp = pprint.PrettyPrinter(indent=4) |
796 #pp = pprint.PrettyPrinter(indent=4) |
794 #logger.write("LocationCFilesAndCFLAGS :\n"+pp.pformat(LocationCFilesAndCFLAGS)+"\n") |
797 #logger.write("LocationCFilesAndCFLAGS :\n"+pp.pformat(LocationCFilesAndCFLAGS)+"\n") |
795 #logger.write("LDFLAGS :\n"+pp.pformat(LDFLAGS)+"\n") |
798 #logger.write("LDFLAGS :\n"+pp.pformat(LDFLAGS)+"\n") |
796 |
799 |
797 # Generate main |
800 # Generate main |
798 locstrs = map(lambda x:"_".join(map(str,x)), [loc for loc in zip(*LocationCFilesAndCFLAGS)[0] if loc]) |
801 locstrs = map(lambda x:"_".join(map(str,x)), [loc for loc,Cfiles,DoCalls in LocationCFilesAndCFLAGS if loc and DoCalls]) |
799 plc_main = runtime.code("plc_common_main") % { |
802 plc_main = runtime.code("plc_common_main") % { |
800 "calls_prototypes":"".join([""" |
803 "calls_prototypes":"".join( |
801 void __init%(s)s(); |
804 ["void __init_%(s)s();\nvoid __cleanup_%(s)s();\nvoid __retrive_%(s)s();\nvoid __publish_%(s)s();"% |
802 void __cleanup%(s)s(); |
805 {'s':locstr} for locstr in locstrs]), |
803 void __retrive%(s)s(); |
806 "retrive_calls":"".join([" __retrive_%(s)s();"%{'s':locstr} for locstr in locstrs]), |
804 void __publish%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
807 "publish_calls":"".join([" __publish_%(s)s();"%{'s':locstr} for locstr in locstrs]), |
805 "retrive_calls":"".join([""" |
808 "init_calls":"".join([" __init_%(s)s();"%{'s':locstr} for locstr in locstrs]), |
806 __retrive%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
809 "cleanup_calls":"".join([" __cleanup_%(s)s();"%{'s':locstr} for locstr in locstrs])} |
807 "publish_calls":"".join([""" |
|
808 __publish%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
|
809 "init_calls":"".join([""" |
|
810 __init%(s)s();"""%{'s':locstr} for locstr in locstrs]), |
|
811 "cleanup_calls":"".join([""" |
|
812 __cleanup%(s)s();"""%{'s':locstr} for locstr in locstrs])} |
|
813 target_name = self.BeremizRoot.TargetType.content["name"] |
810 target_name = self.BeremizRoot.TargetType.content["name"] |
814 plc_main += runtime.code("plc_%s_main"%target_name) |
811 plc_main += runtime.code("plc_%s_main"%target_name) |
815 |
812 |
816 main_path = os.path.join(buildpath, "main.c" ) |
813 main_path = os.path.join(buildpath, "main.c" ) |
817 f = open(main_path,'w') |
814 f = open(main_path,'w') |
820 # First element is necessarely root |
817 # First element is necessarely root |
821 LocationCFilesAndCFLAGS[0][1].insert(0,(main_path, self.CFLAGS)) |
818 LocationCFilesAndCFLAGS[0][1].insert(0,(main_path, self.CFLAGS)) |
822 |
819 |
823 # Compile the resulting code into object files. |
820 # Compile the resulting code into object files. |
824 compiler = self.BeremizRoot.getCompiler() |
821 compiler = self.BeremizRoot.getCompiler() |
825 for Location, CFilesAndCFLAGS in LocationCFilesAndCFLAGS: |
822 obns = [] |
|
823 objs = [] |
|
824 for Location, CFilesAndCFLAGS, DoCalls in LocationCFilesAndCFLAGS: |
826 if Location: |
825 if Location: |
827 logger.write("Plugin : " + self.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n") |
826 logger.write("Plugin : " + self.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n") |
828 else: |
827 else: |
829 logger.write("PLC :\n") |
828 logger.write("PLC :\n") |
830 |
829 |
831 for CFile, CFLAGS in CFilesAndCFLAGS: |
830 for CFile, CFLAGS in CFilesAndCFLAGS: |
832 bn = os.path.basename(CFile) |
831 bn = os.path.basename(CFile) |
833 logger.write(" [CC] "+bn+" -> "+os.path.splitext(bn)[0]+".o\n") |
832 obn = os.path.splitext(bn)[0]+".o" |
|
833 obns.append(obn) |
|
834 logger.write(" [CC] "+bn+" -> "+obn+"\n") |
834 objectfilename = os.path.splitext(CFile)[0]+".o" |
835 objectfilename = os.path.splitext(CFile)[0]+".o" |
835 status, result, err_result = logger.LogCommand("%s -c %s -o %s %s"%(compiler, CFile, objectfilename, CFLAGS)) |
836 status, result, err_result = logger.LogCommand("%s -c %s -o %s %s"%(compiler, CFile, objectfilename, CFLAGS)) |
836 if status != 0: |
837 if status != 0: |
837 logger.write_error("Build failed\n") |
838 logger.write_error("Build failed\n") |
838 return False |
839 return False |
839 |
840 objs.append(objectfilename) |
|
841 # Link all the object files into one executable |
|
842 logger.write("Linking :\n") |
|
843 exe = self.GetProjectName() |
|
844 if target_name == "Win32": |
|
845 exe += ".exe" |
|
846 exe_path = os.path.join(buildpath, exe) |
|
847 logger.write(" [CC] " + ' '.join(obns)+" -> " + exe + "\n") |
|
848 status, result, err_result = logger.LogCommand("%s %s -o %s %s"%(compiler, " ".join(objs), exe_path, ' '.join(LDFLAGS))) |
|
849 if status != 0: |
|
850 logger.write_error("Build failed\n") |
|
851 return False |
|
852 |
|
853 |
840 return True |
854 return True |
841 |
855 |
842 |
856 |
843 # Link object files into something that can be executed on target |
857 # Link object files into something that can be executed on target |
844 |
858 |