- Remove the TOOL without NAME defined and its definition in ARCH_build.opt
[mirror_edk2.git] / Tools / Python / buildgen / BuildFile.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2007, Intel Corporation
4 # All rights reserved. This program and the accompanying materials
5 # are licensed and made available under the terms and conditions of the BSD License
6 # which accompanies this distribution. The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php
8 #
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 """Generate build file for given platform"""
13
14 import os, sys, copy
15 import xml.dom.minidom, pprint
16 import FrameworkElement
17
18 from SurfaceAreaElement import *
19 from XmlRoutines import *
20 from AntTasks import *
21 from sets import Set
22
23 class BuildFile:
24 def __init__(self, workspace, platform, toolchain, target):
25 if workspace == None or workspace == "":
26 raise Exception("No workspace, no build")
27 if platform == None or platform == "":
28 raise Exception("No platform, no build")
29 if toolchain == None or toolchain == "":
30 raise Exception("No toolchain, no build")
31 if target == None or target == "":
32 raise Exception("No target, no build")
33
34 self.Workspace = workspace
35 self.Platform = platform
36 self.Toolchain = toolchain
37 self.Target = target
38 self.Path = ""
39
40 def Generate(self):
41 """Generate the build file"""
42 pass
43
44 # generating build.xml for platform
45 class AntPlatformBuildFile(BuildFile):
46 def __init__(self, workspace, platform, toolchain, target):
47 BuildFile.__init__(self, workspace, platform, toolchain, target)
48 # Form the build file path, hard-coded at present. It should be specified by a configuration file
49 self.Path = os.path.join(self.Workspace.Path, self.Platform.OutputPath, target + "_" + toolchain, "build.xml")
50 print ""
51 # Generate a common build option property file in the format of Java's property file
52 self.DefaultBuildOptions()
53
54 # new a build file object
55 self.BuildXml = AntBuildFile(name="platform", basedir=".", default="all")
56
57 # generate the top level properties, tasks, etc.
58 self.Header()
59
60 # generate "prebuild" target
61 self.PreBuild()
62
63 # generate "libraries" target for building library modules
64 self.Libraries()
65
66 # generate "modules" target for building non-library modules
67 self.Modules()
68
69 # generate "fvs" target for building firmware volume. (not supported yet)
70
71 # generate "fds" target for building FlashDevice. (not supported yet)
72
73 # generate "postbuild" target
74 self.PostBuild()
75
76 def Generate(self):
77 print "Generating platform build file ...", self.Path
78 self.BuildXml.Create(self.Path)
79
80 def Header(self):
81 _topLevel = self.BuildXml
82 # import external tasks
83 _topLevel.SubTask("taskdef", resource="GenBuild.tasks")
84 _topLevel.SubTask("taskdef", resource="frameworktasks.tasks")
85 _topLevel.SubTask("taskdef", resource="net/sf/antcontrib/antlib.xml")
86
87 # platform wide properties
88 _topLevel.Blankline()
89 _topLevel.Comment("WORKSPACE wide attributes")
90 _topLevel.SubTask("property", environment="env")
91 _topLevel.SubTask("property", name="WORKSPACE_DIR", value="${env.WORKSPACE}")
92 _topLevel.SubTask("property", name="CONFIG_DIR", value="${WORKSPACE_DIR}/Tools/Conf")
93
94 _topLevel.Blankline()
95 _topLevel.Comment("Common build attributes")
96 _topLevel.SubTask("property", name="THREAD_COUNT", value=self.Workspace.ThreadCount)
97 _topLevel.SubTask("property", name="SINGLE_MODULE_BUILD", value="no")
98 _topLevel.SubTask("property", name="MODULE_BUILD_TARGET", value="platform_module_build")
99
100 _topLevel.Blankline()
101 _topLevel.SubTask("property", name="TOOLCHAIN", value=self.Toolchain)
102 _topLevel.SubTask("property", name="TARGET", value=self.Target)
103
104 _topLevel.Blankline()
105 _topLevel.Comment("Platform attributes")
106 _topLevel.SubTask("property", name="PLATFORM", value=self.Platform.Name)
107 _topLevel.SubTask("property", name="PLATFORM_GUID", value=self.Platform.GuidValue)
108 _topLevel.SubTask("property", name="PLATFORM_VERSION", value=self.Platform.Version)
109 _topLevel.SubTask("property", name="PLATFORM_RELATIVE_DIR", value=self.Platform.Dir)
110 _topLevel.SubTask("property", name="PLATFORM_DIR", value="${WORKSPACE_DIR}/${PLATFORM_RELATIVE_DIR}")
111 _topLevel.SubTask("property", name="PLATFORM_OUTPUT_DIR", value=self.Platform.OutputPath)
112
113 # user configurable build path for platform
114 _topLevel.Blankline()
115 _topLevel.Comment("Common path definition for platform build")
116 _topLevel.SubTask("property", file="${WORKSPACE_DIR}/Tools/Python/buildgen/platform_build_path.txt")
117
118 # common build tasks in the form of Ant macro
119 _topLevel.Blankline()
120 _topLevel.Comment("Task Macros for Compiling, Assembling, Linking, etc.")
121 _topLevel.SubTask("import", file="${CONFIG_DIR}/BuildMacro.xml")
122 _topLevel.Blankline()
123 _topLevel.SubTask("echo", message="${PLATFORM}-${PLATFORM_VERSION} (${PLATFORM_RELATIVE_DIR})", level="info")
124
125 # define the targets execution sequence
126 _topLevel.Blankline()
127 _topLevel.Comment("Default target")
128 _topLevel.SubTask("target", name="all", depends="prebuild, libraries, modules, postbuild")
129
130 def PreBuild(self):
131 _topLevel = self.BuildXml
132 _topLevel.Blankline()
133 _topLevel.Comment(" TARGET: prebuild ")
134
135 # prebuild is defined by user in the fpd file through <UserExtionsion> element,
136 # which has attribute "identifier=0" or "identifier=prebuild"
137 prebuildTasks = []
138 if self.Platform.UserExtensions.has_key("0"):
139 prebuildTasks = self.Platform.UserExtensions["0"]
140 elif self.Platform.UserExtensions.has_key("postbuild"):
141 prebuildTasks = self.Platform.UserExtensions["prebuild"]
142
143 _topLevel.SubTask("target", prebuildTasks, name="prebuild")
144
145 def Libraries(self):
146 _topLevel = self.BuildXml
147 _topLevel.Blankline()
148 _topLevel.Comment(" TARGET: libraries ")
149
150 librariesTarget = _topLevel.SubTask("target", name="libraries")
151 parallelBuild = librariesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")
152
153 libraryNumber = 0
154 for arch in self.Platform.Libraries:
155 libraryNumber += len(self.Platform.Libraries[arch])
156 libraryIndex = 0
157 for arch in self.Platform.Libraries:
158 for lib in self.Platform.Libraries[arch]:
159 libraryIndex += 1
160 print "Generating library build files ... %d%%\r" % int((float(libraryIndex) / float(libraryNumber)) * 100),
161 buildFile = AntModuleBuildFile(self.Workspace, self.Platform, lib, self.Toolchain, self.Target, arch)
162 buildFile.Generate()
163 buildDir = os.path.join("${TARGET_DIR}", arch, lib.Module.Package.SubPath(lib.Module.Dir),
164 lib.Module.FileBaseName)
165 parallelBuild.SubTask("ant", dir=buildDir,
166 #antfile="build.xml",
167 inheritAll="true",
168 target="${MODULE_BUILD_TARGET}")
169 print ""
170
171 def Modules(self):
172 _topLevel = self.BuildXml
173 _topLevel.Blankline()
174 _topLevel.Comment(" TARGET: modules ")
175
176 modulesTarget = _topLevel.SubTask("target", name="modules")
177 parallelBuild = modulesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")
178
179 moduleNumber = 0
180 for arch in self.Platform.Modules:
181 moduleNumber += len(self.Platform.Modules[arch])
182
183 moduleIndex = 0
184 for arch in self.Platform.Modules:
185 for module in self.Platform.Modules[arch]:
186 moduleIndex += 1
187 print "Generating module build files ... %d%%\r" % int((float(moduleIndex) / float(moduleNumber)) * 100),
188
189 buildDir = os.path.join("${TARGET_DIR}", arch, module.Module.Package.SubPath(module.Module.Dir),
190 module.Module.FileBaseName)
191 parallelBuild.SubTask("ant", dir=buildDir,
192 #antfile="build.xml",
193 inheritAll="true",
194 target="${MODULE_BUILD_TARGET}")
195 buildFile = AntModuleBuildFile(self.Workspace, self.Platform, module, self.Toolchain, self.Target, arch)
196 buildFile.Generate()
197 print ""
198
199 def Fvs(self):
200 pass
201
202 def Fds(self):
203 pass
204
205 def PostBuild(self):
206 _topLevel = self.BuildXml
207 _topLevel.Blankline()
208 _topLevel.Comment(" TARGET: postbuild ")
209
210 # postbuild is defined by user in the fpd file through <UserExtionsion> element,
211 # which has attribute "identifier=1" or "identifier=postbuild"
212 postbuildTasks = []
213 if self.Platform.UserExtensions.has_key("1"):
214 postbuildTasks = self.Platform.UserExtensions["1"]
215 elif self.Platform.UserExtensions.has_key("postbuild"):
216 postbuildTasks = self.Platform.UserExtensions["postbuild"]
217
218 _topLevel.SubTask("target", postbuildTasks, name="postbuild")
219
220 def Clean(self):
221 pass
222
223 def CleanAll(self):
224 pass
225
226 def UserExtensions(self):
227 pass
228
229 def DefaultBuildOptions(self):
230 """Generate ${ARCH}_build.opt which contains the default build&tool definitions"""
231 tools = self.Workspace.ToolConfig.ToolCodes
232 for arch in self.Workspace.ActiveArchs:
233 validTools = []
234 for tool in tools:
235 key = (self.Toolchain, self.Target, arch, tool, "NAME")
236 if self.Workspace.ToolConfig[key] == "": continue
237 validTools.append(tool)
238
239 optFileDir = os.path.join(self.Workspace.Path, self.Platform.OutputPath,
240 self.Target + "_" + self.Toolchain)
241 optFileName = arch + "_build.opt"
242 if not os.path.exists(optFileDir): os.makedirs(optFileDir)
243 f = open(os.path.join(optFileDir, optFileName), "w")
244
245 for tool in validTools:
246 key = (self.Toolchain, self.Target, arch, tool, "FLAGS")
247 if key in self.Platform.BuildOptions:
248 flag = self.Platform.BuildOptions[key]
249 else:
250 key = (self.Toolchain, self.Target, arch, tool, "FAMILY")
251 family = self.Workspace.ToolConfig[key]
252 key = (family, self.Target, arch, tool, "FLAGS")
253 if key in self.Platform.BuildOptions:
254 flag = self.Platform.BuildOptions[key]
255 else:
256 flag = ""
257 f.write("PLATFORM_%s_FLAGS=%s\n" % (tool, flag))
258 f.write("\n")
259
260 for tool in validTools:
261 key = (self.Toolchain, self.Target, arch, tool, "FLAGS")
262 flag = self.Workspace.ToolConfig[key]
263 f.write("DEFAULT_%s_FLAGS=%s\n" % (tool, flag))
264
265 f.write("\n")
266 for tool in validTools:
267 for attr in self.Workspace.ToolConfig.Attributes:
268 if attr == "FLAGS": continue
269 key = (self.Toolchain, self.Target, arch, tool, attr)
270 value = self.Workspace.ToolConfig[key]
271 if attr == "NAME":
272 path = self.Workspace.ToolConfig[(self.Toolchain, self.Target, arch, tool, "PATH")]
273 f.write("%s=%s\n" % (tool, os.path.join(path, value)))
274 else:
275 f.write("%s_%s=%s\n" % (tool, attr, value))
276 f.write("%s_FLAGS=${DEFAULT_%s_FLAGS} ${DEFAULT_MODULE_%s_FLAGS} ${PLATFORM_%s_FLAGS} ${MODULE_%s_FLAGS}\n" %
277 (tool, tool, tool, tool, tool))
278 f.write("\n")
279
280 f.close()
281
282 class AntModuleBuildFile(BuildFile):
283 def __init__(self, workspace, platform, module, toolchain, target, arch):
284 BuildFile.__init__(self, workspace, platform, toolchain, target)
285 self.Module = module
286 self.Arch = arch
287 self.Path = os.path.join(self.Workspace.Path, self.Platform.OutputPath,
288 target + "_" + toolchain, arch, self.Module.Module.Package.Dir,
289 self.Module.Module.Dir, self.Module.Module.FileBaseName, "build.xml")
290 self.BuildXml = AntBuildFile(self.Module.Module.Name)
291
292 self.SourceFiles = self.GetSourceFiles()
293
294 self.Header()
295 self.PreBuild()
296 self.Libraries()
297 self.Sourcefiles()
298 self.Sections()
299 self.Ffs()
300 self.PostBuild()
301
302 def Generate(self):
303 # print self.Path,"\r",
304 self.BuildXml.Create(self.Path)
305
306 def Header(self):
307 _topLevel = self.BuildXml
308 _topLevel.SubTask("taskdef", resource="frameworktasks.tasks")
309 _topLevel.SubTask("taskdef", resource="cpptasks.tasks")
310 _topLevel.SubTask("taskdef", resource="cpptasks.types")
311 _topLevel.SubTask("taskdef", resource="net/sf/antcontrib/antlib.xml")
312
313 _topLevel.Blankline()
314 _topLevel.Comment(" TODO ")
315 _topLevel.SubTask("property", environment="env")
316 _topLevel.SubTask("property", name="WORKSPACE_DIR", value="${env.WORKSPACE}")
317
318 _topLevel.Blankline()
319 _topLevel.Comment("Common build attributes")
320 _topLevel.SubTask("property", name="SINGLE_MODULE_BUILD", value="yes")
321 _topLevel.SubTask("property", name="MODULE_BUILD_TARGET", value="single_module_build")
322 _topLevel.SubTask("property", name="PLATFORM_PREBUILD", value="yes")
323 _topLevel.SubTask("property", name="PLATFORM_POSTBUILD", value="no")
324
325 _topLevel.Blankline()
326 _topLevel.Comment(" TODO ")
327 ifTask = _topLevel.SubTask("if")
328 ifTask.SubTask("istrue", value="${SINGLE_MODULE_BUILD}")
329 thenTask = ifTask.SubTask("then")
330 platformBuildFile = os.path.join("${WORKSPACE_DIR}", self.Platform.OutputPath,
331 self.Target + "_" + self.Toolchain, "build.xml")
332 thenTask.SubTask("import", file=platformBuildFile)
333
334 _topLevel.Blankline()
335 _topLevel.SubTask("property", name="ARCH", value=self.Arch)
336
337 module = self.Module.Module
338 package = module.Package
339 _topLevel.Blankline()
340 _topLevel.SubTask("property", name="PACKAGE", value=package.Name)
341 _topLevel.SubTask("property", name="PACKAGE_GUID", value=package.GuidValue)
342 _topLevel.SubTask("property", name="PACKAGE_VERSION", value=package.Version)
343 _topLevel.SubTask("property", name="PACKAGE_RELATIVE_DIR", value=package.Dir)
344 _topLevel.SubTask("property", name="PACKAGE_DIR", value=os.path.join("${WORKSPACE_DIR}","${PACKAGE_RELATIVE_DIR}"))
345
346 _topLevel.Blankline()
347 _topLevel.SubTask("property", name="MODULE", value=module.Name)
348 _topLevel.SubTask("property", name="MODULE_GUID", value=module.GuidValue)
349 _topLevel.SubTask("property", name="MODULE_VERSION", value=module.Version)
350 _topLevel.SubTask("property", name="MODULE_TYPE", value=module.Type)
351 _topLevel.SubTask("property", name="MODULE_FILE_BASE_NAME", value=module.FileBaseName)
352 _topLevel.SubTask("property", name="MODULE_RELATIVE_DIR", value=module.Dir)
353 _topLevel.SubTask("property", name="MODULE_DIR", value=os.path.join("${PACKAGE_DIR}", "${MODULE_RELATIVE_DIR}"))
354 _topLevel.SubTask("property", name="BASE_NAME", value=module.BaseName)
355
356 _topLevel.Blankline()
357 _topLevel.SubTask("property", file="${WORKSPACE_DIR}/Tools/Python/buildgen/module_build_path.txt")
358
359 self._BuildOption()
360
361 _topLevel.Blankline()
362 _topLevel.SubTask("property", name="ENTRYPOINT", value="_ModuleEntryPoint")
363
364 _topLevel.SubTask("property", name="SOURCE_FILES", value="\n ".join(self._GetSourceFileList()))
365 _topLevel.SubTask("property", name="LIBS", value="\n ".join(self._GetLibList()))
366
367 _topLevel.Blankline()
368 _topLevel.SubTask("property", file="${PLATFORM_BUILD_DIR}/%s_build.opt" % self.Arch)
369 _topLevel.Blankline()
370 _topLevel.SubTask("echo", message="${MODULE}-${MODULE_VERSION} [${ARCH}] from package ${PACKAGE}-${PACKAGE_VERSION} (${MODULE_RELATIVE_DIR})", level="info")
371
372 _topLevel.Blankline()
373 _topLevel.Comment("Default target")
374 _topLevel.SubTask("target", name="all", depends="single_module_build")
375 _topLevel.SubTask("target", name="platform_module_build", depends="prebuild, sourcefiles, sections, output, postbuild")
376 _topLevel.SubTask("target", name="single_module_build", depends="prebuild, libraries, sourcefiles, sections, output, postbuild")
377
378 def _BuildOption(self):
379 _topLevel = self.BuildXml
380 _topLevel.Blankline()
381 baseModule = self.Module.Module
382 tools = self.Workspace.ToolConfig.ToolCodes
383
384 for tool in tools:
385 key = (self.Toolchain, self.Target, self.Arch, tool, "FLAGS")
386 flag = ""
387 if key in baseModule.BuildOptions:
388 flag = baseModule.BuildOptions[key]
389 _topLevel.SubTask("property", name="DEFAULT_MODULE_%s_FLAGS" % tool, value=flag)
390
391 _topLevel.Blankline()
392 for tool in tools:
393 key = (self.Toolchain, self.Target, self.Arch, tool, "FLAGS")
394 flag = ""
395 if key in self.Module.BuildOptions:
396 flag = self.Module.BuildOptions[key]
397 _topLevel.SubTask("property", name="MODULE_%s_FLAGS" % tool, value=flag)
398
399 def PreBuild(self):
400 _topLevel = self.BuildXml
401 _topLevel.Blankline()
402 _topLevel.Comment(" TARGET: prebuild ")
403
404 prebuildTasks = []
405 module = self.Module.Module
406 if module.UserExtensions.has_key("0"):
407 prebuildTasks = module.UserExtensions["0"]
408 elif module.UserExtensions.has_key("postbuild"):
409 prebuildTasks = module.UserExtensions["prebuild"]
410
411 _topLevel.SubTask("target", prebuildTasks, name="prebuild")
412
413
414 def Libraries(self):
415 _topLevel = self.BuildXml
416 _topLevel.Blankline()
417 _topLevel.Comment(" TARGET: libraries ")
418
419 librariesTarget = _topLevel.SubTask("target", name="libraries")
420 parallelBuild = librariesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")
421 for lib in self.Module.Libraries:
422 module = lib.Module
423 buildDir = os.path.join("${BIN_DIR}", module.Package.SubPath(module.Dir), module.FileBaseName)
424 libTask = parallelBuild.SubTask("ant", dir=buildDir,
425 inheritAll="false",
426 target="${MODULE_BUILD_TARGET}")
427 libTask.SubTask("property", name="PLATFORM_PREBUILD", value="false")
428 libTask.SubTask("property", name="PLATFORM_POSTBUILD", value="false")
429
430 def Sourcefiles(self):
431 _topLevel = self.BuildXml
432 _topLevel.Blankline()
433 _topLevel.Comment(" TARGET: sourcefiles ")
434 _sourcefilesTarget = _topLevel.SubTask("target", name="sourcefiles")
435
436 _incTask = AntTask(self.BuildXml.Document, "EXTRA.INC")
437 _incTask.SubTask("includepath", path="${WORKSPACE_DIR}")
438 _incTask.SubTask("includepath", path="${MODULE_DIR}")
439 _incTask.SubTask("includepath", path=os.path.join("${MODULE_DIR}", self.Arch.capitalize()))
440 _incTask.SubTask("includepath", path="${DEST_DIR_DEBUG}")
441 if self.Arch in self.Module.Module.IncludePaths:
442 for inc in self.Module.Module.IncludePaths[self.Arch]:
443 _incTask.SubTask("includepath", path=os.path.join("${WORKSPACE_DIR}", inc))
444
445 # init
446 if not self.Module.Module.IsBinary:
447 _buildTask = _sourcefilesTarget.SubTask("Build_Init")
448 _buildTask.AddSubTask(_incTask)
449
450 # AutoGen firt
451 _buildTask = _sourcefilesTarget.SubTask("Build_AUTOGEN", FILEEXT="c", FILENAME="AutoGen", FILEPATH=".")
452 _buildTask.AddSubTask(_incTask)
453
454 # uni file follows
455 type = "UNI"
456 if type in self.SourceFiles:
457 for srcpath in self.SourceFiles[type]:
458 taskName = "Build_" + type
459 fileDir = os.path.dirname(srcpath)
460 if fileDir == "": fileDir = "."
461 fileBaseName,fileExt = os.path.basename(srcpath).rsplit(".", 1)
462 _buildTask = _sourcefilesTarget.SubTask(taskName, FILENAME=fileBaseName, FILEEXT=fileExt, FILEPATH=fileDir)
463 _buildTask.AddSubTask(_incTask)
464
465 # others: c, vfr, ...
466 for type in self.SourceFiles:
467 if type == "Unicode": continue
468 for srcpath in self.SourceFiles[type]:
469 taskName = "Build_" + type
470 fileDir = os.path.dirname(srcpath)
471 if fileDir == "": fileDir = "."
472 fileBaseName,fileExt = os.path.basename(srcpath).rsplit(".", 1)
473 _buildTask = _sourcefilesTarget.SubTask(taskName, FILENAME=fileBaseName, FILEEXT=fileExt, FILEPATH=fileDir)
474 _buildTask.AddSubTask(_incTask)
475
476 def Sections(self):
477 _topLevel = self.BuildXml
478 _topLevel.Blankline()
479 _topLevel.Comment(" TARGET: sections ")
480 _sectionsTarget = _topLevel.SubTask("target", name="sections")
481
482 def Ffs(self):
483 _topLevel = self.BuildXml
484 _topLevel.Blankline()
485 _topLevel.Comment(" TARGET: output ")
486 _sectionsTarget = _topLevel.SubTask("target", name="output")
487
488 def PostBuild(self):
489 _topLevel = self.BuildXml
490 _topLevel.Blankline()
491 _topLevel.Comment(" TARGET: postbuild ")
492
493 postbuildTasks = []
494 module = self.Module.Module
495 if module.UserExtensions.has_key("1"):
496 postbuildTasks = module.UserExtensions["1"]
497 elif module.UserExtensions.has_key("postbuild"):
498 postbuildTasks = module.UserExtensions["postbuild"]
499
500 _topLevel.SubTask("target", postbuildTasks, name="postbuild")
501
502 def Clean(self):
503 pass
504
505 def CleanAll(self):
506 pass
507
508 def UserExtensions(self):
509 pass
510
511 def GetSourceFiles(self):
512 ## check arch, toolchain, family, toolcode, ext
513 ## if the arch of source file supports active arch
514 ## if the toolchain of source file supports active toolchain
515 ## if the toolchain family of source file supports active toolchain family
516 ## if the ext of the source file is supported by the toolcode
517 module = self.Module.Module
518 files = {} # file type -> src
519 for type in module.SourceFiles[self.Arch]:
520 if not module.IsBuildable(type):
521 # print type,"is not buildable"
522 continue
523
524 if type not in files:
525 files[type] = []
526 for src in module.SourceFiles[self.Arch][type]:
527 if self.Toolchain not in src.Toolchains:
528 # print self.Toolchain,"not in ",src.Toolchains
529 continue
530 if not self.IsCompatible(src.Families, self.Workspace.ActiveFamilies):
531 # print src.Families,"not compatible with",self.Workspace.ActiveFamilies
532 continue
533 toolcode = src.GetToolCode(src.Type)
534 if toolcode != "":
535 ext = self.Workspace.GetToolDef(self.Toolchain, self.Target, self.Arch, toolcode, "EXT")
536 if ext != "" and ext != src.Ext:
537 # print ext,"in tools_def.txt is not the same as",src.Ext
538 continue
539 ## fileFullPath = os.path.join("${MODULE_DIR}", )
540 ## print fileFullPath
541 files[type].append(src.Path)
542
543 return files
544
545 def Intersection(self, list1, list2):
546 return list(Set(list1) & Set(list2))
547
548 def IsCompatible(self, list1, list2):
549 return len(self.Intersection(list1, list2)) > 0
550
551 def _GetLibList(self):
552 libList = []
553 for lib in self.Module.Libraries:
554 module = lib.Module
555 libList.append(os.path.join("${BIN_DIR}", module.Name + ".lib"))
556 return libList
557
558 def _GetSourceFileList(self):
559 srcList = []
560 for type in self.SourceFiles:
561 srcList.extend(self.SourceFiles[type])
562 return srcList
563
564 class NmakeFile(BuildFile):
565 pass
566
567 class GmakeFile(BuildFile):
568 pass
569
570 # for test
571 if __name__ == "__main__":
572 workspacePath = os.getenv("WORKSPACE", os.getcwd())
573 startTime = time.clock()
574 ws = Workspace(workspacePath, [], [])
575
576 # generate build.xml
577 ap = ws.ActivePlatform
578 for target in ws.ActiveTargets:
579 ant = AntPlatformBuildFile(ws, ap, ws.ActiveToolchain, target)
580 ant.Generate()
581
582 print "\n[Finished in %fs]" % (time.clock() - startTime)