]>
Commit | Line | Data |
---|---|---|
878ddf1f | 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 | |
3c696250 | 19 | import java.util.ArrayList;\r |
a29c47e0 | 20 | import java.util.Hashtable;\r |
878ddf1f | 21 | import java.util.Iterator;\r |
22 | import java.util.LinkedHashSet;\r | |
23 | import java.util.List;\r | |
24 | import java.util.Map;\r | |
25 | import java.util.Set;\r | |
a29c47e0 | 26 | import java.util.Stack;\r |
878ddf1f | 27 | import java.util.Vector;\r |
28 | import java.util.regex.Matcher;\r | |
29 | import java.util.regex.Pattern;\r | |
30 | \r | |
878ddf1f | 31 | import org.apache.tools.ant.BuildException;\r |
878ddf1f | 32 | import org.apache.tools.ant.taskdefs.Ant;\r |
a29c47e0 | 33 | import org.apache.tools.ant.taskdefs.Property;\r |
878ddf1f | 34 | import org.apache.xmlbeans.XmlObject;\r |
878ddf1f | 35 | \r |
136adffc | 36 | import org.tianocore.build.autogen.AutoGen;\r |
878ddf1f | 37 | import org.tianocore.build.fpd.FpdParserTask;\r |
136adffc | 38 | import org.tianocore.build.global.GenBuildLogger;\r |
878ddf1f | 39 | import org.tianocore.build.global.GlobalData;\r |
40 | import org.tianocore.build.global.OutputManager;\r | |
41 | import org.tianocore.build.global.SurfaceAreaQuery;\r | |
a29c47e0 | 42 | import org.tianocore.build.id.FpdModuleIdentification;\r |
43 | import org.tianocore.build.id.ModuleIdentification;\r | |
44 | import org.tianocore.build.id.PackageIdentification;\r | |
45 | import org.tianocore.build.id.PlatformIdentification;\r | |
46 | import org.tianocore.build.tools.ModuleItem;\r | |
136adffc | 47 | import org.tianocore.exception.EdkException;\r |
48 | import org.tianocore.logger.EdkLog;\r | |
878ddf1f | 49 | \r |
50 | /**\r | |
51 | <p>\r | |
52 | <code>GenBuildTask</code> is an ANT task that can be used in ANT build\r | |
53 | system. The main function of this task is to parse module's surface area,\r | |
54 | then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r | |
a29c47e0 | 55 | build script) and call this to build the module. The whole process including:\r |
56 | 1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances; \r | |
57 | 3. build all source files inlcude AutoGen.c; 4. generate sections;\r | |
58 | 5. generate FFS file if it is driver module while LIB file if it is Library module. \r | |
878ddf1f | 59 | </p>\r |
60 | \r | |
61 | <p>\r | |
62 | The usage is (take module <em>HelloWorld</em> for example):\r | |
63 | </p>\r | |
64 | \r | |
65 | <pre>\r | |
a29c47e0 | 66 | <GenBuild \r |
67 | msaFilename="HelloWorld.msa"/> \r | |
68 | processTo="ALL"/>\r | |
878ddf1f | 69 | </pre>\r |
70 | \r | |
a29c47e0 | 71 | <p><code>processTo</code> provides a way to customize the whole build process. \r |
72 | processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE. \r | |
73 | Default is ALL, means whole \r | |
74 | </p>\r | |
75 | \r | |
878ddf1f | 76 | <p>\r |
77 | This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and\r | |
78 | <em>AutoGen.h</em>. The task also parses the development environment\r | |
79 | configuration files, such as collecting package information, setting compiler\r | |
80 | flags and so on.\r | |
81 | </p>\r | |
82 | \r | |
83 | \r | |
84 | @since GenBuild 1.0\r | |
85 | **/\r | |
a29c47e0 | 86 | public class GenBuildTask extends Ant {\r |
87 | \r | |
878ddf1f | 88 | ///\r |
89 | /// Module surface area file.\r | |
90 | ///\r | |
a29c47e0 | 91 | File msaFile;\r |
878ddf1f | 92 | \r |
93 | ///\r | |
878ddf1f | 94 | /// \r |
878ddf1f | 95 | ///\r |
a29c47e0 | 96 | private String type = "all"; // = "build";\r |
97 | \r | |
878ddf1f | 98 | ///\r |
a29c47e0 | 99 | /// Module's Identification.\r |
878ddf1f | 100 | ///\r |
a29c47e0 | 101 | private ModuleIdentification moduleId;\r |
878ddf1f | 102 | \r |
a29c47e0 | 103 | private Vector<Property> properties = new Vector<Property>();\r |
de4bb9f6 | 104 | \r |
a29c47e0 | 105 | private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();\r |
106 | \r | |
de4bb9f6 | 107 | private boolean isSingleModuleBuild = false;\r |
a29c47e0 | 108 | \r |
878ddf1f | 109 | /**\r |
110 | Public construct method. It is necessary for ANT task.\r | |
111 | **/\r | |
112 | public GenBuildTask() {\r | |
113 | }\r | |
114 | \r | |
115 | /**\r | |
a29c47e0 | 116 | \r |
878ddf1f | 117 | @throws BuildException\r |
118 | From module build, exception from module surface area invalid.\r | |
119 | **/\r | |
120 | public void execute() throws BuildException {\r | |
136adffc | 121 | //\r |
122 | // set Logger\r | |
123 | //\r | |
124 | GenBuildLogger logger = new GenBuildLogger(getProject());\r | |
125 | EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));\r | |
126 | EdkLog.setLogger(logger);\r | |
127 | // remove !!\r | |
128 | try {\r | |
a29c47e0 | 129 | pushProperties();\r |
878ddf1f | 130 | //\r |
a29c47e0 | 131 | // Enable all specified properties\r |
878ddf1f | 132 | //\r |
a29c47e0 | 133 | Iterator<Property> iter = properties.iterator();\r |
134 | while (iter.hasNext()) {\r | |
135 | Property item = iter.next();\r | |
136 | getProject().setProperty(item.getName(), item.getValue());\r | |
878ddf1f | 137 | }\r |
a29c47e0 | 138 | \r |
878ddf1f | 139 | //\r |
a29c47e0 | 140 | // GenBuild should specify either msaFile or moduleGuid & packageGuid\r |
878ddf1f | 141 | //\r |
a29c47e0 | 142 | if (msaFile == null ) {\r |
143 | String moduleGuid = getProject().getProperty("MODULE_GUID");\r | |
144 | String moduleVersion = getProject().getProperty("MODULE_VERSION");\r | |
145 | String packageGuid = getProject().getProperty("PACKAGE_GUID");\r | |
146 | String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r | |
147 | if (moduleGuid == null || packageGuid == null) {\r | |
148 | throw new BuildException("GenBuild parameters error. ");\r | |
878ddf1f | 149 | }\r |
a29c47e0 | 150 | PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r |
151 | moduleId = new ModuleIdentification(moduleGuid, moduleVersion);\r | |
152 | moduleId.setPackage(packageId);\r | |
153 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);\r | |
154 | SurfaceAreaQuery.setDoc(doc);\r | |
155 | moduleId = SurfaceAreaQuery.getMsaHeader();\r | |
878ddf1f | 156 | }\r |
a29c47e0 | 157 | else {\r |
158 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r | |
159 | SurfaceAreaQuery.setDoc(doc);\r | |
160 | moduleId = SurfaceAreaQuery.getMsaHeader();\r | |
878ddf1f | 161 | }\r |
42b78757 | 162 | String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED",null);\r |
a29c47e0 | 163 | if (producedLibraryClasses.length == 0) {\r |
164 | moduleId.setLibrary(false);\r | |
878ddf1f | 165 | }\r |
a29c47e0 | 166 | else {\r |
167 | moduleId.setLibrary(true);\r | |
878ddf1f | 168 | }\r |
a29c47e0 | 169 | \r |
878ddf1f | 170 | //\r |
a29c47e0 | 171 | // Judge whether it is single module build or not\r |
878ddf1f | 172 | //\r |
de4bb9f6 | 173 | if (isSingleModuleBuild) {\r |
878ddf1f | 174 | //\r |
a29c47e0 | 175 | // Single Module build\r |
878ddf1f | 176 | //\r |
a29c47e0 | 177 | prepareSingleModuleBuild();\r |
178 | }\r | |
179 | else {\r | |
180 | //\r | |
181 | // Platform build. Restore the platform related info\r | |
182 | //\r | |
de4bb9f6 | 183 | String filename = getProject().getProperty("PLATFORM_FILE");\r |
184 | PlatformIdentification platformId = GlobalData.getPlatform(filename);\r | |
a29c47e0 | 185 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r |
186 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
878ddf1f | 187 | \r |
a29c47e0 | 188 | String packageGuid = getProject().getProperty("PACKAGE_GUID");\r |
189 | String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r | |
190 | PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r | |
191 | moduleId.setPackage(packageId);\r | |
878ddf1f | 192 | }\r |
a29c47e0 | 193 | \r |
194 | //\r | |
195 | // If single module : intersection MSA supported ARCHs and tools def!!\r | |
196 | // else, get arch from pass down\r | |
197 | //\r | |
3c696250 | 198 | Set<String> archListSupByToolChain = new LinkedHashSet<String>(); \r |
199 | String[] archs = GlobalData.getToolChainInfo().getArchs(); \r | |
200 | \r | |
201 | for (int i = 0; i < archs.length; i ++) {\r | |
202 | archListSupByToolChain.add(archs[i]);\r | |
203 | }\r | |
204 | \r | |
205 | Set<String> archSet = new LinkedHashSet<String>();\r | |
206 | \r | |
207 | if ( getProject().getProperty("ARCH") != null) {\r | |
208 | String[] fpdArchList = getProject().getProperty("ARCH").split(" ");\r | |
209 | \r | |
210 | for (int i = 0; i < fpdArchList.length; i++) {\r | |
211 | if (archListSupByToolChain.contains(fpdArchList[i])) {\r | |
212 | archSet.add(fpdArchList[i]);\r | |
213 | }\r | |
214 | }\r | |
215 | }\r | |
216 | else {\r | |
217 | archSet = archListSupByToolChain; \r | |
218 | }\r | |
219 | \r | |
220 | String[] archList = archSet.toArray(new String[archSet.size()]);\r | |
a29c47e0 | 221 | \r |
222 | //\r | |
223 | // Judge if arch is all supported by current module. If not, throw Exception.\r | |
224 | //\r | |
225 | List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();\r | |
226 | if (moduleSupportedArchs != null) {\r | |
227 | for (int k = 0; k < archList.length; k++) {\r | |
228 | if ( ! moduleSupportedArchs.contains(archList[k])) {\r | |
229 | throw new BuildException("ARCH [" + archList[k] + "] is not supported by " + moduleId + ". " + moduleId + " only supports [" + moduleSupportedArchs + "].");\r | |
230 | }\r | |
231 | }\r | |
878ddf1f | 232 | }\r |
a29c47e0 | 233 | \r |
234 | for (int k = 0; k < archList.length; k++) {\r | |
3c696250 | 235 | \r |
a29c47e0 | 236 | getProject().setProperty("ARCH", archList[k]);\r |
237 | \r | |
238 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r | |
239 | \r | |
878ddf1f | 240 | //\r |
a29c47e0 | 241 | // Whether the module is built before\r |
878ddf1f | 242 | //\r |
a29c47e0 | 243 | if (GlobalData.isModuleBuilt(fpdModuleId)) {\r |
244 | return ;\r | |
245 | }\r | |
246 | else {\r | |
247 | GlobalData.registerBuiltModule(fpdModuleId);\r | |
248 | }\r | |
249 | \r | |
878ddf1f | 250 | //\r |
a29c47e0 | 251 | // For Every TOOLCHAIN, TARGET\r |
252 | //\r | |
253 | String[] targetList = GlobalData.getToolChainInfo().getTargets();\r | |
254 | for (int i = 0; i < targetList.length; i ++){\r | |
255 | //\r | |
256 | // Prepare for target related common properties\r | |
257 | // TARGET\r | |
258 | //\r | |
259 | getProject().setProperty("TARGET", targetList[i]);\r | |
260 | String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r | |
261 | for(int j = 0; j < toolchainList.length; j ++){\r | |
c773bec0 | 262 | //\r |
263 | // check if any tool is defined for current target + toolchain + arch\r | |
264 | // don't do anything if no tools found\r | |
265 | // \r | |
266 | if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {\r | |
196ad8d7 | 267 | System.out.println("Warning: No build issued. No tools found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");\r |
c773bec0 | 268 | continue;\r |
269 | }\r | |
270 | \r | |
a29c47e0 | 271 | //\r |
272 | // Prepare for toolchain related common properties\r | |
273 | // TOOLCHAIN\r | |
274 | //\r | |
275 | getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r | |
276 | \r | |
277 | System.out.println("Build " + moduleId + " start >>>");\r | |
278 | System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);\r | |
279 | SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));\r | |
280 | \r | |
281 | //\r | |
282 | // Prepare for all other common properties\r | |
283 | // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
284 | // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r | |
285 | // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
286 | // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r | |
287 | // LIBS, OBJECTS, SDB_FILES\r | |
288 | //\r | |
289 | setModuleCommonProperties(archList[k]);\r | |
290 | \r | |
291 | //\r | |
292 | // OutputManage prepare for \r | |
293 | // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r | |
294 | //\r | |
295 | OutputManager.getInstance().update(getProject());\r | |
296 | \r | |
297 | if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r | |
298 | applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r | |
299 | }\r | |
300 | else if (type.equalsIgnoreCase("clean")) {\r | |
301 | applyClean(fpdModuleId);\r | |
302 | }\r | |
303 | else if (type.equalsIgnoreCase("cleanall")) {\r | |
304 | applyCleanall(fpdModuleId);\r | |
305 | }\r | |
306 | }\r | |
307 | }\r | |
878ddf1f | 308 | }\r |
a29c47e0 | 309 | popProperties();\r |
310 | }catch (Exception e){\r | |
a29c47e0 | 311 | throw new BuildException(e.getMessage());\r |
878ddf1f | 312 | }\r |
313 | }\r | |
314 | \r | |
315 | /**\r | |
a29c47e0 | 316 | This method is used to prepare Platform-related information. \r |
878ddf1f | 317 | \r |
a29c47e0 | 318 | <p>In Single Module Build mode, platform-related information is not ready.\r |
319 | The method read the system environment variable <code>ACTIVE_PLATFORM</code> \r | |
320 | and search in the Framework Database. Note that platform name in the Framework\r | |
321 | Database must be unique. </p>\r | |
322 | \r | |
878ddf1f | 323 | **/\r |
a29c47e0 | 324 | private void prepareSingleModuleBuild(){\r |
878ddf1f | 325 | //\r |
a29c47e0 | 326 | // Find out the package which the module belongs to\r |
327 | // TBD: Enhance it!!!!\r | |
878ddf1f | 328 | //\r |
a29c47e0 | 329 | PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r |
330 | \r | |
331 | moduleId.setPackage(packageId);\r | |
332 | \r | |
878ddf1f | 333 | //\r |
a29c47e0 | 334 | // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r |
878ddf1f | 335 | //\r |
de4bb9f6 | 336 | String filename = getProject().getProperty("PLATFORM_FILE");\r |
a29c47e0 | 337 | \r |
de4bb9f6 | 338 | if (filename == null){\r |
a29c47e0 | 339 | throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");\r |
878ddf1f | 340 | }\r |
a29c47e0 | 341 | \r |
de4bb9f6 | 342 | PlatformIdentification platformId = GlobalData.getPlatform(filename);\r |
a29c47e0 | 343 | \r |
878ddf1f | 344 | //\r |
a29c47e0 | 345 | // Read FPD file\r |
878ddf1f | 346 | //\r |
a29c47e0 | 347 | FpdParserTask fpdParser = new FpdParserTask();\r |
348 | fpdParser.setProject(getProject());\r | |
349 | fpdParser.parseFpdFile(platformId.getFpdFile());\r | |
350 | \r | |
878ddf1f | 351 | //\r |
a29c47e0 | 352 | // Prepare for Platform related common properties\r |
353 | // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r | |
878ddf1f | 354 | //\r |
de4bb9f6 | 355 | getProject().setProperty("PLATFORM", platformId.getName());\r |
a29c47e0 | 356 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r |
357 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
878ddf1f | 358 | }\r |
359 | \r | |
878ddf1f | 360 | \r |
361 | /**\r | |
a29c47e0 | 362 | Set Module-Related information to properties.\r |
878ddf1f | 363 | **/\r |
a29c47e0 | 364 | private void setModuleCommonProperties(String arch) {\r |
878ddf1f | 365 | //\r |
a29c47e0 | 366 | // Prepare for all other common properties\r |
367 | // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
878ddf1f | 368 | //\r |
a29c47e0 | 369 | PackageIdentification packageId = moduleId.getPackage();\r |
370 | getProject().setProperty("PACKAGE", packageId.getName());\r | |
371 | getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r | |
372 | getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r | |
373 | getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r | |
374 | getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r | |
375 | \r | |
376 | //\r | |
377 | // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r | |
378 | // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
379 | //\r | |
380 | getProject().setProperty("MODULE", moduleId.getName());\r | |
381 | String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r | |
382 | if (baseName == null) {\r | |
383 | getProject().setProperty("BASE_NAME", moduleId.getName());\r | |
384 | }\r | |
878ddf1f | 385 | else {\r |
a29c47e0 | 386 | getProject().setProperty("BASE_NAME", baseName);\r |
387 | }\r | |
388 | getProject().setProperty("GUID", moduleId.getGuid());\r | |
389 | getProject().setProperty("FILE_GUID", moduleId.getGuid());\r | |
390 | getProject().setProperty("VERSION", moduleId.getVersion());\r | |
391 | getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());\r | |
392 | getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r | |
393 | getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));\r | |
394 | \r | |
395 | //\r | |
396 | // SUBSYSTEM\r | |
397 | //\r | |
398 | String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},\r | |
399 | { "SEC", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
400 | { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
401 | { "PEIM", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
402 | { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r | |
403 | { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
404 | { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" }, \r | |
405 | { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
406 | { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
407 | { "TOOL", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
408 | { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r | |
409 | { "UEFI_APPLICATION", "EFI_APPLICATION" }, \r | |
410 | { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} }; \r | |
411 | \r | |
412 | String subsystem = "EFI_BOOT_SERVICE_DRIVER";\r | |
413 | for (int i = 0; i < subsystemMap.length; i++) {\r | |
414 | if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {\r | |
415 | subsystem = subsystemMap[i][1];\r | |
416 | break ;\r | |
878ddf1f | 417 | }\r |
418 | }\r | |
a29c47e0 | 419 | getProject().setProperty("SUBSYSTEM", subsystem);\r |
420 | \r | |
421 | //\r | |
422 | // ENTRYPOINT\r | |
423 | //\r | |
424 | if (arch.equalsIgnoreCase("EBC")) {\r | |
425 | getProject().setProperty("ENTRYPOINT", "EfiStart");\r | |
878ddf1f | 426 | }\r |
a29c47e0 | 427 | else {\r |
428 | getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r | |
878ddf1f | 429 | }\r |
a29c47e0 | 430 | \r |
878ddf1f | 431 | //\r |
a29c47e0 | 432 | // LIBS, OBJECTS, SDB_FILES\r |
878ddf1f | 433 | //\r |
a29c47e0 | 434 | getProject().setProperty("OBJECTS", "");\r |
435 | getProject().setProperty("SDB_FILES", "");\r | |
436 | getProject().setProperty("LIBS", "");\r | |
878ddf1f | 437 | }\r |
438 | \r | |
a29c47e0 | 439 | private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {\r |
440 | String[] cmd = GlobalData.getToolChainInfo().getCommands();\r | |
441 | for ( int m = 0; m < cmd.length; m++) {\r | |
878ddf1f | 442 | //\r |
a29c47e0 | 443 | // Set cmd, like CC, DLINK\r |
878ddf1f | 444 | //\r |
a29c47e0 | 445 | String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};\r |
446 | key[4] = "PATH";\r | |
447 | String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
448 | key[4] = "NAME";\r | |
449 | String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
450 | File cmdFile = new File(cmdPath + File.separatorChar + cmdName);\r | |
a29c47e0 | 451 | getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r |
452 | \r | |
878ddf1f | 453 | //\r |
a29c47e0 | 454 | // set CC_FLAGS\r |
878ddf1f | 455 | //\r |
a29c47e0 | 456 | key[4] = "FLAGS";\r |
457 | String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
a29c47e0 | 458 | Set<String> addset = new LinkedHashSet<String>();\r |
459 | Set<String> subset = new LinkedHashSet<String>();\r | |
460 | putFlagsToSet(addset, cmdFlags);\r | |
461 | getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));\r | |
462 | \r | |
878ddf1f | 463 | //\r |
a29c47e0 | 464 | // Set CC_EXT\r |
878ddf1f | 465 | //\r |
a29c47e0 | 466 | key[4] = "EXT";\r |
467 | String extName = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
a29c47e0 | 468 | if ( extName != null && ! extName.equalsIgnoreCase("")) {\r |
469 | getProject().setProperty(cmd[m] + "_EXT", extName);\r | |
878ddf1f | 470 | }\r |
a29c47e0 | 471 | else {\r |
472 | getProject().setProperty(cmd[m] + "_EXT", "");\r | |
878ddf1f | 473 | }\r |
a29c47e0 | 474 | \r |
878ddf1f | 475 | //\r |
a29c47e0 | 476 | // set CC_FAMILY\r |
878ddf1f | 477 | //\r |
a29c47e0 | 478 | key[4] = "FAMILY";\r |
479 | String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
a29c47e0 | 480 | if (toolChainFamily != null) {\r |
481 | getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r | |
878ddf1f | 482 | }\r |
a29c47e0 | 483 | \r |
878ddf1f | 484 | //\r |
a29c47e0 | 485 | // set CC_SPATH\r |
878ddf1f | 486 | //\r |
a29c47e0 | 487 | key[4] = "SPATH";\r |
488 | String spath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
a29c47e0 | 489 | if (spath != null) {\r |
490 | getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r | |
878ddf1f | 491 | }\r |
a29c47e0 | 492 | else {\r |
493 | getProject().setProperty(cmd[m] + "_SPATH", "");\r | |
878ddf1f | 494 | }\r |
a29c47e0 | 495 | \r |
878ddf1f | 496 | //\r |
a29c47e0 | 497 | // set CC_DPATH\r |
878ddf1f | 498 | //\r |
a29c47e0 | 499 | key[4] = "DPATH";\r |
500 | String dpath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
a29c47e0 | 501 | if (dpath != null) {\r |
502 | getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r | |
878ddf1f | 503 | }\r |
a29c47e0 | 504 | else {\r |
505 | getProject().setProperty(cmd[m] + "_DPATH", "");\r | |
878ddf1f | 506 | }\r |
507 | }\r | |
a29c47e0 | 508 | }\r |
509 | \r | |
510 | public void setMsaFile(File msaFile) {\r | |
511 | this.msaFile = msaFile;\r | |
878ddf1f | 512 | }\r |
513 | \r | |
514 | /**\r | |
a29c47e0 | 515 | Method is for ANT to initialize MSA file. \r |
516 | \r | |
517 | @param msaFilename MSA file name\r | |
878ddf1f | 518 | **/\r |
a29c47e0 | 519 | public void setMsaFile(String msaFilename) {\r |
520 | String moduleDir = getProject().getProperty("MODULE_DIR");\r | |
878ddf1f | 521 | \r |
a29c47e0 | 522 | //\r |
523 | // If is Single Module Build, then use the Base Dir defined in build.xml\r | |
524 | //\r | |
525 | if (moduleDir == null) {\r | |
526 | moduleDir = getProject().getBaseDir().getPath();\r | |
878ddf1f | 527 | }\r |
a29c47e0 | 528 | msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r |
529 | }\r | |
530 | \r | |
531 | public void addConfiguredModuleItem(ModuleItem moduleItem) {\r | |
532 | PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());\r | |
533 | ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());\r | |
534 | moduleId.setPackage(packageId);\r | |
535 | this.moduleId = moduleId;\r | |
536 | }\r | |
537 | \r | |
538 | /**\r | |
539 | Add a property. \r | |
540 | \r | |
541 | @param p property\r | |
542 | **/\r | |
543 | public void addProperty(Property p) {\r | |
544 | properties.addElement(p);\r | |
545 | }\r | |
546 | \r | |
547 | public void setType(String type) {\r | |
548 | this.type = type;\r | |
549 | }\r | |
550 | \r | |
551 | private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException{\r | |
552 | //\r | |
553 | // AutoGen\r | |
554 | //\r | |
136adffc | 555 | \r |
73b4e31a | 556 | AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());\r |
136adffc | 557 | autogen.genAutogen();\r |
a29c47e0 | 558 | \r |
878ddf1f | 559 | \r |
a29c47e0 | 560 | //\r |
561 | // Get compiler flags\r | |
562 | //\r | |
563 | getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r | |
564 | \r | |
565 | //\r | |
566 | // Prepare LIBS\r | |
567 | //\r | |
568 | ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r | |
569 | String propertyLibs = "";\r | |
570 | for (int i = 0; i < libinstances.length; i++) {\r | |
571 | propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";\r | |
878ddf1f | 572 | }\r |
a29c47e0 | 573 | getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r |
574 | \r | |
575 | //\r | |
576 | // if it is CUSTOM_BUILD\r | |
577 | // then call the exist BaseName_build.xml directly.\r | |
578 | //\r | |
579 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
580 | GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r | |
581 | Ant ant = new Ant();\r | |
582 | ant.setProject(getProject());\r | |
583 | ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
584 | ant.setInheritAll(true);\r | |
585 | ant.init();\r | |
586 | ant.execute();\r | |
587 | return ;\r | |
878ddf1f | 588 | }\r |
a29c47e0 | 589 | \r |
878ddf1f | 590 | //\r |
a29c47e0 | 591 | // Generate ${BASE_NAME}_build.xml\r |
592 | // TBD\r | |
878ddf1f | 593 | //\r |
a29c47e0 | 594 | String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();\r |
595 | ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);\r | |
596 | String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
597 | fileGenerator.genBuildFile(buildFilename);\r | |
598 | \r | |
599 | //\r | |
600 | // Ant call ${BASE_NAME}_build.xml\r | |
601 | //\r | |
602 | Ant ant = new Ant();\r | |
603 | ant.setProject(getProject());\r | |
604 | ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
605 | ant.setInheritAll(true);\r | |
606 | ant.init();\r | |
607 | ant.execute();\r | |
608 | }\r | |
609 | \r | |
610 | private void applyClean(FpdModuleIdentification fpdModuleId){\r | |
611 | //\r | |
612 | // if it is CUSTOM_BUILD\r | |
613 | // then call the exist BaseName_build.xml directly.\r | |
614 | //\r | |
615 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
616 | GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r | |
617 | Ant ant = new Ant();\r | |
618 | ant.setProject(getProject());\r | |
619 | ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
620 | ant.setTarget("clean");\r | |
621 | ant.setInheritAll(true);\r | |
622 | ant.init();\r | |
623 | ant.execute();\r | |
624 | return ;\r | |
878ddf1f | 625 | }\r |
a29c47e0 | 626 | \r |
627 | Ant ant = new Ant();\r | |
628 | ant.setProject(getProject());\r | |
629 | ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
630 | ant.setTarget("clean");\r | |
631 | ant.setInheritAll(true);\r | |
632 | ant.init();\r | |
633 | ant.execute();\r | |
634 | \r | |
635 | //\r | |
636 | // Delete current module's DEST_DIR_OUTPUT\r | |
637 | // TBD\r | |
638 | }\r | |
639 | \r | |
640 | private void applyCleanall(FpdModuleIdentification fpdModuleId){\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 | GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r | |
647 | Ant ant = new Ant();\r | |
648 | ant.setProject(getProject());\r | |
649 | ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
650 | ant.setTarget("cleanall");\r | |
651 | ant.setInheritAll(true);\r | |
652 | ant.init();\r | |
653 | ant.execute();\r | |
654 | return ;\r | |
878ddf1f | 655 | }\r |
a29c47e0 | 656 | \r |
657 | Ant ant = new Ant();\r | |
658 | ant.setProject(getProject());\r | |
659 | ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
660 | ant.setTarget("cleanall");\r | |
661 | ant.setInheritAll(true);\r | |
662 | ant.init();\r | |
663 | ant.execute();\r | |
664 | \r | |
665 | //\r | |
666 | // Delete current module's DEST_DIR_OUTPUT\r | |
667 | // TBD\r | |
878ddf1f | 668 | }\r |
669 | \r | |
a29c47e0 | 670 | \r |
671 | \r | |
672 | \r | |
878ddf1f | 673 | /**\r |
674 | Separate the string and instore in set.\r | |
675 | \r | |
676 | <p> String is separated by Java Regulation Expression \r | |
677 | "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>\r | |
678 | \r | |
679 | <p>For example: </p>\r | |
680 | \r | |
681 | <pre>\r | |
682 | "/nologo", "/W3", "/WX"\r | |
683 | "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""\r | |
684 | </pre>\r | |
685 | \r | |
686 | @param set store the separated string\r | |
687 | @param str string to separate\r | |
688 | **/\r | |
689 | private void putFlagsToSet(Set<String> set, String str) {\r | |
a29c47e0 | 690 | if (str == null || str.length() == 0) {\r |
691 | return;\r | |
692 | }\r | |
693 | \r | |
878ddf1f | 694 | Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");\r |
695 | Matcher matcher = myPattern.matcher(str + " ");\r | |
696 | while (matcher.find()) {\r | |
697 | String item = str.substring(matcher.start(1), matcher.end(1));\r | |
a29c47e0 | 698 | set.add(item);\r |
878ddf1f | 699 | }\r |
700 | }\r | |
701 | \r | |
702 | /**\r | |
703 | Generate the final flags string will be used by compile command. \r | |
704 | \r | |
705 | @param add the add flags set\r | |
706 | @param sub the sub flags set\r | |
707 | @return final flags after add set substract sub set\r | |
708 | **/\r | |
709 | private String getFlags(Set<String> add, Set<String> sub) {\r | |
710 | String result = "";\r | |
711 | add.removeAll(sub);\r | |
712 | Iterator iter = add.iterator();\r | |
713 | while (iter.hasNext()) {\r | |
a29c47e0 | 714 | String str = (String) iter.next();\r |
878ddf1f | 715 | result += str.substring(1, str.length() - 1) + " ";\r |
716 | }\r | |
717 | return result;\r | |
718 | }\r | |
719 | \r | |
720 | /**\r | |
721 | Generate the flags string with original format. The format is defined by \r | |
722 | Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>\r | |
723 | \r | |
724 | <p>For example: </p>\r | |
725 | \r | |
726 | <pre>\r | |
727 | "/nologo", "/W3", "/WX"\r | |
728 | "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""\r | |
729 | </pre>\r | |
730 | \r | |
731 | @param add the add flags set\r | |
732 | @param sub the sub flags set\r | |
733 | @return flags with original format\r | |
734 | **/\r | |
735 | private String getRawFlags(Set<String> add, Set<String> sub) {\r | |
a29c47e0 | 736 | String result = null;\r |
878ddf1f | 737 | add.removeAll(sub);\r |
738 | Iterator iter = add.iterator();\r | |
739 | while (iter.hasNext()) {\r | |
a29c47e0 | 740 | String str = (String) iter.next();\r |
878ddf1f | 741 | result += "\"" + str.substring(1, str.length() - 1) + "\", ";\r |
742 | }\r | |
743 | return result;\r | |
744 | }\r | |
745 | \r | |
a29c47e0 | 746 | private String parseOptionString(String optionString, Set<String> addSet, Set<String> subSet) {\r |
747 | boolean overrideOption = false;\r | |
748 | Pattern pattern = Pattern.compile("ADD\\.\\[(.+)\\]");\r | |
749 | Matcher matcher = pattern.matcher(optionString);\r | |
750 | \r | |
751 | while (matcher.find()) {\r | |
752 | overrideOption = true;\r | |
753 | String addOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r | |
754 | putFlagsToSet(addSet, addOption);\r | |
755 | \r | |
756 | }\r | |
878ddf1f | 757 | \r |
a29c47e0 | 758 | pattern = Pattern.compile("SUB\\.\\[(.+)\\]");\r |
759 | matcher = pattern.matcher(optionString);\r | |
760 | \r | |
761 | while (matcher.find()) {\r | |
762 | overrideOption = true;\r | |
763 | String subOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r | |
764 | putFlagsToSet(subSet, subOption);\r | |
765 | }\r | |
766 | \r | |
767 | if (overrideOption == true) {\r | |
768 | return null;\r | |
769 | }\r | |
770 | \r | |
771 | return optionString;\r | |
772 | }\r | |
773 | \r | |
774 | private void pushProperties() {\r | |
775 | backupPropertiesStack.push(getProject().getProperties());\r | |
776 | }\r | |
777 | \r | |
778 | private void popProperties() {\r | |
779 | Hashtable backupProperties = backupPropertiesStack.pop();\r | |
780 | Set keys = backupProperties.keySet();\r | |
781 | Iterator iter = keys.iterator();\r | |
782 | while (iter.hasNext()) {\r | |
783 | String item = (String)iter.next();\r | |
784 | getProject().setProperty(item, (String)backupProperties.get(item));\r | |
785 | }\r | |
786 | }\r | |
de4bb9f6 | 787 | \r |
788 | public void setSingleModuleBuild(boolean isSingleModuleBuild) {\r | |
789 | this.isSingleModuleBuild = isSingleModuleBuild;\r | |
790 | }\r | |
878ddf1f | 791 | }\r |