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