]>
Commit | Line | Data |
---|---|---|
abce9cbd | 1 | /** @file\r |
2 | This file is for single module thread definition. \r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | **/\r | |
13 | package org.tianocore.build;\r | |
14 | \r | |
15 | import java.util.Hashtable;\r | |
16 | import java.util.Iterator;\r | |
17 | import java.util.LinkedHashSet;\r | |
18 | import java.util.Set;\r | |
19 | import java.util.Vector;\r | |
20 | \r | |
3067c4b0 | 21 | import org.apache.tools.ant.BuildException;\r |
abce9cbd | 22 | import org.apache.tools.ant.BuildListener;\r |
23 | import org.apache.tools.ant.Project;\r | |
24 | import org.apache.tools.ant.taskdefs.Property;\r | |
25 | import org.tianocore.build.GenBuildTask;\r | |
26 | import org.tianocore.build.fpd.FpdParserForThread;\r | |
27 | import org.tianocore.build.id.FpdModuleIdentification;\r | |
28 | import org.tianocore.build.id.ModuleIdentification;\r | |
02c768ee | 29 | import org.tianocore.common.logger.EdkLog;\r |
abce9cbd | 30 | \r |
31 | /**\r | |
32 | Add more comment here. \r | |
33 | \r | |
34 | @since GenBuild 1.0\r | |
35 | **/\r | |
36 | public class GenBuildThread implements Runnable {\r | |
37 | \r | |
38 | private ModuleIdentification parentModuleId = null;\r | |
39 | \r | |
40 | private ModuleIdentification moduleId = null;\r | |
41 | \r | |
42 | private Set<FpdModuleIdentification> dependencies = new LinkedHashSet<FpdModuleIdentification>();\r | |
43 | \r | |
44 | private int status = FpdParserForThread.STATUS_DEPENDENCY_NOT_READY;\r | |
45 | \r | |
46 | private Project project = null;\r | |
47 | \r | |
48 | public Object semaphore = new Object();\r | |
49 | \r | |
50 | private String arch = null;\r | |
51 | \r | |
52 | private boolean highPriority = false;\r | |
53 | \r | |
54 | private Thread thread;\r | |
55 | \r | |
3067c4b0 | 56 | public GenBuildThread(ModuleIdentification moduleId, String arch) {\r |
57 | this.moduleId = moduleId;\r | |
58 | this.arch = arch;\r | |
59 | thread = new Thread(FpdParserForThread.tg, this, moduleId + ":" + arch);\r | |
abce9cbd | 60 | }\r |
61 | \r | |
62 | public boolean start() {\r | |
63 | if (highPriority) {\r | |
64 | thread.setPriority(Thread.MAX_PRIORITY);\r | |
65 | }\r | |
3067c4b0 | 66 | \r |
abce9cbd | 67 | status = FpdParserForThread.STATUS_START_RUN;\r |
68 | thread.start();\r | |
69 | return true;\r | |
70 | }\r | |
71 | \r | |
72 | public void run() {\r | |
abce9cbd | 73 | \r |
3067c4b0 | 74 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r |
75 | \r | |
76 | try {\r | |
77 | //\r | |
78 | // Prepare pass down properties\r | |
79 | // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE\r | |
80 | //\r | |
81 | Vector<Property> properties = new Vector<Property>();\r | |
82 | Property property = new Property();\r | |
83 | property.setName("ARCH");\r | |
84 | property.setValue(arch);\r | |
85 | properties.add(property);\r | |
86 | \r | |
87 | property = new Property();\r | |
88 | property.setName("MODULE_GUID");\r | |
89 | property.setValue(moduleId.getGuid());\r | |
90 | properties.add(property);\r | |
91 | \r | |
92 | property = new Property();\r | |
93 | property.setName("MODULE_VERSION");\r | |
94 | if (moduleId.getVersion() == null) {\r | |
95 | property.setValue("");\r | |
96 | } else {\r | |
97 | property.setValue(moduleId.getVersion());\r | |
98 | }\r | |
99 | properties.add(property);\r | |
100 | \r | |
101 | property = new Property();\r | |
102 | property.setName("PACKAGE_GUID");\r | |
103 | property.setValue(moduleId.getPackage().getGuid());\r | |
104 | properties.add(property);\r | |
105 | \r | |
106 | property = new Property();\r | |
107 | property.setName("PACKAGE_VERSION");\r | |
108 | if (moduleId.getPackage().getVersion() == null) {\r | |
109 | property.setValue("");\r | |
110 | } else {\r | |
111 | property.setValue(moduleId.getPackage().getVersion());\r | |
112 | }\r | |
113 | properties.add(property);\r | |
114 | \r | |
115 | //\r | |
116 | // Build the Module\r | |
117 | //\r | |
118 | GenBuildTask genBuildTask = new GenBuildTask();\r | |
119 | \r | |
120 | Project newProject = new Project();\r | |
121 | \r | |
122 | Hashtable passdownProperties = project.getProperties();\r | |
123 | Iterator iter = passdownProperties.keySet().iterator();\r | |
124 | while (iter.hasNext()) {\r | |
125 | String item = (String) iter.next();\r | |
126 | newProject.setProperty(item, (String) passdownProperties.get(item));\r | |
127 | }\r | |
128 | \r | |
129 | newProject.setInputHandler(project.getInputHandler());\r | |
130 | \r | |
131 | Iterator listenerIter = project.getBuildListeners().iterator();\r | |
132 | while (listenerIter.hasNext()) {\r | |
133 | newProject.addBuildListener((BuildListener)listenerIter.next());\r | |
134 | }\r | |
135 | \r | |
136 | project.initSubProject(newProject);\r | |
137 | \r | |
138 | genBuildTask.setProject(newProject);\r | |
139 | \r | |
140 | genBuildTask.setExternalProperties(properties);\r | |
141 | \r | |
142 | genBuildTask.parentId = parentModuleId;\r | |
143 | \r | |
144 | genBuildTask.execute();\r | |
145 | } catch (BuildException be) {\r | |
146 | FpdParserForThread.tg.interrupt();\r | |
147 | EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, moduleId + " with Arch " + arch +" build error. \n" + be.getMessage());\r | |
148 | FpdParserForThread.isError = true; \r | |
2eb7d78d | 149 | \r |
3067c4b0 | 150 | synchronized (FpdParserForThread.deamonSemaphore) {\r |
151 | FpdParserForThread.deamonSemaphore.notifyAll();\r | |
152 | }\r | |
153 | return ;\r | |
abce9cbd | 154 | }\r |
3067c4b0 | 155 | \r |
abce9cbd | 156 | status = FpdParserForThread.STATUS_END_RUN;\r |
2eb7d78d | 157 | \r |
158 | EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, fpdModuleId + " build finished. ");\r | |
abce9cbd | 159 | \r |
160 | //\r | |
161 | // \r | |
162 | //\r | |
163 | synchronized (FpdParserForThread.deamonSemaphore) {\r | |
164 | FpdParserForThread.subCount();\r | |
165 | FpdParserForThread.deamonSemaphore.notifyAll();\r | |
166 | }\r | |
167 | }\r | |
168 | \r | |
169 | public void setArch(String arch) {\r | |
170 | this.arch = arch;\r | |
171 | }\r | |
172 | \r | |
173 | public void setDependencies(Set<FpdModuleIdentification> dependencies) {\r | |
174 | this.dependencies = dependencies;\r | |
175 | }\r | |
176 | \r | |
177 | public void setModuleId(ModuleIdentification moduleId) {\r | |
178 | this.moduleId = moduleId;\r | |
179 | }\r | |
180 | \r | |
181 | public void setParentModuleId(ModuleIdentification parentModuleId) {\r | |
182 | this.parentModuleId = parentModuleId;\r | |
183 | }\r | |
184 | \r | |
185 | public void setProject(Project project) {\r | |
186 | this.project = project;\r | |
187 | }\r | |
188 | \r | |
189 | public void setHighPriority(boolean highPriority) {\r | |
190 | this.highPriority = highPriority;\r | |
191 | }\r | |
192 | \r | |
193 | \r | |
194 | public Set<FpdModuleIdentification> getDependencies() {\r | |
195 | return dependencies;\r | |
196 | }\r | |
197 | \r | |
198 | public ModuleIdentification getModuleId() {\r | |
199 | return moduleId;\r | |
200 | }\r | |
201 | \r | |
202 | public int getStatus() {\r | |
203 | //\r | |
204 | // Add code here to judge dependency\r | |
205 | //\r | |
206 | if (status == FpdParserForThread.STATUS_DEPENDENCY_NOT_READY) {\r | |
207 | Iterator<FpdModuleIdentification> iter = dependencies.iterator();\r | |
208 | boolean flag = true;\r | |
209 | while (iter.hasNext()) {\r | |
210 | FpdModuleIdentification item = iter.next();\r | |
211 | if (FpdParserForThread.allThreads.get(item).getStatus() == 1) {\r | |
212 | flag = false;\r | |
213 | break ;\r | |
214 | }\r | |
215 | }\r | |
216 | if (flag) {\r | |
217 | status = FpdParserForThread.STATUS_DEPENDENCY_READY;\r | |
218 | }\r | |
219 | }\r | |
220 | return status;\r | |
221 | }\r | |
222 | \r | |
223 | public void setStatus(int status) {\r | |
224 | this.status = status;\r | |
225 | }\r | |
abce9cbd | 226 | }\r |