]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java
Remove TianoToolsException.java. Add code to stop all threads once one corrupts.
[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.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.id.FpdModuleIdentification;
28 import org.tianocore.build.id.ModuleIdentification;
29 import org.tianocore.common.logger.EdkLog;
30
31 /**
32 Add more comment here.
33
34 @since GenBuild 1.0
35 **/
36 public class GenBuildThread implements Runnable {
37
38 private ModuleIdentification parentModuleId = null;
39
40 private ModuleIdentification moduleId = null;
41
42 private Set<FpdModuleIdentification> dependencies = new LinkedHashSet<FpdModuleIdentification>();
43
44 private int status = FpdParserForThread.STATUS_DEPENDENCY_NOT_READY;
45
46 private Project project = null;
47
48 public Object semaphore = new Object();
49
50 private String arch = null;
51
52 private boolean highPriority = false;
53
54 private Thread thread;
55
56 public GenBuildThread(ModuleIdentification moduleId, String arch) {
57 this.moduleId = moduleId;
58 this.arch = arch;
59 thread = new Thread(FpdParserForThread.tg, this, moduleId + ":" + arch);
60 }
61
62 public boolean start() {
63 if (highPriority) {
64 thread.setPriority(Thread.MAX_PRIORITY);
65 }
66
67 status = FpdParserForThread.STATUS_START_RUN;
68 thread.start();
69 return true;
70 }
71
72 public void run() {
73
74 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
75
76 try {
77 //
78 // Prepare pass down properties
79 // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE
80 //
81 Vector<Property> properties = new Vector<Property>();
82 Property property = new Property();
83 property.setName("ARCH");
84 property.setValue(arch);
85 properties.add(property);
86
87 property = new Property();
88 property.setName("MODULE_GUID");
89 property.setValue(moduleId.getGuid());
90 properties.add(property);
91
92 property = new Property();
93 property.setName("MODULE_VERSION");
94 if (moduleId.getVersion() == null) {
95 property.setValue("");
96 } else {
97 property.setValue(moduleId.getVersion());
98 }
99 properties.add(property);
100
101 property = new Property();
102 property.setName("PACKAGE_GUID");
103 property.setValue(moduleId.getPackage().getGuid());
104 properties.add(property);
105
106 property = new Property();
107 property.setName("PACKAGE_VERSION");
108 if (moduleId.getPackage().getVersion() == null) {
109 property.setValue("");
110 } else {
111 property.setValue(moduleId.getPackage().getVersion());
112 }
113 properties.add(property);
114
115 //
116 // Build the Module
117 //
118 GenBuildTask genBuildTask = new GenBuildTask();
119
120 Project newProject = new Project();
121
122 Hashtable passdownProperties = project.getProperties();
123 Iterator iter = passdownProperties.keySet().iterator();
124 while (iter.hasNext()) {
125 String item = (String) iter.next();
126 newProject.setProperty(item, (String) passdownProperties.get(item));
127 }
128
129 newProject.setInputHandler(project.getInputHandler());
130
131 Iterator listenerIter = project.getBuildListeners().iterator();
132 while (listenerIter.hasNext()) {
133 newProject.addBuildListener((BuildListener)listenerIter.next());
134 }
135
136 project.initSubProject(newProject);
137
138 genBuildTask.setProject(newProject);
139
140 genBuildTask.setExternalProperties(properties);
141
142 genBuildTask.parentId = parentModuleId;
143
144 genBuildTask.execute();
145 } catch (BuildException be) {
146 FpdParserForThread.tg.interrupt();
147 EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, moduleId + " with Arch " + arch +" build error. \n" + be.getMessage());
148 FpdParserForThread.isError = true;
149
150 synchronized (FpdParserForThread.deamonSemaphore) {
151 FpdParserForThread.deamonSemaphore.notifyAll();
152 }
153 return ;
154 }
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 }