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