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