2 This file is ANT task FpdParserTask.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.build
.fpd
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Iterator
;
18 import java
.util
.LinkedHashMap
;
19 import java
.util
.LinkedHashSet
;
20 import java
.util
.List
;
24 import org
.apache
.tools
.ant
.BuildException
;
25 import org
.apache
.tools
.ant
.taskdefs
.Ant
;
26 import org
.apache
.xmlbeans
.XmlObject
;
28 import org
.tianocore
.build
.global
.GlobalData
;
29 import org
.tianocore
.build
.global
.OutputManager
;
30 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
31 import org
.tianocore
.build
.id
.ModuleIdentification
;
32 import org
.tianocore
.build
.FrameworkBuildTask
;
33 import org
.tianocore
.build
.GenBuildThread
;
34 import org
.tianocore
.common
.exception
.EdkException
;
35 import org
.tianocore
.common
.logger
.EdkLog
;
41 public class FpdParserForThread
extends FpdParserTask
{
43 public static Map
<FpdModuleIdentification
, GenBuildThread
> allThreads
= new LinkedHashMap
<FpdModuleIdentification
, GenBuildThread
>();
45 List
<String
> queueList
= new ArrayList
<String
>();
47 public static Object deamonSemaphore
= new Object();
49 static Object countSemaphore
= new Object();
51 public static int STATUS_DEPENDENCY_NOT_READY
= 1;
53 public static int STATUS_DEPENDENCY_READY
= 2;
55 public static int STATUS_START_RUN
= 3;
57 public static int STATUS_END_RUN
= 4;
59 private int currentQueueCode
= 0;
61 public static int currentRunNumber
= 0;
64 Public construct method. It is necessary for ANT task.
66 public FpdParserForThread() {
73 public void execute() throws BuildException
{
82 isUnified
= OutputManager
.getInstance().prepareBuildDir(getProject());
83 String buildDir
= getProject().getProperty("BUILD_DIR");
86 // For every Target and ToolChain
88 String
[] targetList
= GlobalData
.getToolChainInfo().getTargets();
89 for (int i
= 0; i
< targetList
.length
; i
++) {
90 String
[] toolchainList
= GlobalData
.getToolChainInfo().getTagnames();
91 for(int j
= 0; j
< toolchainList
.length
; j
++) {
95 String ffsCommonDir
= buildDir
+ File
.separatorChar
96 + targetList
[i
] + File
.separatorChar
98 File fvDir
= new File(ffsCommonDir
+ File
.separatorChar
+ "FV");
100 getProject().setProperty("FV_DIR", fvDir
.getPath().replaceAll("(\\\\)", "/"));
105 genFvInfFiles(ffsCommonDir
);
112 String platformBuildFile
= buildDir
+ File
.separatorChar
+ platformId
.getName() + "_build.xml";
113 PlatformBuildFileGenerator fileGenerator
= new PlatformBuildFileGenerator(getProject(), outfiles
, fvs
, isUnified
, saq
, platformBuildFile
);
114 fileGenerator
.genBuildFile();
119 queueList
.add("libqueue");
121 String
[] validFv
= saq
.getFpdValidImageNames();
123 for (int i
= 0; i
< validFv
.length
; i
++) {
124 queueList
.add(validFv
[i
]);
127 Iterator
<String
> fvsNameIter
= fvs
.keySet().iterator();
129 while (fvsNameIter
.hasNext()) {
130 String fvName
= fvsNameIter
.next();
131 if (!isContain(validFv
, fvName
)) {
132 queueList
.add(fvName
);
137 // Ant call ${PLATFORM}_build.xml
140 ant
.setProject(getProject());
141 ant
.setAntfile(platformBuildFile
);
142 ant
.setTarget("prebuild");
143 ant
.setInheritAll(true);
147 EdkLog
.log(this, "Task number is " + allThreads
.size());
150 // Waiting for all thread over, or time out
152 synchronized (deamonSemaphore
) {
159 // If all modules are already built
161 if (currentQueueCode
>= queueList
.size()) {
165 Set
<FpdModuleIdentification
> currentQueueModules
= fvs
.get(queueList
.get(currentQueueCode
));
167 if (currentQueueModules
== null) {
171 Iterator
<FpdModuleIdentification
> currentIter
= currentQueueModules
.iterator();
173 GenBuildThread a
= null;
175 boolean existNoneReady
= false;
177 while (currentIter
.hasNext()) {
178 GenBuildThread item
= allThreads
.get(currentIter
.next());
179 if (item
.getStatus() == STATUS_DEPENDENCY_NOT_READY
) {
180 existNoneReady
= true;
181 } else if (item
.getStatus() == STATUS_DEPENDENCY_READY
) {
185 if (currentRunNumber
== FrameworkBuildTask
.MAX_CONCURRENT_THREAD_NUMBER
) {
193 // Exist ready thread
195 EdkLog
.log(this, "## Exist ready thread");
197 } else if (existNoneReady
&& currentRunNumber
== 0) {
199 // No active thread, but still have dependency not read thread
201 throw new BuildException("Found can't resolve dependencies. ");
202 } else if (!existNoneReady
&& currentRunNumber
== 0) {
204 // Current queue build finish, move to next
206 EdkLog
.log(this, "## Current queue build finish, move to next");
211 // active thread exist, but no ready thread
213 EdkLog
.log(this, "## active thread exist, but no ready thread" + currentRunNumber
);
217 deamonSemaphore
.wait();
218 } catch (InterruptedException e
) {
225 // call fvs, postbuild
228 ant
.setProject(getProject());
229 ant
.setAntfile(platformBuildFile
);
230 ant
.setTarget("fvs");
231 ant
.setInheritAll(true);
236 ant
.setProject(getProject());
237 ant
.setAntfile(platformBuildFile
);
238 ant
.setTarget("postbuild");
239 ant
.setInheritAll(true);
247 Parse all modules listed in FPD file.
249 void parseModuleSAFiles() throws EdkException
{
251 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> moduleSAs
= saq
.getFpdModules();
254 // For every Module lists in FPD file.
256 Set
<FpdModuleIdentification
> keys
= moduleSAs
.keySet();
257 Iterator
<FpdModuleIdentification
> iter
= keys
.iterator();
258 while (iter
.hasNext()) {
259 FpdModuleIdentification fpdModuleId
= iter
.next();
262 // Generate GenBuildThread
264 GenBuildThread genBuildThread
= new GenBuildThread();
265 genBuildThread
.setArch(fpdModuleId
.getArch());
266 genBuildThread
.setParentModuleId(null);
267 genBuildThread
.setModuleId(fpdModuleId
.getModule());
268 genBuildThread
.setProject(getProject());
270 Set
<FpdModuleIdentification
> dependencies
= new LinkedHashSet
<FpdModuleIdentification
>();
272 GlobalData
.registerFpdModuleSA(fpdModuleId
, moduleSAs
.get(fpdModuleId
));
275 // Add all dependent Library Instance
277 saq
.push(GlobalData
.getDoc(fpdModuleId
));
279 ModuleIdentification
[] libinstances
= saq
.getLibraryInstance(fpdModuleId
.getArch());
282 for (int i
= 0; i
< libinstances
.length
; i
++) {
283 FpdModuleIdentification libFpdModuleId
= new FpdModuleIdentification(libinstances
[i
], fpdModuleId
.getArch());
285 // Add to dependencies
287 dependencies
.add(libFpdModuleId
);
290 // Create thread for library instances
292 GenBuildThread liBuildThread
= new GenBuildThread();
293 liBuildThread
.setArch(fpdModuleId
.getArch());
294 liBuildThread
.setParentModuleId(fpdModuleId
.getModule());
295 liBuildThread
.setModuleId(libinstances
[i
]);
296 liBuildThread
.setProject(getProject());
297 liBuildThread
.setStatus(STATUS_DEPENDENCY_READY
);
298 liBuildThread
.setHighPriority(true);
299 allThreads
.put(libFpdModuleId
, liBuildThread
);
301 updateFvs("libqueue", libFpdModuleId
);
304 genBuildThread
.setDependencies(dependencies
);
305 // if (dependencies.size() == 0) {
306 genBuildThread
.setStatus(STATUS_DEPENDENCY_READY
);
309 allThreads
.put(fpdModuleId
, genBuildThread
);
312 // Put fpdModuleId to the corresponding FV
314 saq
.push(GlobalData
.getDoc(fpdModuleId
));
315 String fvBinding
= saq
.getModuleFvBindingKeyword();
317 fpdModuleId
.setFvBinding(fvBinding
);
318 updateFvs(fvBinding
, fpdModuleId
);
321 // Prepare for out put file name
323 ModuleIdentification moduleId
= fpdModuleId
.getModule();
325 String baseName
= saq
.getModuleOutputFileBasename();
327 if (baseName
== null) {
328 baseName
= moduleId
.getName();
330 outfiles
.put(fpdModuleId
, fpdModuleId
.getArch() + File
.separatorChar
331 + moduleId
.getGuid() + "-" + baseName
332 + getSuffix(moduleId
.getModuleType()));
335 // parse module build options, if any
337 GlobalData
.addModuleToolChainOption(fpdModuleId
, parseModuleBuildOptions(false));
338 GlobalData
.addModuleToolChainFamilyOption(fpdModuleId
, parseModuleBuildOptions(true));
343 private boolean isContain(String
[] list
, String item
) {
344 for (int i
= 0; i
< list
.length
; i
++) {
345 if (list
[i
].equalsIgnoreCase(item
)) {
352 public synchronized static void addCount() {
353 synchronized (countSemaphore
) {
358 public synchronized static void subCount() {
359 synchronized (countSemaphore
) {