2 This file is for single module thread definition.
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
;
15 import java
.util
.Hashtable
;
16 import java
.util
.Iterator
;
17 import java
.util
.LinkedHashSet
;
19 import java
.util
.Vector
;
21 import org
.apache
.tools
.ant
.BuildException
;
22 import org
.apache
.tools
.ant
.BuildListener
;
23 import org
.apache
.tools
.ant
.Project
;
24 import org
.apache
.tools
.ant
.taskdefs
.Property
;
25 import org
.tianocore
.build
.GenBuildTask
;
26 import org
.tianocore
.build
.fpd
.FpdParserForThread
;
27 import org
.tianocore
.build
.global
.GenBuildLogger
;
28 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
29 import org
.tianocore
.build
.id
.ModuleIdentification
;
30 import org
.tianocore
.common
.logger
.EdkLog
;
33 Add more comment here.
37 public class GenBuildThread
implements Runnable
{
39 private ModuleIdentification parentModuleId
= null;
41 private ModuleIdentification moduleId
= null;
43 private Set
<FpdModuleIdentification
> dependencies
= new LinkedHashSet
<FpdModuleIdentification
>();
45 private int status
= FpdParserForThread
.STATUS_DEPENDENCY_NOT_READY
;
47 private Project project
= null;
49 public Object semaphore
= new Object();
51 private String arch
= null;
53 private boolean highPriority
= false;
55 private Thread thread
;
57 public GenBuildThread(ModuleIdentification moduleId
, String arch
) {
58 this.moduleId
= moduleId
;
60 thread
= new Thread(FpdParserForThread
.tg
, this, moduleId
+ ":" + arch
);
63 public boolean start() {
65 thread
.setPriority(Thread
.MAX_PRIORITY
);
68 status
= FpdParserForThread
.STATUS_START_RUN
;
77 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
81 // Prepare pass down properties
82 // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE
84 Vector
<Property
> properties
= new Vector
<Property
>();
85 Property property
= new Property();
86 property
.setName("ARCH");
87 property
.setValue(arch
);
88 properties
.add(property
);
90 property
= new Property();
91 property
.setName("MODULE_GUID");
92 property
.setValue(moduleId
.getGuid());
93 properties
.add(property
);
95 property
= new Property();
96 property
.setName("MODULE_VERSION");
97 if (moduleId
.getVersion() == null) {
98 property
.setValue("");
100 property
.setValue(moduleId
.getVersion());
102 properties
.add(property
);
104 property
= new Property();
105 property
.setName("PACKAGE_GUID");
106 property
.setValue(moduleId
.getPackage().getGuid());
107 properties
.add(property
);
109 property
= new Property();
110 property
.setName("PACKAGE_VERSION");
111 if (moduleId
.getPackage().getVersion() == null) {
112 property
.setValue("");
114 property
.setValue(moduleId
.getPackage().getVersion());
116 properties
.add(property
);
121 GenBuildTask genBuildTask
= new GenBuildTask();
123 Project newProject
= new Project();
125 Hashtable passdownProperties
= project
.getProperties();
126 Iterator iter
= passdownProperties
.keySet().iterator();
127 while (iter
.hasNext()) {
128 String item
= (String
) iter
.next();
129 newProject
.setProperty(item
, (String
) passdownProperties
.get(item
));
132 newProject
.setInputHandler(project
.getInputHandler());
134 Iterator listenerIter
= project
.getBuildListeners().iterator();
135 GenBuildLogger newLogger
= null;
136 while (listenerIter
.hasNext()) {
137 BuildListener item
= (BuildListener
)listenerIter
.next();
138 if (item
instanceof GenBuildLogger
) {
139 newLogger
= (GenBuildLogger
)((GenBuildLogger
)item
).clone();
140 newLogger
.setId(fpdModuleId
);
141 newProject
.addBuildListener(newLogger
);
143 newProject
.addBuildListener(item
);
147 project
.initSubProject(newProject
);
149 genBuildTask
.setProject(newProject
);
151 genBuildTask
.setExternalProperties(properties
);
153 genBuildTask
.parentId
= parentModuleId
;
155 genBuildTask
.perform();
156 } catch (BuildException be
) {
158 EdkLog
.log("GenBuild", EdkLog
.EDK_ALWAYS
, fpdModuleId
+ " build error. \n" + be
.getMessage());
160 if (FpdParserForThread
.errorModule
== null) {
161 FpdParserForThread
.errorModule
= fpdModuleId
;
164 synchronized (FpdParserForThread
.deamonSemaphore
) {
165 FpdParserForThread
.subCount();
166 FpdParserForThread
.deamonSemaphore
.notifyAll();
172 status
= FpdParserForThread
.STATUS_END_RUN
;
174 EdkLog
.log("GenBuild", EdkLog
.EDK_ALWAYS
, fpdModuleId
+ " build finished. ");
179 synchronized (FpdParserForThread
.deamonSemaphore
) {
180 FpdParserForThread
.subCount();
181 FpdParserForThread
.deamonSemaphore
.notifyAll();
185 public void setArch(String arch
) {
189 public void setDependencies(Set
<FpdModuleIdentification
> dependencies
) {
190 this.dependencies
= dependencies
;
193 public void setModuleId(ModuleIdentification moduleId
) {
194 this.moduleId
= moduleId
;
197 public void setParentModuleId(ModuleIdentification parentModuleId
) {
198 this.parentModuleId
= parentModuleId
;
201 public void setProject(Project project
) {
202 this.project
= project
;
205 public void setHighPriority(boolean highPriority
) {
206 this.highPriority
= highPriority
;
210 public Set
<FpdModuleIdentification
> getDependencies() {
214 public ModuleIdentification
getModuleId() {
218 public int getStatus() {
220 // Add code here to judge dependency
222 if (status
== FpdParserForThread
.STATUS_DEPENDENCY_NOT_READY
) {
223 Iterator
<FpdModuleIdentification
> iter
= dependencies
.iterator();
225 while (iter
.hasNext()) {
226 FpdModuleIdentification item
= iter
.next();
227 if (FpdParserForThread
.allThreads
.get(item
).getStatus() == 1) {
233 status
= FpdParserForThread
.STATUS_DEPENDENCY_READY
;
239 public void setStatus(int status
) {
240 this.status
= status
;