]>
Commit | Line | Data |
---|---|---|
a29c47e0 | 1 | package org.tianocore.build;\r |
2 | \r | |
3 | import java.io.File;\r | |
4 | import java.util.Map;\r | |
5 | \r | |
6 | import org.apache.tools.ant.BuildException;\r | |
7 | import org.apache.tools.ant.Task;\r | |
8 | import org.apache.xmlbeans.XmlObject;\r | |
9 | import org.tianocore.build.fpd.FpdParserTask;\r | |
10 | import org.tianocore.build.global.GlobalData;\r | |
11 | import org.tianocore.build.global.OutputManager;\r | |
12 | import org.tianocore.build.global.SurfaceAreaQuery;\r | |
13 | import org.tianocore.build.id.FpdModuleIdentification;\r | |
14 | import org.tianocore.build.id.ModuleIdentification;\r | |
15 | import org.tianocore.build.id.PackageIdentification;\r | |
16 | import org.tianocore.build.id.PlatformIdentification;\r | |
17 | \r | |
18 | public class OutputDirSetup extends Task {\r | |
19 | ///\r | |
20 | /// Module surface area file.\r | |
21 | ///\r | |
22 | File msaFile;\r | |
23 | \r | |
24 | ///\r | |
25 | /// Module's Identification.\r | |
26 | ///\r | |
27 | private ModuleIdentification moduleId;\r | |
28 | \r | |
29 | ///\r | |
30 | /// Module's component type, such as SEC, LIBRARY, BS_DRIVER and so on.\r | |
31 | ///\r | |
32 | private String componentType;\r | |
33 | \r | |
34 | // private ToolChainFactory toolChainFactory;\r | |
35 | \r | |
36 | /**\r | |
37 | Public construct method. It is necessary for ANT task.\r | |
38 | **/\r | |
39 | public OutputDirSetup() {\r | |
40 | }\r | |
41 | \r | |
42 | public void execute() throws BuildException {\r | |
43 | //\r | |
44 | // Global Data initialization\r | |
45 | //\r | |
46 | // GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",\r | |
47 | // getProject().getProperty("WORKSPACE_DIR"));\r | |
48 | \r | |
49 | //\r | |
50 | // Parse MSA and get the basic information\r | |
51 | // Including BaseName, GUID, Version, ComponentType and SupportedArchs\r | |
52 | //\r | |
53 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r | |
54 | \r | |
55 | SurfaceAreaQuery.setDoc(doc);\r | |
56 | \r | |
57 | //\r | |
58 | // String[]: {BaseName, ModuleType, ComponentType, Guid, Version}\r | |
59 | //\r | |
60 | moduleId = SurfaceAreaQuery.getMsaHeader();\r | |
61 | // REMOVE!!! TBD\r | |
62 | componentType = "APPLICATION";\r | |
63 | \r | |
64 | //\r | |
65 | // Judge whether it is single module build or not\r | |
66 | //\r | |
67 | if (getProject().getProperty("PLATFORM") == null) {\r | |
68 | //\r | |
69 | // Single Module build\r | |
70 | //\r | |
71 | prepareSingleModuleBuild();\r | |
72 | }\r | |
73 | else {\r | |
74 | //\r | |
75 | // Platform build\r | |
76 | //\r | |
77 | String platformName = getProject().getProperty("PLATFORM");\r | |
78 | PlatformIdentification platformId = GlobalData.getPlatform(platformName);\r | |
79 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r | |
80 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
81 | \r | |
82 | String packageName = getProject().getProperty("PACKAGE");\r | |
83 | String packageGuid = getProject().getProperty("PACKAGE_GUID");\r | |
84 | String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r | |
85 | PackageIdentification packageId = new PackageIdentification(packageName, packageGuid, packageVersion);\r | |
86 | moduleId.setPackage(packageId);\r | |
87 | }\r | |
88 | \r | |
89 | //\r | |
90 | // Tools Definition file parse\r | |
91 | //\r | |
92 | parseToolsDefinitionFile();\r | |
93 | \r | |
94 | //\r | |
95 | // For Every TOOLCHAIN, TARGET, ARCH\r | |
96 | //\r | |
97 | // String[] targetList = GlobalData.getTargets();\r | |
98 | // for (int i = 0; i < targetList.length; i ++){\r | |
99 | // //\r | |
100 | // // Prepare for target related common properties\r | |
101 | // // TARGET\r | |
102 | // //\r | |
103 | // getProject().setProperty("TARGET", targetList[i]);\r | |
104 | // String[] toolchainList = GlobalData.getToolChains();\r | |
105 | // for(int j = 0; j < toolchainList.length; j ++){\r | |
106 | // //\r | |
107 | // // Prepare for toolchain related common properties\r | |
108 | // // TOOLCHAIN\r | |
109 | // //\r | |
110 | // getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r | |
111 | // //\r | |
112 | // // If single module : intersection MSA supported ARCHs and tools def!!\r | |
113 | // // else, get arch from pass down\r | |
114 | // //\r | |
115 | // String[] archList = GlobalData.getArchs();\r | |
116 | // for (int k = 0; k < archList.length; k++) {\r | |
117 | // \r | |
118 | // FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r | |
119 | // \r | |
120 | // SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));\r | |
121 | // \r | |
122 | // //\r | |
123 | // // Prepare for all other common properties\r | |
124 | // // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
125 | // // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, COMPONENT_TYPE\r | |
126 | // // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
127 | // // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r | |
128 | // // LIBS, OBJECTS, SDB_FILES\r | |
129 | // //\r | |
130 | // getProject().setProperty("ARCH", archList[k]);\r | |
131 | // setModuleCommonProperties();\r | |
132 | // \r | |
133 | // //\r | |
134 | // // String[0] is build mode. String[1] is user-defined output dir. \r | |
135 | // //\r | |
136 | // String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();\r | |
137 | // String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();\r | |
138 | // \r | |
139 | // //\r | |
140 | // // OutputManage prepare for \r | |
141 | // // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r | |
142 | // //\r | |
143 | // OutputManager.getInstance().update(getProject(), userDefinedOutputDir, buildMode);\r | |
144 | // \r | |
145 | // }\r | |
146 | // }\r | |
147 | // }\r | |
148 | \r | |
149 | }\r | |
150 | \r | |
151 | private void prepareSingleModuleBuild(){\r | |
152 | //\r | |
153 | // Find out the package which the module belongs to\r | |
154 | // TBD: Enhance it!!!!\r | |
155 | //\r | |
156 | PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r | |
157 | \r | |
158 | moduleId.setPackage(packageId);\r | |
159 | \r | |
160 | //\r | |
161 | // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r | |
162 | //\r | |
163 | String activePlatformName = getProject().getProperty("env.ACTIVE_PLATFORM");\r | |
164 | \r | |
165 | PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);\r | |
166 | \r | |
167 | //\r | |
168 | // Read FPD file\r | |
169 | //\r | |
170 | FpdParserTask fpdParser = new FpdParserTask();\r | |
171 | fpdParser.parseFpdFile(platformId.getFpdFile());\r | |
172 | \r | |
173 | //\r | |
174 | // Prepare for Platform related common properties\r | |
175 | // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r | |
176 | //\r | |
177 | getProject().setProperty("PLATFORM", activePlatformName);\r | |
178 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r | |
179 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
180 | }\r | |
181 | \r | |
182 | \r | |
183 | \r | |
184 | /**\r | |
185 | \r | |
186 | **/\r | |
187 | private void setModuleCommonProperties() {\r | |
188 | //\r | |
189 | // Prepare for all other common properties\r | |
190 | // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
191 | //\r | |
192 | PackageIdentification packageId = moduleId.getPackage();\r | |
193 | getProject().setProperty("PACKAGE", packageId.getName());\r | |
194 | getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r | |
195 | getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r | |
196 | GlobalData.log.info("" + packageId);\r | |
197 | getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r | |
198 | getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r | |
199 | \r | |
200 | //\r | |
201 | // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, COMPONENT_TYPE\r | |
202 | // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
203 | //\r | |
204 | getProject().setProperty("MODULE", moduleId.getName());\r | |
205 | getProject().setProperty("BASE_NAME", moduleId.getName());\r | |
206 | getProject().setProperty("GUID", moduleId.getGuid());\r | |
207 | getProject().setProperty("FILE_GUID", moduleId.getGuid());\r | |
208 | getProject().setProperty("VERSION", moduleId.getVersion());\r | |
209 | getProject().setProperty("COMPONENT_TYPE", componentType);\r | |
210 | getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r | |
211 | getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));\r | |
212 | }\r | |
213 | \r | |
214 | \r | |
215 | /**\r | |
216 | Method is for ANT use to initialize MSA file.\r | |
217 | \r | |
218 | @param msaFilename MSA file name\r | |
219 | **/\r | |
220 | public void setMsaFile(String msaFilename) {\r | |
221 | String moduleDir = getProject().getProperty("MODULE_DIR");\r | |
222 | if (moduleDir == null) {\r | |
223 | moduleDir = getProject().getBaseDir().getPath();\r | |
224 | }\r | |
225 | msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r | |
226 | }\r | |
227 | \r | |
228 | /**\r | |
229 | Compile flags setup. \r | |
230 | \r | |
231 | <p> Take command <code>CC</code> and arch <code>IA32</code> for example, \r | |
232 | Those flags are from <code>ToolChainFactory</code>: </p>\r | |
233 | <ul>\r | |
234 | <li> IA32_CC </li>\r | |
235 | <li> IA32_CC_STD_FLAGS </li>\r | |
236 | <li> IA32_CC_GLOBAL_FLAGS </li>\r | |
237 | <li> IA32_CC_GLOBAL_ADD_FLAGS </li>\r | |
238 | <li> IA32_CC_GLOBAL_SUB_FLAGS </li>\r | |
239 | </ul>\r | |
240 | Those flags can user-define: \r | |
241 | <ul>\r | |
242 | <li> IA32_CC_PROJ_FLAGS </li>\r | |
243 | <li> IA32_CC_PROJ_ADD_FLAGS </li>\r | |
244 | <li> IA32_CC_PROJ_SUB_FLAGS </li>\r | |
245 | <li> CC_PROJ_FLAGS </li>\r | |
246 | <li> CC_PROJ_ADD_FLAGS </li>\r | |
247 | <li> CC_PROJ_SUB_FLAGS </li>\r | |
248 | <li> CC_FLAGS </li>\r | |
249 | <li> IA32_CC_FLAGS </li>\r | |
250 | </ul>\r | |
251 | \r | |
252 | <p> The final flags is composed of STD, GLOBAL and PROJ. If CC_FLAGS or\r | |
253 | IA32_CC_FLAGS is specified, STD, GLOBAL and PROJ will not affect. </p>\r | |
254 | \r | |
255 | Note that the <code>ToolChainFactory</code> executes only once \r | |
256 | during whole build process. \r | |
257 | **/\r | |
258 | private void parseToolsDefinitionFile() {\r | |
259 | //\r | |
260 | // If ToolChain has been set up before, do nothing.\r | |
261 | // CONF dir + tools definition file name\r | |
262 | //\r | |
263 | String confDir = GlobalData.getWorkspacePath() + File.separatorChar + "Tools" + File.separatorChar + "Conf";\r | |
264 | String toolsDefFilename = "tools_def.txt";\r | |
265 | if (getProject().getProperty("env.TOOLS_DEF") != null) {\r | |
266 | toolsDefFilename = getProject().getProperty("env.TOOLS_DEF");\r | |
267 | }\r | |
268 | // toolChainFactory = new ToolChainFactory(confDir, toolsDefFilename);\r | |
269 | // toolChainFactory.setupToolChain();\r | |
270 | }\r | |
271 | }\r |