1 package org
.tianocore
.build
;
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
;
16 public class OutputDirSetup
extends Task
{
18 /// Module surface area file.
23 /// Module's Identification.
25 private ModuleIdentification moduleId
;
28 /// Module's component type, such as SEC, LIBRARY, BS_DRIVER and so on.
30 private String componentType
;
32 private boolean isSingleModuleBuild
= false;
33 // private ToolChainFactory toolChainFactory;
36 Public construct method. It is necessary for ANT task.
38 public OutputDirSetup() {
41 public void execute() throws BuildException
{
43 // Global Data initialization
45 // GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",
46 // getProject().getProperty("WORKSPACE_DIR"));
49 // Parse MSA and get the basic information
50 // Including BaseName, GUID, Version, ComponentType and SupportedArchs
52 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(msaFile
);
54 SurfaceAreaQuery
.setDoc(doc
);
57 // String[]: {BaseName, ModuleType, ComponentType, Guid, Version}
59 moduleId
= SurfaceAreaQuery
.getMsaHeader();
61 componentType
= "APPLICATION";
64 // Judge whether it is single module build or not
66 if (isSingleModuleBuild
) {
68 // Single Module build
70 prepareSingleModuleBuild();
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("(\\\\)", "/"));
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
);
89 // Tools Definition file parse
91 parseToolsDefinitionFile();
94 // For Every TOOLCHAIN, TARGET, ARCH
96 // String[] targetList = GlobalData.getTargets();
97 // for (int i = 0; i < targetList.length; i ++){
99 // // Prepare for target related common properties
102 // getProject().setProperty("TARGET", targetList[i]);
103 // String[] toolchainList = GlobalData.getToolChains();
104 // for(int j = 0; j < toolchainList.length; j ++){
106 // // Prepare for toolchain related common properties
109 // getProject().setProperty("TOOLCHAIN", toolchainList[j]);
111 // // If single module : intersection MSA supported ARCHs and tools def!!
112 // // else, get arch from pass down
114 // String[] archList = GlobalData.getArchs();
115 // for (int k = 0; k < archList.length; k++) {
117 // FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
119 // SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));
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
129 // getProject().setProperty("ARCH", archList[k]);
130 // setModuleCommonProperties();
133 // // String[0] is build mode. String[1] is user-defined output dir.
135 // String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();
136 // String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();
139 // // OutputManage prepare for
140 // // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
142 // OutputManager.getInstance().update(getProject(), userDefinedOutputDir, buildMode);
150 private void prepareSingleModuleBuild(){
152 // Find out the package which the module belongs to
153 // TBD: Enhance it!!!!
155 PackageIdentification packageId
= GlobalData
.getPackageForModule(moduleId
);
157 moduleId
.setPackage(packageId
);
160 // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)
162 String filename
= getProject().getProperty("PLATFORM_FILE");
164 PlatformIdentification platformId
= GlobalData
.getPlatform(filename
);
169 FpdParserTask fpdParser
= new FpdParserTask();
170 fpdParser
.parseFpdFile(platformId
.getFpdFile());
173 // Prepare for Platform related common properties
174 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
176 getProject().setProperty("PLATFORM", platformId
.getName());
177 getProject().setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
178 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
186 private void setModuleCommonProperties() {
188 // Prepare for all other common properties
189 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
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("(\\\\)", "/"));
200 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, COMPONENT_TYPE
201 // MODULE_DIR, MODULE_RELATIVE_DIR
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("(\\\\)", "/"));
215 Method is for ANT use to initialize MSA file.
217 @param msaFilename MSA file name
219 public void setMsaFile(String msaFilename
) {
220 String moduleDir
= getProject().getProperty("MODULE_DIR");
221 if (moduleDir
== null) {
222 moduleDir
= getProject().getBaseDir().getPath();
224 msaFile
= new File(moduleDir
+ File
.separatorChar
+ msaFilename
);
230 <p> Take command <code>CC</code> and arch <code>IA32</code> for example,
231 Those flags are from <code>ToolChainFactory</code>: </p>
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>
239 Those flags can user-define:
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>
248 <li> IA32_CC_FLAGS </li>
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>
254 Note that the <code>ToolChainFactory</code> executes only once
255 during whole build process.
257 private void parseToolsDefinitionFile() {
259 // If ToolChain has been set up before, do nothing.
260 // CONF dir + tools definition file name
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");
267 // toolChainFactory = new ToolChainFactory(confDir, toolsDefFilename);
268 // toolChainFactory.setupToolChain();