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