]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java
Adding new Logger instead of Ant's.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / GenBuildThread.java
1 /** @file
2 This file is for single module thread definition.
3
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
9
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.
12 **/
13 package org.tianocore.build;
14
15 import java.util.Hashtable;
16 import java.util.Iterator;
17 import java.util.LinkedHashSet;
18 import java.util.Set;
19 import java.util.Vector;
20
21 import org.apache.tools.ant.BuildListener;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.taskdefs.Property;
24 import org.tianocore.build.GenBuildTask;
25 import org.tianocore.build.fpd.FpdParserForThread;
26 import org.tianocore.build.id.FpdModuleIdentification;
27 import org.tianocore.build.id.ModuleIdentification;
28 import org.tianocore.common.logger.EdkLog;
29
30 /**
31 Add more comment here.
32
33 @since GenBuild 1.0
34 **/
35 public class GenBuildThread implements Runnable {
36
37 private ModuleIdentification parentModuleId = null;
38
39 private ModuleIdentification moduleId = null;
40
41 private Set<FpdModuleIdentification> dependencies = new LinkedHashSet<FpdModuleIdentification>();
42
43 private int status = FpdParserForThread.STATUS_DEPENDENCY_NOT_READY;
44
45 private Project project = null;
46
47 public Object semaphore = new Object();
48
49 private String arch = null;
50
51 private boolean highPriority = false;
52
53 private Thread thread;
54
55 public GenBuildThread() {
56 thread = new Thread(this);
57 }
58
59 public boolean start() {
60 if (highPriority) {
61 thread.setPriority(Thread.MAX_PRIORITY);
62 }
63
64 status = FpdParserForThread.STATUS_START_RUN;
65 thread.start();
66 return true;
67 }
68
69 public void run() {
70
71 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
72
73 //
74 // Prepare pass down properties
75 // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE
76 //
77 Vector<Property> properties = new Vector<Property>();
78 Property property = new Property();
79 property.setName("ARCH");
80 property.setValue(arch);
81 properties.add(property);
82
83 property = new Property();
84 property.setName("MODULE_GUID");
85 property.setValue(moduleId.getGuid());
86 properties.add(property);
87
88 property = new Property();
89 property.setName("MODULE_VERSION");
90 if (moduleId.getVersion() == null) {
91 property.setValue("");
92 } else {
93 property.setValue(moduleId.getVersion());
94 }
95 properties.add(property);
96
97 property = new Property();
98 property.setName("PACKAGE_GUID");
99 property.setValue(moduleId.getPackage().getGuid());
100 properties.add(property);
101
102 property = new Property();
103 property.setName("PACKAGE_VERSION");
104 if (moduleId.getPackage().getVersion() == null) {
105 property.setValue("");
106 } else {
107 property.setValue(moduleId.getPackage().getVersion());
108 }
109 properties.add(property);
110
111 // property = new Property();
112 // property.setName("PLATFORM_FILE");
113 // property.setValue(arch);
114 // properties.add(property);
115
116 //
117 // Build the Module
118 //
119 GenBuildTask genBuildTask = new GenBuildTask();
120
121 Project newProject = new Project();
122
123 Hashtable passdownProperties = project.getProperties();
124 Iterator iter = passdownProperties.keySet().iterator();
125 while (iter.hasNext()) {
126 String item = (String) iter.next();
127 newProject.setProperty(item, (String) passdownProperties.get(item));
128 }
129
130 newProject.setInputHandler(project.getInputHandler());
131
132 Iterator listenerIter = project.getBuildListeners().iterator();
133 while (listenerIter.hasNext()) {
134 BuildListener item = (BuildListener) listenerIter.next();
135
136 // if (item instanceof BuildLogger) {
137 // BuildLogger newLogger = new GenBuildLogger(newProject);
138 // BuildLogger oldLogger = (BuildLogger)item;
139 // newLogger.setEmacsMode(true);
140 // EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, "########");
141 // } else {
142 newProject.addBuildListener(item);
143 // }
144 }
145
146 project.initSubProject(newProject);
147
148 genBuildTask.setProject(newProject);
149
150 genBuildTask.setExternalProperties(properties);
151
152 genBuildTask.parentId = parentModuleId;
153
154 genBuildTask.perform();
155
156 status = FpdParserForThread.STATUS_END_RUN;
157
158 EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, fpdModuleId + " build finished. ");
159
160 //
161 //
162 //
163 synchronized (FpdParserForThread.deamonSemaphore) {
164 FpdParserForThread.subCount();
165 FpdParserForThread.deamonSemaphore.notifyAll();
166 }
167 }
168
169 public void setArch(String arch) {
170 this.arch = arch;
171 }
172
173 public void setDependencies(Set<FpdModuleIdentification> dependencies) {
174 this.dependencies = dependencies;
175 }
176
177 public void setModuleId(ModuleIdentification moduleId) {
178 this.moduleId = moduleId;
179 }
180
181 public void setParentModuleId(ModuleIdentification parentModuleId) {
182 this.parentModuleId = parentModuleId;
183 }
184
185 public void setProject(Project project) {
186 this.project = project;
187 }
188
189 public void setHighPriority(boolean highPriority) {
190 this.highPriority = highPriority;
191 }
192
193
194 public Set<FpdModuleIdentification> getDependencies() {
195 return dependencies;
196 }
197
198 public ModuleIdentification getModuleId() {
199 return moduleId;
200 }
201
202 public int getStatus() {
203 //
204 // Add code here to judge dependency
205 //
206 if (status == FpdParserForThread.STATUS_DEPENDENCY_NOT_READY) {
207 Iterator<FpdModuleIdentification> iter = dependencies.iterator();
208 boolean flag = true;
209 while (iter.hasNext()) {
210 FpdModuleIdentification item = iter.next();
211 if (FpdParserForThread.allThreads.get(item).getStatus() == 1) {
212 flag = false;
213 break ;
214 }
215 }
216 if (flag) {
217 status = FpdParserForThread.STATUS_DEPENDENCY_READY;
218 }
219 }
220 return status;
221 }
222
223 public void setStatus(int status) {
224 this.status = status;
225 }
226 }