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