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