]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/OutputDirSetupTask.java
Fix two bugs for current PCD workflow:
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / OutputDirSetupTask.java
CommitLineData
878ddf1f 1/** @file\r
2 \r
3 This file is an ANT task OutputDirSetupTask. \r
4 \r
5 This task main purpose is to setup some necessary properties for Package,\r
6 Platform or Module clean. \r
7 \r
8Copyright (c) 2006, Intel Corporation\r
9All rights reserved. This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16**/\r
17package org.tianocore.build;\r
18\r
19import java.io.File;\r
20import java.util.HashMap;\r
21import java.util.Map;\r
22\r
23import org.apache.tools.ant.BuildException;\r
24import org.apache.tools.ant.Task;\r
25import org.apache.xmlbeans.XmlObject;\r
26\r
27import org.tianocore.build.global.GlobalData;\r
28import org.tianocore.build.global.OutputManager;\r
29import org.tianocore.build.global.SurfaceAreaQuery;\r
30import org.tianocore.build.toolchain.ToolChainFactory;\r
31\r
32/**\r
33 <code>OutputDirSetupTask</code> is an ANT task that can be used in ANT build\r
34 system. The main function of this task is to initialize some basic information\r
35 for Package|Platform|Module clean or cleanall usage. \r
36 \r
37 <p>Here is an example: </p> \r
38 <pre>\r
39 &lt;OutputDirSetup baseName="HelloWorld" \r
40 mbdFilename="${MODULE_DIR}\HelloWorld.mbd" \r
41 msaFilename="${MODULE_DIR}\HelloWorld.msa" /&gt;\r
42 </pre>\r
43 \r
44 <p>Note that all this task doing is part of GenBuildTask. </p>\r
45 \r
46 @since GenBuild 1.0\r
47 @see org.tianocore.build.GenBuildTask\r
48**/\r
49public class OutputDirSetupTask extends Task {\r
50 \r
51 ///\r
52 /// Module surface area file.\r
53 ///\r
54 File msaFilename;\r
55\r
56 ///\r
57 /// Module build description file.\r
58 ///\r
59 File mbdFilename;\r
60 \r
61 ///\r
62 /// Module surface area information after overrided.\r
63 ///\r
64 public Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
65 \r
66 ///\r
67 /// Module's base name.\r
68 ///\r
69 private String baseName;\r
70 \r
71 /**\r
72 Public construct method. It is necessary for ANT task.\r
73 **/\r
74 public OutputDirSetupTask () {\r
75 }\r
76 \r
77 /**\r
78 ANT task's entry point, will be called after init(). The main steps is described\r
79 as following: \r
80 <ul>\r
81 <li> Judge current build mode (MODULE | PACKAGE | PLATFORM). This step will execute\r
82 only once in whole build process; </li>\r
83 <li> Initialize global information (Framework DB, SPD files and all MSA files \r
84 listed in SPD). This step will execute only once in whole build process; </li>\r
85 <li> Restore some important ANT property. If current build is single module \r
86 build, here will set many default values; </li>\r
87 <li> Get the current module's overridded surface area information from \r
88 global data; </li> \r
89 <li> Set up the output directories, including BIN_DIR, DEST_DIR_OUTPUT and\r
90 DEST_DIR_DEBUG; </li>\r
91 </ul>\r
92 \r
93 @throws BuildException\r
94 From module build, exception from module surface area invalid.\r
95 **/\r
96 public void execute() throws BuildException {\r
97 System.out.println("Deleting module [" + baseName + "] start.");\r
98 OutputManager.update(getProject());\r
99 GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db", getProject()\r
100 .getProperty("WORKSPACE_DIR"));\r
101 recallFixedProperties();\r
102 map = GlobalData.getDoc(baseName);\r
103 //\r
104 // Initialize SurfaceAreaQuery\r
105 //\r
106 SurfaceAreaQuery.setDoc(map);\r
107 //\r
108 // Setup Output Management\r
109 //\r
110 String[] outdir = SurfaceAreaQuery.getOutputDirectory();\r
111 OutputManager.update(getProject(), outdir[1], outdir[0]);\r
112 }\r
113 \r
114 /**\r
115 Get current module's base name. \r
116 \r
117 @return base name\r
118 **/\r
119 public String getBaseName() {\r
120 return baseName;\r
121 }\r
122\r
123 /**\r
124 Set base name. For ANT use.\r
125 \r
126 @param baseName Base name\r
127 **/\r
128 public void setBaseName(String baseName) {\r
129 this.baseName = baseName;\r
130 }\r
131\r
132 /**\r
133 Set MBD surface area file. For ANT use.\r
134 \r
135 @param mbdFilename Surface Area file\r
136 **/\r
137 public void setMbdFilename(File mbdFilename) {\r
138 this.mbdFilename = mbdFilename;\r
139 }\r
140\r
141 /**\r
142 Set MSA surface area file. For ANT use.\r
143 \r
144 @param msaFilename Surface Area file\r
145 **/\r
146 public void setMsaFilename(File msaFilename) {\r
147 this.msaFilename = msaFilename;\r
148 }\r
149 \r
150 /**\r
151 Restore some important ANT property. If current build is single module \r
152 build, here will set many default values.\r
153 \r
154 <p> If current build is single module build, then the default <code>ARCH</code>\r
155 is <code>IA32</code>. Also set up the properties <code>PACKAGE</code>, \r
156 <code>PACKAGE_DIR</code>, <code>TARGET</code> and <code>MODULE_DIR</code></p>\r
157 \r
158 <p> Note that for package build, package name is stored in <code>PLATFORM</code>\r
159 and package directory is stored in <code>PLATFORM_DIR</code>. </p> \r
160 \r
161 @see org.tianocore.build.global.OutputManager\r
162 **/\r
163 private void recallFixedProperties(){\r
164 //\r
165 // If build is for module build\r
166 //\r
167 if (getProject().getProperty("PACKAGE_DIR") == null) {\r
168 ToolChainFactory toolChainFactory = new ToolChainFactory(getProject());\r
169 toolChainFactory.setupToolChain();\r
170 //\r
171 // PACKAGE PACKAGE_DIR ARCH (Default) COMMON_FILE BUILD_MACRO\r
172 //\r
173 if (getProject().getProperty("ARCH") == null){\r
174 getProject().setProperty("ARCH", "IA32");\r
175 }\r
176 String packageName = GlobalData.getPackageNameForModule(baseName);\r
177 getProject().setProperty("PACKAGE", packageName);\r
178 String packageDir = GlobalData.getPackagePath(packageName);\r
179 getProject().setProperty("PACKAGE_DIR", getProject().getProperty("WORKSPACE_DIR") + File.separatorChar + packageDir);\r
180 getProject().setProperty("TARGET", toolChainFactory.getCurrentTarget());\r
181 getProject().setProperty("MODULE_DIR", getProject().replaceProperties(getProject().getProperty("MODULE_DIR")));\r
182 }\r
183 if (OutputManager.PLATFORM != null) {\r
184 getProject().setProperty("PLATFORM", OutputManager.PLATFORM);\r
185 }\r
186 if (OutputManager.PLATFORM_DIR != null) {\r
187 getProject().setProperty("PLATFORM_DIR", OutputManager.PLATFORM_DIR);\r
188 }\r
189 }\r
190}\r