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
.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
;
18 public class OutputDirSetup
extends Task
{
20 /// Module surface area file.
25 /// Module's Identification.
27 private ModuleIdentification moduleId
;
30 /// Module's component type, such as SEC, LIBRARY, BS_DRIVER and so on.
32 private String componentType
;
34 // private ToolChainFactory toolChainFactory;
37 Public construct method. It is necessary for ANT task.
39 public OutputDirSetup() {
42 public void execute() throws BuildException
{
44 // Global Data initialization
46 // GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",
47 // getProject().getProperty("WORKSPACE_DIR"));
50 // Parse MSA and get the basic information
51 // Including BaseName, GUID, Version, ComponentType and SupportedArchs
53 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(msaFile
);
55 SurfaceAreaQuery
.setDoc(doc
);
58 // String[]: {BaseName, ModuleType, ComponentType, Guid, Version}
60 moduleId
= SurfaceAreaQuery
.getMsaHeader();
62 componentType
= "APPLICATION";
65 // Judge whether it is single module build or not
67 if (getProject().getProperty("PLATFORM") == null) {
69 // Single Module build
71 prepareSingleModuleBuild();
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("(\\\\)", "/"));
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
);
90 // Tools Definition file parse
92 parseToolsDefinitionFile();
95 // For Every TOOLCHAIN, TARGET, ARCH
97 // String[] targetList = GlobalData.getTargets();
98 // for (int i = 0; i < targetList.length; i ++){
100 // // Prepare for target related common properties
103 // getProject().setProperty("TARGET", targetList[i]);
104 // String[] toolchainList = GlobalData.getToolChains();
105 // for(int j = 0; j < toolchainList.length; j ++){
107 // // Prepare for toolchain related common properties
110 // getProject().setProperty("TOOLCHAIN", toolchainList[j]);
112 // // If single module : intersection MSA supported ARCHs and tools def!!
113 // // else, get arch from pass down
115 // String[] archList = GlobalData.getArchs();
116 // for (int k = 0; k < archList.length; k++) {
118 // FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
120 // SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));
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
130 // getProject().setProperty("ARCH", archList[k]);
131 // setModuleCommonProperties();
134 // // String[0] is build mode. String[1] is user-defined output dir.
136 // String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();
137 // String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();
140 // // OutputManage prepare for
141 // // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
143 // OutputManager.getInstance().update(getProject(), userDefinedOutputDir, buildMode);
151 private void prepareSingleModuleBuild(){
153 // Find out the package which the module belongs to
154 // TBD: Enhance it!!!!
156 PackageIdentification packageId
= GlobalData
.getPackageForModule(moduleId
);
158 moduleId
.setPackage(packageId
);
161 // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)
163 String activePlatformName
= getProject().getProperty("env.ACTIVE_PLATFORM");
165 PlatformIdentification platformId
= GlobalData
.getPlatform(activePlatformName
);
170 FpdParserTask fpdParser
= new FpdParserTask();
171 fpdParser
.parseFpdFile(platformId
.getFpdFile());
174 // Prepare for Platform related common properties
175 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
177 getProject().setProperty("PLATFORM", activePlatformName
);
178 getProject().setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
179 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
187 private void setModuleCommonProperties() {
189 // Prepare for all other common properties
190 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
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("(\\\\)", "/"));
201 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, COMPONENT_TYPE
202 // MODULE_DIR, MODULE_RELATIVE_DIR
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("(\\\\)", "/"));
216 Method is for ANT use to initialize MSA file.
218 @param msaFilename MSA file name
220 public void setMsaFile(String msaFilename
) {
221 String moduleDir
= getProject().getProperty("MODULE_DIR");
222 if (moduleDir
== null) {
223 moduleDir
= getProject().getBaseDir().getPath();
225 msaFile
= new File(moduleDir
+ File
.separatorChar
+ msaFilename
);
231 <p> Take command <code>CC</code> and arch <code>IA32</code> for example,
232 Those flags are from <code>ToolChainFactory</code>: </p>
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>
240 Those flags can user-define:
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>
249 <li> IA32_CC_FLAGS </li>
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>
255 Note that the <code>ToolChainFactory</code> executes only once
256 during whole build process.
258 private void parseToolsDefinitionFile() {
260 // If ToolChain has been set up before, do nothing.
261 // CONF dir + tools definition file name
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");
268 // toolChainFactory = new ToolChainFactory(confDir, toolsDefFilename);
269 // toolChainFactory.setupToolChain();