8 """ |
8 """ |
9 This abstract class contains GCC specific code. |
9 This abstract class contains GCC specific code. |
10 It cannot be used as this and should be inherited in a target specific |
10 It cannot be used as this and should be inherited in a target specific |
11 class such as target_linux or target_win32 |
11 class such as target_linux or target_win32 |
12 """ |
12 """ |
13 def __init__(self, PluginsRootInstance): |
13 def __init__(self, ConfigTreeRootInstance): |
14 self.PluginsRootInstance = PluginsRootInstance |
14 self.ConfigTreeRootInstance = ConfigTreeRootInstance |
15 self.buildpath = None |
15 self.buildpath = None |
16 self.SetBuildPath(self.PluginsRootInstance._getBuildPath()) |
16 self.SetBuildPath(self.ConfigTreeRootInstance._getBuildPath()) |
17 |
17 |
18 def getBuilderCFLAGS(self): |
18 def getBuilderCFLAGS(self): |
19 """ |
19 """ |
20 Returns list of builder specific CFLAGS |
20 Returns list of builder specific CFLAGS |
21 """ |
21 """ |
22 return [self.PluginsRootInstance.GetTarget().getcontent()["value"].getCFLAGS()] |
22 return [self.ConfigTreeRootInstance.GetTarget().getcontent()["value"].getCFLAGS()] |
23 |
23 |
24 def getBuilderLDFLAGS(self): |
24 def getBuilderLDFLAGS(self): |
25 """ |
25 """ |
26 Returns list of builder specific LDFLAGS |
26 Returns list of builder specific LDFLAGS |
27 """ |
27 """ |
28 return self.PluginsRootInstance.LDFLAGS + \ |
28 return self.ConfigTreeRootInstance.LDFLAGS + \ |
29 [self.PluginsRootInstance.GetTarget().getcontent()["value"].getLDFLAGS()] |
29 [self.ConfigTreeRootInstance.GetTarget().getcontent()["value"].getLDFLAGS()] |
30 |
30 |
31 def GetBinaryCode(self): |
31 def GetBinaryCode(self): |
32 try: |
32 try: |
33 return open(self.exe_path, "rb").read() |
33 return open(self.exe_path, "rb").read() |
34 except Exception, e: |
34 except Exception, e: |
87 # TODO detect cicular deps. |
87 # TODO detect cicular deps. |
88 return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match) |
88 return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match) |
89 |
89 |
90 def build(self): |
90 def build(self): |
91 # Retrieve toolchain user parameters |
91 # Retrieve toolchain user parameters |
92 toolchain_params = self.PluginsRootInstance.GetTarget().getcontent()["value"] |
92 toolchain_params = self.ConfigTreeRootInstance.GetTarget().getcontent()["value"] |
93 self.compiler = toolchain_params.getCompiler() |
93 self.compiler = toolchain_params.getCompiler() |
94 self.linker = toolchain_params.getLinker() |
94 self.linker = toolchain_params.getLinker() |
95 |
95 |
96 Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS()) |
96 Builder_CFLAGS = ' '.join(self.getBuilderCFLAGS()) |
97 |
97 |
98 ######### GENERATE OBJECT FILES ######################################## |
98 ######### GENERATE OBJECT FILES ######################################## |
99 obns = [] |
99 obns = [] |
100 objs = [] |
100 objs = [] |
101 relink = False |
101 relink = False |
102 for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: |
102 for Location, CFilesAndCFLAGS, DoCalls in self.ConfigTreeRootInstance.LocationCFilesAndCFLAGS: |
103 if Location: |
103 if Location: |
104 self.PluginsRootInstance.logger.write(_("Plugin : ") + self.PluginsRootInstance.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n") |
104 self.ConfigTreeRootInstance.logger.write(_("ConfNode : ") + self.ConfigTreeRootInstance.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n") |
105 else: |
105 else: |
106 self.PluginsRootInstance.logger.write(_("PLC :\n")) |
106 self.ConfigTreeRootInstance.logger.write(_("PLC :\n")) |
107 |
107 |
108 for CFile, CFLAGS in CFilesAndCFLAGS: |
108 for CFile, CFLAGS in CFilesAndCFLAGS: |
109 if CFile.endswith(".c"): |
109 if CFile.endswith(".c"): |
110 bn = os.path.basename(CFile) |
110 bn = os.path.basename(CFile) |
111 obn = os.path.splitext(bn)[0]+".o" |
111 obn = os.path.splitext(bn)[0]+".o" |
112 objectfilename = os.path.splitext(CFile)[0]+".o" |
112 objectfilename = os.path.splitext(CFile)[0]+".o" |
113 |
113 |
114 match = self.check_and_update_hash_and_deps(bn) |
114 match = self.check_and_update_hash_and_deps(bn) |
115 |
115 |
116 if match: |
116 if match: |
117 self.PluginsRootInstance.logger.write(" [pass] "+bn+" -> "+obn+"\n") |
117 self.ConfigTreeRootInstance.logger.write(" [pass] "+bn+" -> "+obn+"\n") |
118 else: |
118 else: |
119 relink = True |
119 relink = True |
120 |
120 |
121 self.PluginsRootInstance.logger.write(" [CC] "+bn+" -> "+obn+"\n") |
121 self.ConfigTreeRootInstance.logger.write(" [CC] "+bn+" -> "+obn+"\n") |
122 |
122 |
123 status, result, err_result = ProcessLogger( |
123 status, result, err_result = ProcessLogger( |
124 self.PluginsRootInstance.logger, |
124 self.ConfigTreeRootInstance.logger, |
125 "\"%s\" -c \"%s\" -o \"%s\" %s %s"% |
125 "\"%s\" -c \"%s\" -o \"%s\" %s %s"% |
126 (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS) |
126 (self.compiler, CFile, objectfilename, Builder_CFLAGS, CFLAGS) |
127 ).spin() |
127 ).spin() |
128 |
128 |
129 if status : |
129 if status : |
130 self.srcmd5.pop(bn) |
130 self.srcmd5.pop(bn) |
131 self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n")%bn) |
131 self.ConfigTreeRootInstance.logger.write_error(_("C compilation of %s failed.\n")%bn) |
132 return False |
132 return False |
133 obns.append(obn) |
133 obns.append(obn) |
134 objs.append(objectfilename) |
134 objs.append(objectfilename) |
135 elif CFile.endswith(".o"): |
135 elif CFile.endswith(".o"): |
136 obns.append(os.path.basename(CFile)) |
136 obns.append(os.path.basename(CFile)) |
137 objs.append(CFile) |
137 objs.append(CFile) |
138 |
138 |
139 ######### GENERATE library FILE ######################################## |
139 ######### GENERATE library FILE ######################################## |
140 # Link all the object files into one binary file |
140 # Link all the object files into one binary file |
141 self.PluginsRootInstance.logger.write(_("Linking :\n")) |
141 self.ConfigTreeRootInstance.logger.write(_("Linking :\n")) |
142 if relink: |
142 if relink: |
143 objstring = [] |
143 objstring = [] |
144 |
144 |
145 # Generate list .o files |
145 # Generate list .o files |
146 listobjstring = '"' + '" "'.join(objs) + '"' |
146 listobjstring = '"' + '" "'.join(objs) + '"' |
147 |
147 |
148 ALLldflags = ' '.join(self.getBuilderLDFLAGS()) |
148 ALLldflags = ' '.join(self.getBuilderLDFLAGS()) |
149 |
149 |
150 self.PluginsRootInstance.logger.write(" [CC] " + ' '.join(obns)+" -> " + self.exe + "\n") |
150 self.ConfigTreeRootInstance.logger.write(" [CC] " + ' '.join(obns)+" -> " + self.exe + "\n") |
151 |
151 |
152 status, result, err_result = ProcessLogger( |
152 status, result, err_result = ProcessLogger( |
153 self.PluginsRootInstance.logger, |
153 self.ConfigTreeRootInstance.logger, |
154 "\"%s\" %s -o \"%s\" %s"% |
154 "\"%s\" %s -o \"%s\" %s"% |
155 (self.linker, |
155 (self.linker, |
156 listobjstring, |
156 listobjstring, |
157 self.exe_path, |
157 self.exe_path, |
158 ALLldflags) |
158 ALLldflags) |