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