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