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
;
40 public class FpdParserForThread
extends FpdParserTask
{
42 public static Map
<FpdModuleIdentification
, GenBuildThread
> allThreads
= new LinkedHashMap
<FpdModuleIdentification
, GenBuildThread
>();
44 List
<String
> queueList
= new ArrayList
<String
>();
46 public static Object deamonSemaphore
= new Object();
48 static Object countSemaphore
= new Object();
50 public static int STATUS_DEPENDENCY_NOT_READY
= 1;
52 public static int STATUS_DEPENDENCY_READY
= 2;
54 public static int STATUS_START_RUN
= 3;
56 public static int STATUS_END_RUN
= 4;
58 private int currentQueueCode
= 0;
60 public static int currentRunNumber
= 0;
63 Public construct method. It is necessary for ANT task.
65 public FpdParserForThread() {
72 public void execute() throws BuildException
{
81 isUnified
= OutputManager
.getInstance().prepareBuildDir(getProject());
84 // For every Target and ToolChain
86 String
[] targetList
= GlobalData
.getToolChainInfo().getTargets();
87 for (int i
= 0; i
< targetList
.length
; i
++) {
88 String
[] toolchainList
= GlobalData
.getToolChainInfo().getTagnames();
89 for(int j
= 0; j
< toolchainList
.length
; j
++) {
93 String ffsCommonDir
= getProject().getProperty("BUILD_DIR") + File
.separatorChar
94 + targetList
[i
] + File
.separatorChar
96 File fvDir
= new File(ffsCommonDir
+ File
.separatorChar
+ "FV");
98 getProject().setProperty("FV_DIR", fvDir
.getPath().replaceAll("(\\\\)", "/"));
103 genFvInfFiles(ffsCommonDir
);
110 PlatformBuildFileGenerator fileGenerator
= new PlatformBuildFileGenerator(getProject(), outfiles
, fvs
, isUnified
, saq
);
111 fileGenerator
.genBuildFile();
116 queueList
.add("libqueue");
118 String
[] validFv
= saq
.getFpdValidImageNames();
120 for (int i
= 0; i
< validFv
.length
; i
++) {
121 queueList
.add(validFv
[i
]);
124 Iterator
<String
> fvsNameIter
= fvs
.keySet().iterator();
126 while (fvsNameIter
.hasNext()) {
127 String fvName
= fvsNameIter
.next();
128 if (!isContain(validFv
, fvName
)) {
129 queueList
.add(fvName
);
134 // Ant call ${PLATFORM}_build.xml
137 ant
.setProject(getProject());
138 ant
.setAntfile(platformId
.getFpdFile().getParent() + File
.separatorChar
+ platformId
.getName() + "_build.xml");
139 ant
.setTarget("prebuild");
140 ant
.setInheritAll(true);
144 System
.out
.println("Task number is " + allThreads
.size());
147 // Waiting for all thread over, or time out
149 synchronized (deamonSemaphore
) {
156 // If all modules are already built
158 if (currentQueueCode
>= queueList
.size()) {
162 Set
<FpdModuleIdentification
> currentQueueModules
= fvs
.get(queueList
.get(currentQueueCode
));
164 if (currentQueueModules
== null) {
168 Iterator
<FpdModuleIdentification
> currentIter
= currentQueueModules
.iterator();
170 GenBuildThread a
= null;
172 boolean existNoneReady
= false;
174 while (currentIter
.hasNext()) {
175 GenBuildThread item
= allThreads
.get(currentIter
.next());
176 if (item
.getStatus() == STATUS_DEPENDENCY_NOT_READY
) {
177 existNoneReady
= true;
178 } else if (item
.getStatus() == STATUS_DEPENDENCY_READY
) {
182 if (currentRunNumber
== FrameworkBuildTask
.MAX_CONCURRENT_THREAD_NUMBER
) {
190 // Exist ready thread
192 System
.out
.println("## Exist ready thread");
194 } else if (existNoneReady
&& currentRunNumber
== 0) {
196 // No active thread, but still have dependency not read thread
198 throw new BuildException("Found can't resolve dependencies. ");
199 } else if (!existNoneReady
&& currentRunNumber
== 0) {
201 // Current queue build finish, move to next
203 System
.out
.println("## Current queue build finish, move to next");
208 // active thread exist, but no ready thread
210 System
.out
.println("## active thread exist, but no ready thread" + currentRunNumber
);
214 deamonSemaphore
.wait();
215 } catch (InterruptedException e
) {
222 // call fvs, postbuild
225 ant
.setProject(getProject());
226 ant
.setAntfile(platformId
.getFpdFile().getParent() + File
.separatorChar
+ platformId
.getName() + "_build.xml");
227 ant
.setTarget("fvs");
228 ant
.setInheritAll(true);
233 ant
.setProject(getProject());
234 ant
.setAntfile(platformId
.getFpdFile().getParent() + File
.separatorChar
+ platformId
.getName() + "_build.xml");
235 ant
.setTarget("postbuild");
236 ant
.setInheritAll(true);
244 Parse all modules listed in FPD file.
246 void parseModuleSAFiles() throws EdkException
{
248 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> moduleSAs
= saq
.getFpdModules();
251 // For every Module lists in FPD file.
253 Set
<FpdModuleIdentification
> keys
= moduleSAs
.keySet();
254 Iterator
<FpdModuleIdentification
> iter
= keys
.iterator();
255 while (iter
.hasNext()) {
256 FpdModuleIdentification fpdModuleId
= iter
.next();
259 // Generate GenBuildThread
261 GenBuildThread genBuildThread
= new GenBuildThread();
262 genBuildThread
.setArch(fpdModuleId
.getArch());
263 genBuildThread
.setParentModuleId(null);
264 genBuildThread
.setModuleId(fpdModuleId
.getModule());
265 genBuildThread
.setProject(getProject());
267 Set
<FpdModuleIdentification
> dependencies
= new LinkedHashSet
<FpdModuleIdentification
>();
269 GlobalData
.registerFpdModuleSA(fpdModuleId
, moduleSAs
.get(fpdModuleId
));
272 // Add all dependent Library Instance
274 saq
.push(GlobalData
.getDoc(fpdModuleId
));
276 ModuleIdentification
[] libinstances
= saq
.getLibraryInstance(fpdModuleId
.getArch());
279 for (int i
= 0; i
< libinstances
.length
; i
++) {
280 FpdModuleIdentification libFpdModuleId
= new FpdModuleIdentification(libinstances
[i
], fpdModuleId
.getArch());
282 // Add to dependencies
284 dependencies
.add(libFpdModuleId
);
287 // Create thread for library instances
289 GenBuildThread liBuildThread
= new GenBuildThread();
290 liBuildThread
.setArch(fpdModuleId
.getArch());
291 liBuildThread
.setParentModuleId(fpdModuleId
.getModule());
292 liBuildThread
.setModuleId(libinstances
[i
]);
293 liBuildThread
.setProject(getProject());
294 liBuildThread
.setStatus(STATUS_DEPENDENCY_READY
);
295 liBuildThread
.setHighPriority(true);
296 allThreads
.put(libFpdModuleId
, liBuildThread
);
298 updateFvs("libqueue", libFpdModuleId
);
301 genBuildThread
.setDependencies(dependencies
);
302 // if (dependencies.size() == 0) {
303 genBuildThread
.setStatus(STATUS_DEPENDENCY_READY
);
306 allThreads
.put(fpdModuleId
, genBuildThread
);
309 // Put fpdModuleId to the corresponding FV
311 saq
.push(GlobalData
.getDoc(fpdModuleId
));
312 String fvBinding
= saq
.getModuleFvBindingKeyword();
314 fpdModuleId
.setFvBinding(fvBinding
);
315 updateFvs(fvBinding
, fpdModuleId
);
318 // Prepare for out put file name
320 ModuleIdentification moduleId
= fpdModuleId
.getModule();
322 String baseName
= saq
.getModuleOutputFileBasename();
324 if (baseName
== null) {
325 baseName
= moduleId
.getName();
327 outfiles
.put(fpdModuleId
, fpdModuleId
.getArch() + File
.separatorChar
328 + moduleId
.getGuid() + "-" + baseName
329 + getSuffix(moduleId
.getModuleType()));
332 // parse module build options, if any
334 GlobalData
.addModuleToolChainOption(fpdModuleId
, parseModuleBuildOptions(false));
335 GlobalData
.addModuleToolChainFamilyOption(fpdModuleId
, parseModuleBuildOptions(true));
340 private boolean isContain(String
[] list
, String item
) {
341 for (int i
= 0; i
< list
.length
; i
++) {
342 if (list
[i
].equalsIgnoreCase(item
)) {
349 public synchronized static void addCount() {
350 synchronized (countSemaphore
) {
355 public synchronized static void subCount() {
356 synchronized (countSemaphore
) {