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