]>
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 | |
21 | import org.apache.tools.ant.BuildListener;\r | |
22 | import org.apache.tools.ant.Project;\r | |
23 | import org.apache.tools.ant.taskdefs.Property;\r | |
24 | import org.tianocore.build.GenBuildTask;\r | |
25 | import org.tianocore.build.fpd.FpdParserForThread;\r | |
26 | import org.tianocore.build.id.FpdModuleIdentification;\r | |
27 | import org.tianocore.build.id.ModuleIdentification;\r | |
02c768ee | 28 | import org.tianocore.common.logger.EdkLog;\r |
abce9cbd | 29 | \r |
30 | /**\r | |
31 | Add more comment here. \r | |
32 | \r | |
33 | @since GenBuild 1.0\r | |
34 | **/\r | |
35 | public class GenBuildThread implements Runnable {\r | |
36 | \r | |
37 | private ModuleIdentification parentModuleId = null;\r | |
38 | \r | |
39 | private ModuleIdentification moduleId = null;\r | |
40 | \r | |
41 | private Set<FpdModuleIdentification> dependencies = new LinkedHashSet<FpdModuleIdentification>();\r | |
42 | \r | |
43 | private int status = FpdParserForThread.STATUS_DEPENDENCY_NOT_READY;\r | |
44 | \r | |
45 | private Project project = null;\r | |
46 | \r | |
47 | public Object semaphore = new Object();\r | |
48 | \r | |
49 | private String arch = null;\r | |
50 | \r | |
51 | private boolean highPriority = false;\r | |
52 | \r | |
53 | private Thread thread;\r | |
54 | \r | |
55 | public GenBuildThread() {\r | |
56 | thread = new Thread(this);\r | |
57 | }\r | |
58 | \r | |
59 | public boolean start() {\r | |
60 | if (highPriority) {\r | |
61 | thread.setPriority(Thread.MAX_PRIORITY);\r | |
62 | }\r | |
63 | \r | |
64 | status = FpdParserForThread.STATUS_START_RUN;\r | |
65 | thread.start();\r | |
66 | return true;\r | |
67 | }\r | |
68 | \r | |
69 | public void run() {\r | |
70 | \r | |
71 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r | |
72 | \r | |
73 | //\r | |
74 | // Prepare pass down properties\r | |
75 | // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE\r | |
76 | //\r | |
77 | Vector<Property> properties = new Vector<Property>();\r | |
78 | Property property = new Property();\r | |
79 | property.setName("ARCH");\r | |
80 | property.setValue(arch);\r | |
81 | properties.add(property);\r | |
82 | \r | |
83 | property = new Property();\r | |
84 | property.setName("MODULE_GUID");\r | |
85 | property.setValue(moduleId.getGuid());\r | |
86 | properties.add(property);\r | |
87 | \r | |
88 | property = new Property();\r | |
89 | property.setName("MODULE_VERSION");\r | |
90 | if (moduleId.getVersion() == null) {\r | |
91 | property.setValue("");\r | |
92 | } else {\r | |
93 | property.setValue(moduleId.getVersion());\r | |
94 | }\r | |
95 | properties.add(property);\r | |
96 | \r | |
97 | property = new Property();\r | |
98 | property.setName("PACKAGE_GUID");\r | |
99 | property.setValue(moduleId.getPackage().getGuid());\r | |
100 | properties.add(property);\r | |
101 | \r | |
102 | property = new Property();\r | |
103 | property.setName("PACKAGE_VERSION");\r | |
104 | if (moduleId.getPackage().getVersion() == null) {\r | |
105 | property.setValue("");\r | |
106 | } else {\r | |
107 | property.setValue(moduleId.getPackage().getVersion());\r | |
108 | }\r | |
109 | properties.add(property);\r | |
110 | \r | |
111 | // property = new Property();\r | |
112 | // property.setName("PLATFORM_FILE");\r | |
113 | // property.setValue(arch);\r | |
114 | // properties.add(property);\r | |
115 | \r | |
116 | //\r | |
117 | // Build the Module\r | |
118 | //\r | |
119 | GenBuildTask genBuildTask = new GenBuildTask();\r | |
120 | \r | |
121 | Project newProject = new Project();\r | |
122 | \r | |
123 | Hashtable passdownProperties = project.getProperties();\r | |
124 | Iterator iter = passdownProperties.keySet().iterator();\r | |
125 | while (iter.hasNext()) {\r | |
126 | String item = (String) iter.next();\r | |
127 | newProject.setProperty(item, (String) passdownProperties.get(item));\r | |
128 | }\r | |
129 | \r | |
130 | newProject.setInputHandler(project.getInputHandler());\r | |
131 | \r | |
132 | Iterator listenerIter = project.getBuildListeners().iterator();\r | |
133 | while (listenerIter.hasNext()) {\r | |
2eb7d78d | 134 | BuildListener item = (BuildListener) listenerIter.next();\r |
135 | \r | |
136 | // if (item instanceof BuildLogger) {\r | |
137 | // BuildLogger newLogger = new GenBuildLogger(newProject);\r | |
138 | // BuildLogger oldLogger = (BuildLogger)item;\r | |
139 | // newLogger.setEmacsMode(true);\r | |
140 | // EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, "########");\r | |
141 | // } else {\r | |
142 | newProject.addBuildListener(item);\r | |
143 | // }\r | |
abce9cbd | 144 | }\r |
145 | \r | |
146 | project.initSubProject(newProject);\r | |
147 | \r | |
148 | genBuildTask.setProject(newProject);\r | |
149 | \r | |
150 | genBuildTask.setExternalProperties(properties);\r | |
151 | \r | |
152 | genBuildTask.parentId = parentModuleId;\r | |
153 | \r | |
154 | genBuildTask.perform();\r | |
155 | \r | |
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 |