]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | This file is ANT task GenBuild.\r | |
3 | \r | |
4 | The file is used to parse a specified Module, and generate its build time\r | |
5 | ANT script build.xml, then call the the ANT script to build the module.\r | |
6 | \r | |
7 | Copyright (c) 2006, Intel Corporation\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | **/\r | |
16 | package org.tianocore.build;\r | |
17 | \r | |
18 | import java.io.File;\r | |
19 | import java.util.Hashtable;\r | |
20 | import java.util.Iterator;\r | |
21 | import java.util.LinkedHashSet;\r | |
22 | import java.util.List;\r | |
23 | import java.util.Map;\r | |
24 | import java.util.Set;\r | |
25 | import java.util.Vector;\r | |
26 | \r | |
27 | import org.apache.tools.ant.BuildException;\r | |
28 | import org.apache.tools.ant.BuildListener;\r | |
29 | import org.apache.tools.ant.Project;\r | |
30 | import org.apache.tools.ant.taskdefs.Ant;\r | |
31 | import org.apache.tools.ant.taskdefs.Property;\r | |
32 | import org.apache.xmlbeans.XmlObject;\r | |
33 | \r | |
34 | import org.tianocore.common.definitions.ToolDefinitions;\r | |
35 | import org.tianocore.common.exception.EdkException;\r | |
36 | import org.tianocore.common.logger.EdkLog;\r | |
37 | import org.tianocore.build.autogen.AutoGen;\r | |
38 | import org.tianocore.build.exception.AutoGenException;\r | |
39 | import org.tianocore.build.exception.GenBuildException;\r | |
40 | import org.tianocore.build.exception.PcdAutogenException;\r | |
41 | import org.tianocore.build.exception.PlatformPcdPreprocessBuildException;\r | |
42 | import org.tianocore.build.fpd.FpdParserTask;\r | |
43 | import org.tianocore.build.global.GlobalData;\r | |
44 | import org.tianocore.build.global.OutputManager;\r | |
45 | import org.tianocore.build.global.SurfaceAreaQuery;\r | |
46 | import org.tianocore.build.id.FpdModuleIdentification;\r | |
47 | import org.tianocore.build.id.ModuleIdentification;\r | |
48 | import org.tianocore.build.id.PackageIdentification;\r | |
49 | import org.tianocore.build.id.PlatformIdentification;\r | |
50 | import org.tianocore.build.tools.ModuleItem;\r | |
51 | \r | |
52 | /**\r | |
53 | <p>\r | |
54 | <code>GenBuildTask</code> is an ANT task that can be used in ANT build\r | |
55 | system. \r | |
56 | \r | |
57 | <p>The main function of this task is to parse module's surface area (MSA),\r | |
58 | then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r | |
59 | build script) and call this to build the module. The whole process including:\r | |
60 | \r | |
61 | <pre>\r | |
62 | 1. generate AutoGen.c and AutoGen.h; \r | |
63 | 2. build all dependent library instances;\r | |
64 | 3. build all source files inlcude AutoGen.c; \r | |
65 | 4. generate sections;\r | |
66 | 5. generate FFS file if it is driver module while LIB file if it is Library module.\r | |
67 | </pre>\r | |
68 | \r | |
69 | \r | |
70 | <p>\r | |
71 | The usage is (take module <em>HelloWorld</em> for example):\r | |
72 | </p>\r | |
73 | \r | |
74 | <pre>\r | |
75 | <GenBuild \r | |
76 | msaFile="${PACKAGE_DIR}/Application/HelloWorld/HelloWorld.msa"\r | |
77 | type="cleanall" />\r | |
78 | </pre>\r | |
79 | \r | |
80 | <p>\r | |
81 | This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and\r | |
82 | <em>AutoGen.h</em>. \r | |
83 | </p>\r | |
84 | \r | |
85 | <p>\r | |
86 | This task will also set properties for current module, such as PACKAGE, \r | |
87 | PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR \r | |
88 | (relative to Workspace), MODULE or BASE_NAME, GUID, VERSION, MODULE_DIR, \r | |
89 | MODULE_RELATIVE_DIR (relative to Package), CONFIG_DIR, BIN_DIR, \r | |
90 | DEST_DIR_DEBUG, DEST_DIR_OUTPUT, TARGET, ARCH, TOOLCHAIN, TOOLCHAIN_FAMILY, \r | |
91 | SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH, all compiler command related \r | |
92 | properties (CC, CC_FLAGS, CC_DPATH, CC_SPATH, CC_FAMILY, CC_EXT). \r | |
93 | </p>\r | |
94 | \r | |
95 | @since GenBuild 1.0\r | |
96 | **/\r | |
97 | public class GenBuildTask extends Ant {\r | |
98 | \r | |
99 | ///\r | |
100 | /// Module surface area file.\r | |
101 | ///\r | |
102 | File msaFile;\r | |
103 | \r | |
104 | public ModuleIdentification parentId;\r | |
105 | \r | |
106 | private String type = "all"; \r | |
107 | \r | |
108 | ///\r | |
109 | /// Module's Identification.\r | |
110 | ///\r | |
111 | private ModuleIdentification moduleId;\r | |
112 | \r | |
113 | private Vector<Property> properties = new Vector<Property>();\r | |
114 | \r | |
115 | private boolean isSingleModuleBuild = false;\r | |
116 | \r | |
117 | private SurfaceAreaQuery saq = null;\r | |
118 | \r | |
119 | /**\r | |
120 | Public construct method. It is necessary for ANT task.\r | |
121 | **/\r | |
122 | public GenBuildTask() {\r | |
123 | }\r | |
124 | \r | |
125 | /**\r | |
126 | \r | |
127 | @throws BuildException\r | |
128 | From module build, exception from module surface area invalid.\r | |
129 | **/\r | |
130 | public void execute() throws BuildException {\r | |
131 | this.setTaskName("GenBuild");\r | |
132 | try {\r | |
133 | processGenBuild();\r | |
134 | } catch (PcdAutogenException e) {\r | |
135 | BuildException buildException = new BuildException(e.getMessage());\r | |
136 | buildException.setStackTrace(e.getStackTrace());\r | |
137 | throw buildException;\r | |
138 | } catch (AutoGenException e) {\r | |
139 | BuildException buildException = new BuildException(e.getMessage());\r | |
140 | buildException.setStackTrace(e.getStackTrace());\r | |
141 | throw buildException;\r | |
142 | } catch (PlatformPcdPreprocessBuildException e) {\r | |
143 | BuildException buildException = new BuildException(e.getMessage());\r | |
144 | buildException.setStackTrace(e.getStackTrace());\r | |
145 | throw buildException;\r | |
146 | } catch (GenBuildException e) {\r | |
147 | BuildException buildException = new BuildException(e.getMessage());\r | |
148 | buildException.setStackTrace(e.getStackTrace());\r | |
149 | throw buildException;\r | |
150 | } catch (EdkException e) {\r | |
151 | BuildException buildException = new BuildException(e.getMessage());\r | |
152 | buildException.setStackTrace(e.getStackTrace());\r | |
153 | throw buildException;\r | |
154 | }\r | |
155 | }\r | |
156 | \r | |
157 | private void processGenBuild() throws EdkException, BuildException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException {\r | |
158 | if (!FrameworkBuildTask.multithread) {\r | |
159 | cleanupProperties();\r | |
160 | }\r | |
161 | \r | |
162 | //\r | |
163 | // Enable all specified properties\r | |
164 | //\r | |
165 | Iterator<Property> iter = properties.iterator();\r | |
166 | while (iter.hasNext()) {\r | |
167 | Property item = iter.next();\r | |
168 | getProject().setProperty(item.getName(), item.getValue());\r | |
169 | }\r | |
170 | \r | |
171 | //\r | |
172 | // GenBuild should specify either msaFile or moduleGuid & packageGuid\r | |
173 | //\r | |
174 | if (msaFile == null ) {\r | |
175 | String moduleGuid = getProject().getProperty("MODULE_GUID");\r | |
176 | String moduleVersion = getProject().getProperty("MODULE_VERSION");\r | |
177 | String packageGuid = getProject().getProperty("PACKAGE_GUID");\r | |
178 | String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r | |
179 | //\r | |
180 | // If one of module Guid or package Guid is not specified, report error\r | |
181 | //\r | |
182 | if (moduleGuid == null || packageGuid == null) {\r | |
183 | throw new BuildException("GenBuild parameter error.");\r | |
184 | }\r | |
185 | \r | |
186 | PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r | |
187 | GlobalData.refreshPackageIdentification(packageId);\r | |
188 | moduleId = new ModuleIdentification(moduleGuid, moduleVersion);\r | |
189 | moduleId.setPackage(packageId);\r | |
190 | GlobalData.refreshModuleIdentification(moduleId);\r | |
191 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);\r | |
192 | saq = new SurfaceAreaQuery(doc);\r | |
193 | } else {\r | |
194 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r | |
195 | saq = new SurfaceAreaQuery(doc);\r | |
196 | moduleId = saq.getMsaHeader();\r | |
197 | moduleId.setMsaFile(msaFile);\r | |
198 | }\r | |
199 | \r | |
200 | String[] producedLibraryClasses = saq.getLibraryClasses("ALWAYS_PRODUCED",null);\r | |
201 | if (producedLibraryClasses.length == 0) {\r | |
202 | moduleId.setLibrary(false);\r | |
203 | } else {\r | |
204 | moduleId.setLibrary(true);\r | |
205 | }\r | |
206 | \r | |
207 | //\r | |
208 | // Judge whether it is single module build or not\r | |
209 | //\r | |
210 | if (isSingleModuleBuild) {\r | |
211 | //\r | |
212 | // Single Module build\r | |
213 | //\r | |
214 | prepareSingleModuleBuild();\r | |
215 | }\r | |
216 | \r | |
217 | //\r | |
218 | // If single module : get arch from pass down, otherwise intersection MSA \r | |
219 | // supported ARCHs and tools def\r | |
220 | //\r | |
221 | Set<String> archListSupByToolChain = new LinkedHashSet<String>();\r | |
222 | String[] archs = GlobalData.getToolChainInfo().getArchs();\r | |
223 | \r | |
224 | for (int i = 0; i < archs.length; i ++) {\r | |
225 | archListSupByToolChain.add(archs[i]);\r | |
226 | }\r | |
227 | \r | |
228 | Set<String> archSet = new LinkedHashSet<String>();\r | |
229 | \r | |
230 | if ( getProject().getProperty("ARCH") != null) {\r | |
231 | String[] fpdArchList = getProject().getProperty("ARCH").split(" ");\r | |
232 | \r | |
233 | for (int i = 0; i < fpdArchList.length; i++) {\r | |
234 | if (archListSupByToolChain.contains(fpdArchList[i])) {\r | |
235 | archSet.add(fpdArchList[i]);\r | |
236 | }\r | |
237 | }\r | |
238 | } else {\r | |
239 | archSet = archListSupByToolChain; \r | |
240 | }\r | |
241 | \r | |
242 | String[] archList = archSet.toArray(new String[archSet.size()]);\r | |
243 | \r | |
244 | //\r | |
245 | // Judge if arch is all supported by current module. If not, throw Exception.\r | |
246 | //\r | |
247 | List moduleSupportedArchs = saq.getModuleSupportedArchs();\r | |
248 | if (moduleSupportedArchs != null) {\r | |
249 | for (int k = 0; k < archList.length; k++) {\r | |
250 | if ( ! moduleSupportedArchs.contains(archList[k])) {\r | |
251 | throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");\r | |
252 | }\r | |
253 | }\r | |
254 | }\r | |
255 | \r | |
256 | if (archList.length == 0) {\r | |
257 | EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + moduleId + " was not found in current platform FPD file!\n");\r | |
258 | }\r | |
259 | \r | |
260 | for (int k = 0; k < archList.length; k++) {\r | |
261 | \r | |
262 | getProject().setProperty("ARCH", archList[k]);\r | |
263 | \r | |
264 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r | |
265 | \r | |
266 | //\r | |
267 | // Whether the module is built before\r | |
268 | //\r | |
269 | if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {\r | |
270 | EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");\r | |
271 | continue;\r | |
272 | } else if (GlobalData.isModuleBuilt(fpdModuleId)) {\r | |
273 | break;\r | |
274 | } else {\r | |
275 | GlobalData.registerBuiltModule(fpdModuleId);\r | |
276 | }\r | |
277 | \r | |
278 | //\r | |
279 | // For Every TOOLCHAIN, TARGET\r | |
280 | //\r | |
281 | String[] targetList = GlobalData.getToolChainInfo().getTargets();\r | |
282 | for (int i = 0; i < targetList.length; i ++){\r | |
283 | //\r | |
284 | // Prepare for target related common properties\r | |
285 | // TARGET\r | |
286 | //\r | |
287 | getProject().setProperty("TARGET", targetList[i]);\r | |
288 | String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r | |
289 | for(int j = 0; j < toolchainList.length; j ++){\r | |
290 | //\r | |
291 | // check if any tool is defined for current target + toolchain + arch\r | |
292 | // don't do anything if no tools found\r | |
293 | //\r | |
294 | if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {\r | |
295 | EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: No build issued. No tools found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");\r | |
296 | continue;\r | |
297 | }\r | |
298 | \r | |
299 | //\r | |
300 | // Prepare for toolchain related common properties\r | |
301 | // TOOLCHAIN\r | |
302 | //\r | |
303 | getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r | |
304 | \r | |
305 | EdkLog.log(this, "Build " + moduleId + " start >>>");\r | |
306 | EdkLog.log(this, "Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);\r | |
307 | saq.push(GlobalData.getDoc(fpdModuleId));\r | |
308 | \r | |
309 | //\r | |
310 | // Prepare for all other common properties\r | |
311 | // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
312 | // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r | |
313 | // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
314 | // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r | |
315 | //\r | |
316 | setModuleCommonProperties(archList[k]);\r | |
317 | \r | |
318 | //\r | |
319 | // OutputManage prepare for\r | |
320 | // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r | |
321 | //\r | |
322 | OutputManager.getInstance().update(getProject());\r | |
323 | \r | |
324 | if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r | |
325 | applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r | |
326 | } else if (type.equalsIgnoreCase("clean")) {\r | |
327 | applyClean(fpdModuleId);\r | |
328 | } else if (type.equalsIgnoreCase("cleanall")) {\r | |
329 | applyCleanall(fpdModuleId);\r | |
330 | }\r | |
331 | }\r | |
332 | }\r | |
333 | }\r | |
334 | }\r | |
335 | \r | |
336 | /**\r | |
337 | This method is used to prepare Platform-related information.\r | |
338 | \r | |
339 | <p>In Single Module Build mode, platform-related information is not ready.\r | |
340 | The method read the system environment variable <code>ACTIVE_PLATFORM</code>\r | |
341 | and search in the Framework Database. Note that platform name in the Framework\r | |
342 | Database must be unique. </p>\r | |
343 | \r | |
344 | **/\r | |
345 | private void prepareSingleModuleBuild() throws EdkException {\r | |
346 | //\r | |
347 | // Find out the package which the module belongs to\r | |
348 | //\r | |
349 | PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r | |
350 | GlobalData.refreshPackageIdentification(packageId);\r | |
351 | moduleId.setPackage(packageId);\r | |
352 | GlobalData.refreshModuleIdentification(moduleId);\r | |
353 | \r | |
354 | //\r | |
355 | // Read ACTIVE_PLATFORM's FPD file \r | |
356 | //\r | |
357 | String filename = getProject().getProperty("PLATFORM_FILE");\r | |
358 | \r | |
359 | if (filename == null){\r | |
360 | throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");\r | |
361 | }\r | |
362 | \r | |
363 | PlatformIdentification platformId = GlobalData.getPlatform(filename);\r | |
364 | \r | |
365 | //\r | |
366 | // Read FPD file (Call FpdParserTask's method)\r | |
367 | //\r | |
368 | FpdParserTask fpdParser = new FpdParserTask();\r | |
369 | fpdParser.setProject(getProject());\r | |
370 | fpdParser.parseFpdFile(platformId.getFpdFile());\r | |
371 | getProject().setProperty("ARCH", fpdParser.getAllArchForModule(moduleId));\r | |
372 | }\r | |
373 | \r | |
374 | private void cleanupProperties() {\r | |
375 | Project newProject = new Project();\r | |
376 | \r | |
377 | Hashtable<String, String> passdownProperties = FrameworkBuildTask.originalProperties;\r | |
378 | Iterator<String> iter = passdownProperties.keySet().iterator();\r | |
379 | while (iter.hasNext()) {\r | |
380 | String item = iter.next();\r | |
381 | newProject.setProperty(item, passdownProperties.get(item));\r | |
382 | }\r | |
383 | \r | |
384 | newProject.setInputHandler(getProject().getInputHandler());\r | |
385 | \r | |
386 | Iterator listenerIter = getProject().getBuildListeners().iterator();\r | |
387 | while (listenerIter.hasNext()) {\r | |
388 | newProject.addBuildListener((BuildListener) listenerIter.next());\r | |
389 | }\r | |
390 | \r | |
391 | getProject().initSubProject(newProject);\r | |
392 | \r | |
393 | setProject(newProject);\r | |
394 | }\r | |
395 | \r | |
396 | /**\r | |
397 | Set Module-Related information to properties.\r | |
398 | \r | |
399 | @param arch current build ARCH\r | |
400 | **/\r | |
401 | private void setModuleCommonProperties(String arch) {\r | |
402 | //\r | |
403 | // Prepare for all other common properties\r | |
404 | // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
405 | //\r | |
406 | PackageIdentification packageId = moduleId.getPackage();\r | |
407 | getProject().setProperty("PACKAGE", packageId.getName());\r | |
408 | getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r | |
409 | getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r | |
410 | getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r | |
411 | getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r | |
412 | \r | |
413 | //\r | |
414 | // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r | |
415 | // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
416 | //\r | |
417 | getProject().setProperty("MODULE", moduleId.getName());\r | |
418 | String baseName = saq.getModuleOutputFileBasename();\r | |
419 | if (baseName == null) {\r | |
420 | getProject().setProperty("BASE_NAME", moduleId.getName());\r | |
421 | } else {\r | |
422 | getProject().setProperty("BASE_NAME", baseName);\r | |
423 | }\r | |
424 | getProject().setProperty("GUID", moduleId.getGuid());\r | |
425 | getProject().setProperty("FILE_GUID", moduleId.getGuid());\r | |
426 | getProject().setProperty("VERSION", moduleId.getVersion());\r | |
427 | getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());\r | |
428 | getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r | |
429 | getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/") + File.separatorChar + moduleId.getName());\r | |
430 | \r | |
431 | //\r | |
432 | // SUBSYSTEM\r | |
433 | //\r | |
434 | String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},\r | |
435 | { "SEC", "EFI_BOOT_SERVICE_DRIVER" },\r | |
436 | { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r | |
437 | { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },\r | |
438 | { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r | |
439 | { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r | |
440 | { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },\r | |
441 | { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r | |
442 | { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r | |
443 | { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },\r | |
444 | { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r | |
445 | { "UEFI_APPLICATION", "EFI_APPLICATION" },\r | |
446 | { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };\r | |
447 | \r | |
448 | String subsystem = "EFI_BOOT_SERVICE_DRIVER";\r | |
449 | for (int i = 0; i < subsystemMap.length; i++) {\r | |
450 | if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {\r | |
451 | subsystem = subsystemMap[i][1];\r | |
452 | break ;\r | |
453 | }\r | |
454 | }\r | |
455 | getProject().setProperty("SUBSYSTEM", subsystem);\r | |
456 | \r | |
457 | //\r | |
458 | // ENTRYPOINT\r | |
459 | //\r | |
460 | if (arch.equalsIgnoreCase("EBC")) {\r | |
461 | getProject().setProperty("ENTRYPOINT", "EfiStart");\r | |
462 | } else {\r | |
463 | getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r | |
464 | }\r | |
465 | \r | |
466 | getProject().setProperty("OBJECTS", "");\r | |
467 | }\r | |
468 | \r | |
469 | private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {\r | |
470 | String[] cmd = GlobalData.getToolChainInfo().getCommands();\r | |
471 | for ( int m = 0; m < cmd.length; m++) {\r | |
472 | //\r | |
473 | // Set cmd, like CC, DLINK\r | |
474 | //\r | |
475 | String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};\r | |
476 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_PATH;\r | |
477 | String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
478 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME;\r | |
479 | String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
480 | if (cmdName.length() == 0) {\r | |
481 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "Warning: " + cmd[m] + " hasn't been defined!");\r | |
482 | getProject().setProperty(cmd[m], "");\r | |
483 | continue;\r | |
484 | }\r | |
485 | File cmdFile = new File(cmdPath + File.separatorChar + cmdName);\r | |
486 | getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r | |
487 | \r | |
488 | //\r | |
489 | // set CC_FLAGS\r | |
490 | //\r | |
491 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS;\r | |
492 | String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
493 | if (cmdFlags != null) \r | |
494 | {\r | |
495 | getProject().setProperty(cmd[m] + "_FLAGS", cmdFlags);\r | |
496 | } \r | |
497 | else \r | |
498 | {\r | |
499 | getProject().setProperty(cmd[m] + "_FLAGS", "");\r | |
500 | }\r | |
501 | \r | |
502 | //\r | |
503 | // Set CC_EXT\r | |
504 | //\r | |
505 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT;\r | |
506 | String extName = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
507 | if ( extName != null && ! extName.equalsIgnoreCase("")) {\r | |
508 | getProject().setProperty(cmd[m] + "_EXT", extName);\r | |
509 | } else {\r | |
510 | getProject().setProperty(cmd[m] + "_EXT", "");\r | |
511 | }\r | |
512 | \r | |
513 | //\r | |
514 | // set CC_FAMILY\r | |
515 | //\r | |
516 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY;\r | |
517 | String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
518 | if (toolChainFamily != null) {\r | |
519 | getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r | |
520 | }\r | |
521 | \r | |
522 | //\r | |
523 | // set CC_SPATH\r | |
524 | //\r | |
525 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH;\r | |
526 | String spath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
527 | if (spath != null) {\r | |
528 | getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r | |
529 | } else {\r | |
530 | getProject().setProperty(cmd[m] + "_SPATH", "");\r | |
531 | }\r | |
532 | \r | |
533 | //\r | |
534 | // set CC_DPATH\r | |
535 | //\r | |
536 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH;\r | |
537 | String dpath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
538 | if (dpath != null) {\r | |
539 | getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r | |
540 | } else {\r | |
541 | getProject().setProperty(cmd[m] + "_DPATH", "");\r | |
542 | }\r | |
543 | \r | |
544 | //\r | |
545 | // Set CC_LIBPATH\r | |
546 | //\r | |
547 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_LIBPATH;\r | |
548 | String libpath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
549 | if (libpath != null) {\r | |
550 | getProject().setProperty(cmd[m] + "_LIBPATH", libpath.replaceAll("(\\\\)", "/"));\r | |
551 | } else {\r | |
552 | getProject().setProperty(cmd[m] + "_LIBPATH", "");\r | |
553 | }\r | |
554 | \r | |
555 | //\r | |
556 | // Set CC_INCLUDEPATH\r | |
557 | //\r | |
558 | key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_INCLUDEPATH;\r | |
559 | String includepath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
560 | if (dpath != null) {\r | |
561 | getProject().setProperty(cmd[m] + "_INCLUDEPATH", includepath.replaceAll("(\\\\)", "/"));\r | |
562 | } else {\r | |
563 | getProject().setProperty(cmd[m] + "_INCLUDEPATH", "");\r | |
564 | }\r | |
565 | }\r | |
566 | }\r | |
567 | \r | |
568 | public void setMsaFile(File msaFile) {\r | |
569 | this.msaFile = msaFile;\r | |
570 | }\r | |
571 | \r | |
572 | /**\r | |
573 | Method is for ANT to initialize MSA file.\r | |
574 | \r | |
575 | @param msaFilename MSA file name\r | |
576 | **/\r | |
577 | public void setMsaFile(String msaFilename) {\r | |
578 | String moduleDir = getProject().getProperty("MODULE_DIR");\r | |
579 | \r | |
580 | //\r | |
581 | // If is Single Module Build, then use the Base Dir defined in build.xml\r | |
582 | //\r | |
583 | if (moduleDir == null) {\r | |
584 | moduleDir = getProject().getBaseDir().getPath();\r | |
585 | }\r | |
586 | msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r | |
587 | }\r | |
588 | \r | |
589 | public void addConfiguredModuleItem(ModuleItem moduleItem) {\r | |
590 | PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());\r | |
591 | ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());\r | |
592 | moduleId.setPackage(packageId);\r | |
593 | this.moduleId = moduleId;\r | |
594 | }\r | |
595 | \r | |
596 | /**\r | |
597 | Add a property.\r | |
598 | \r | |
599 | @param p property\r | |
600 | **/\r | |
601 | public void addProperty(Property p) {\r | |
602 | properties.addElement(p);\r | |
603 | }\r | |
604 | \r | |
605 | public void setType(String type) {\r | |
606 | this.type = type;\r | |
607 | }\r | |
608 | \r | |
609 | private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException {\r | |
610 | //\r | |
611 | // Call AutoGen to generate AutoGen.c and AutoGen.h\r | |
612 | //\r | |
613 | AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch(), saq, parentId);\r | |
614 | autogen.genAutogen();\r | |
615 | \r | |
616 | //\r | |
617 | // Get compiler flags\r | |
618 | //\r | |
619 | try {\r | |
620 | getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r | |
621 | }\r | |
622 | catch (EdkException ee) {\r | |
623 | throw new BuildException(ee.getMessage());\r | |
624 | }\r | |
625 | \r | |
626 | //\r | |
627 | // Prepare LIBS\r | |
628 | //\r | |
629 | ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch());\r | |
630 | String propertyLibs = "";\r | |
631 | for (int i = 0; i < libinstances.length; i++) {\r | |
632 | propertyLibs += getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib" + " ";\r | |
633 | }\r | |
634 | getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r | |
635 | \r | |
636 | //\r | |
637 | // Get all includepath and set to INCLUDE_PATHS\r | |
638 | //\r | |
639 | String[] includes = prepareIncludePaths(fpdModuleId);\r | |
640 | \r | |
641 | //\r | |
642 | // if it is CUSTOM_BUILD\r | |
643 | // then call the exist BaseName_build.xml directly.\r | |
644 | //\r | |
645 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
646 | EdkLog.log(this, "Call user-defined " + moduleId.getName() + "_build.xml");\r | |
647 | \r | |
648 | String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
649 | antCall(antFilename, null);\r | |
650 | \r | |
651 | return ;\r | |
652 | }\r | |
653 | \r | |
654 | //\r | |
655 | // Generate ${BASE_NAME}_build.xml\r | |
656 | // TBD\r | |
657 | //\r | |
658 | String ffsKeyword = saq.getModuleFfsKeyword();\r | |
659 | ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId, includes, saq);\r | |
660 | String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
661 | fileGenerator.genBuildFile(buildFilename);\r | |
662 | \r | |
663 | //\r | |
664 | // Ant call ${BASE_NAME}_build.xml\r | |
665 | //\r | |
666 | String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
667 | antCall(antFilename, null);\r | |
668 | }\r | |
669 | \r | |
670 | private void applyClean(FpdModuleIdentification fpdModuleId){\r | |
671 | //\r | |
672 | // if it is CUSTOM_BUILD\r | |
673 | // then call the exist BaseName_build.xml directly.\r | |
674 | //\r | |
675 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
676 | EdkLog.log(this, "Calling user-defined " + moduleId.getName() + "_build.xml");\r | |
677 | \r | |
678 | String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
679 | antCall(antFilename, "clean");\r | |
680 | \r | |
681 | return ;\r | |
682 | }\r | |
683 | \r | |
684 | String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
685 | antCall(antFilename, "clean");\r | |
686 | }\r | |
687 | \r | |
688 | private void applyCleanall(FpdModuleIdentification fpdModuleId){\r | |
689 | //\r | |
690 | // if it is CUSTOM_BUILD\r | |
691 | // then call the exist BaseName_build.xml directly.\r | |
692 | //\r | |
693 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
694 | EdkLog.log(this, "Calling user-defined " + moduleId.getName() + "_build.xml");\r | |
695 | \r | |
696 | String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
697 | antCall(antFilename, "cleanall");\r | |
698 | \r | |
699 | return ;\r | |
700 | }\r | |
701 | \r | |
702 | String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
703 | antCall(antFilename, "cleanall");\r | |
704 | }\r | |
705 | \r | |
706 | private void antCall(String antFilename, String target) {\r | |
707 | Ant ant = new Ant();\r | |
708 | ant.setProject(getProject());\r | |
709 | ant.setAntfile(antFilename);\r | |
710 | if (target != null) {\r | |
711 | ant.setTarget(target);\r | |
712 | }\r | |
713 | ant.setInheritAll(true);\r | |
714 | ant.init();\r | |
715 | ant.execute();\r | |
716 | }\r | |
717 | \r | |
718 | public void setSingleModuleBuild(boolean isSingleModuleBuild) {\r | |
719 | this.isSingleModuleBuild = isSingleModuleBuild;\r | |
720 | }\r | |
721 | \r | |
722 | private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) throws EdkException{\r | |
723 | //\r | |
724 | // Prepare the includes: PackageDependencies and Output debug direactory\r | |
725 | //\r | |
726 | Set<String> includes = new LinkedHashSet<String>();\r | |
727 | String arch = fpdModuleId.getArch();\r | |
728 | \r | |
729 | //\r | |
730 | // WORKSPACE\r | |
731 | //\r | |
732 | includes.add("${WORKSPACE_DIR}" + File.separatorChar);\r | |
733 | \r | |
734 | //\r | |
735 | // Module iteself\r | |
736 | //\r | |
737 | includes.add("${MODULE_DIR}");\r | |
738 | includes.add("${MODULE_DIR}" + File.separatorChar + archDir(arch));\r | |
739 | \r | |
740 | //\r | |
741 | // Packages in PackageDenpendencies\r | |
742 | //\r | |
743 | PackageIdentification[] packageDependencies = saq.getDependencePkg(fpdModuleId.getArch());\r | |
744 | for (int i = 0; i < packageDependencies.length; i++) {\r | |
745 | GlobalData.refreshPackageIdentification(packageDependencies[i]);\r | |
746 | File packageFile = packageDependencies[i].getSpdFile();\r | |
747 | includes.add(packageFile.getParent() + File.separatorChar + "Include");\r | |
748 | includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r | |
749 | }\r | |
750 | \r | |
751 | //\r | |
752 | // All Dependency Library Instance's PackageDependencies\r | |
753 | //\r | |
754 | ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch());\r | |
755 | for (int i = 0; i < libinstances.length; i++) {\r | |
756 | saq.push(GlobalData.getDoc(libinstances[i], fpdModuleId.getArch()));\r | |
757 | PackageIdentification[] libraryPackageDependencies = saq.getDependencePkg(fpdModuleId.getArch());\r | |
758 | for (int j = 0; j < libraryPackageDependencies.length; j++) {\r | |
759 | GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]);\r | |
760 | File packageFile = libraryPackageDependencies[j].getSpdFile();\r | |
761 | includes.add(packageFile.getParent() + File.separatorChar + "Include");\r | |
762 | includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r | |
763 | }\r | |
764 | saq.pop();\r | |
765 | }\r | |
766 | \r | |
767 | \r | |
768 | //\r | |
769 | // The package which the module belongs to\r | |
770 | // TBD\r | |
771 | includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include");\r | |
772 | includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r | |
773 | \r | |
774 | //\r | |
775 | // Debug files output directory\r | |
776 | //\r | |
777 | includes.add("${DEST_DIR_DEBUG}");\r | |
778 | \r | |
779 | //\r | |
780 | // set to INCLUDE_PATHS property\r | |
781 | //\r | |
782 | Iterator<String> iter = includes.iterator();\r | |
783 | StringBuffer includePaths = new StringBuffer();\r | |
784 | while (iter.hasNext()) {\r | |
785 | includePaths.append(iter.next());\r | |
786 | includePaths.append("; ");\r | |
787 | }\r | |
788 | getProject().setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/"));\r | |
789 | \r | |
790 | return includes.toArray(new String[includes.size()]);\r | |
791 | }\r | |
792 | \r | |
793 | /**\r | |
794 | Return the name of the directory that corresponds to the architecture.\r | |
795 | This is a translation from the XML Schema tag to a directory that\r | |
796 | corresponds to our directory name coding convention.\r | |
797 | \r | |
798 | **/\r | |
799 | private String archDir(String arch) {\r | |
800 | return arch.replaceFirst("X64", "x64")\r | |
801 | .replaceFirst("IPF", "Ipf")\r | |
802 | .replaceFirst("IA32", "Ia32")\r | |
803 | .replaceFirst("ARM", "Arm")\r | |
804 | .replaceFirst("EBC", "Ebc");\r | |
805 | }\r | |
806 | \r | |
807 | \r | |
808 | public void setExternalProperties(Vector<Property> v) {\r | |
809 | this.properties = v;\r | |
810 | }\r | |
811 | }\r |