- Fixed EDKT146; The override warning message has been reduced to almost none.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / OutputManager.java
1 /** @file
2 OutputManager class.
3
4 OutputManager class set output directories for every module by BUILD_MODE.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 **/
15 package org.tianocore.build.global;
16
17 import org.apache.tools.ant.Project;
18 import java.io.File;
19 import org.tianocore.build.global.PropertyManager;
20
21 /**
22 OutputManager class is used to setup output directories (BIN_DIR, DEST_DIR_OUTPUT,
23 DEST_DIR_DEBUG).
24
25 @since GenBuild 1.0
26 **/
27 public class OutputManager {
28
29 ///
30 /// means intermediate files will put under Module's dir
31 ///
32 private String MODULE = "MODULE";
33
34 ///
35 /// mean intermediate files will put under a unify dir
36 ///
37 private String UNIFIED = "UNIFIED";
38
39
40 private String userdir;
41
42 private String type;
43 ///
44 /// Singleton Design Pattern
45 ///
46 private static OutputManager object;
47
48 public synchronized static OutputManager getInstance() {
49 if ( object == null ) {
50 object = new OutputManager();
51 }
52 return object;
53 }
54
55 public void setup(String userdir, String type) {
56 this.userdir = userdir;
57 this.type = type;
58 }
59
60 /**
61 Setup BIN_DIR, DEST_DIR_OUTPUT and DEST_DIR_OUTPUT, following are the rules:
62
63 <p>Divide all output files into two types: one is final files, such as FFS
64 file for driver module while LIB file for library module; another is
65 intermediate files, such AutoGen.c, OBJ files, Section files and so on.
66
67 <p>In FPD, OutputDirectory element is used to specify where to put the output
68 files to. There are two mode (MODULE | UNIFIED). MODULE mode means that all
69 output files will put to the module directory while UNIFIED mode means that
70 all output files will put together. Default is UNIFIED mode.
71
72 <p>BUILD_DIR is the base directory for current module build. By default,
73 BUILD_DIR is PLATFORM_DIR/Build in UNIFIED mode while is MODULE_DIR/Build
74 in MODULE mode. Of course, user can customize BUILD_DIR. If user-defined
75 BUILD_DIR is relative path, then look as related to WORKSPACE_DIR.
76
77 <p>Then, BIN_DIR is BUILD_DIR/TARGET/TOOLCHAIN/ARCH;
78
79 <p>FV_DIR is BUILD_DIR/TARGET/TOOLCHAIN/FV;
80
81 <p>DEST_DIR_DEBUG | DEST_DIR_OUTPUT is:
82 BIN_DIR/PACKAGE_RELATIVE_DIR/MODULE_RELATIVE_DIR/DEBUG | OUTPUT
83
84
85 @param project current ANT build Project
86 @param userdir user-defined directory
87 @param type the module build type (MODULE or UNIFIED)
88 **/
89 public void update(Project project) {
90 //
91 // Default mode is UNIFIED.
92 //
93 if (type != null && type.equalsIgnoreCase(MODULE)) {
94 type = MODULE;
95 }
96 else {
97 type = UNIFIED;
98 }
99
100 //
101 // default BUILD_DIR value
102 //
103 String buildDir;
104 if(type.equals(MODULE)){
105 buildDir = project.getProperty("MODULE_DIR") + File.separatorChar + "Build";
106 }
107 else {
108 buildDir = project.getProperty("PLATFORM_DIR") + File.separatorChar + "Build";
109 }
110
111 //
112 // If user define BUILD_DIR
113 //
114 if (userdir != null && ! userdir.equals("")) {
115 File buildFile = new File(userdir);
116 if (buildFile.isAbsolute()){
117 buildDir = userdir;
118 }
119 //
120 // If path is not absolute, then look as related to WORKSPACE_DIR
121 //
122 else {
123 buildDir = GlobalData.getWorkspacePath() + File.separatorChar + userdir;
124 }
125 }
126
127 //
128 // Define BIN_DIR and FV_DIR
129 //
130 String binDir = buildDir + File.separatorChar + project.getProperty("TARGET")
131 + File.separatorChar + project.getProperty("TOOLCHAIN")
132 + File.separatorChar + project.getProperty("ARCH") ;
133
134 String fvDir = buildDir + File.separatorChar + project.getProperty("TARGET")
135 + File.separatorChar + project.getProperty("TOOLCHAIN")
136 + File.separatorChar + "FV";
137
138 //
139 // Define DEST_DIR_OUTPUT and DEST_DIR_DEBUG
140 //
141 String destDir = binDir + File.separatorChar + project.getProperty("PACKAGE_RELATIVE_DIR")
142 + File.separatorChar + project.getProperty("MODULE_RELATIVE_DIR");
143
144 //
145 // Set properties
146 //
147 PropertyManager.setProperty(project, "BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));
148 PropertyManager.setProperty(project, "FV_DIR", fvDir.replaceAll("(\\\\)", "/"));
149 PropertyManager.setProperty(project, "BIN_DIR", binDir.replaceAll("(\\\\)", "/"));
150 PropertyManager.setProperty(project, "DEST_DIR_DEBUG", (destDir + File.separatorChar + "DEBUG").replaceAll("(\\\\)", "/"));
151 PropertyManager.setProperty(project, "DEST_DIR_OUTPUT", (destDir + File.separatorChar + "OUTPUT").replaceAll("(\\\\)", "/"));
152
153 //
154 // Create all directory if necessary
155 //
156 (new File(buildDir)).mkdirs();
157 (new File(fvDir)).mkdirs();
158 (new File(binDir)).mkdirs();
159 (new File(destDir + File.separatorChar + "DEBUG")).mkdirs();
160 (new File(destDir + File.separatorChar + "OUTPUT")).mkdirs();
161 }
162
163 public boolean prepareBuildDir(Project project){
164 boolean isUnified = true;
165
166 if (type.equalsIgnoreCase("MODULE")) {
167 isUnified = false;
168 }
169
170 String buildDir = project.getProperty("PLATFORM_DIR") + File.separatorChar + "Build";
171 //
172 // If user define BUILD_DIR
173 //
174 if (userdir != null && ! userdir.equals("")) {
175 File buildFile = new File(userdir);
176 if (buildFile.isAbsolute()){
177 buildDir = userdir;
178 }
179 //
180 // If path is not absolute, then look as related to WORKSPACE_DIR
181 //
182 else {
183 buildDir = GlobalData.getWorkspacePath() + File.separatorChar + userdir;
184 }
185 }
186
187 //
188 // Set to property
189 //
190 PropertyManager.setProperty(project, "BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));
191
192 //
193 // Create all directory if necessary
194 //
195 (new File(buildDir)).mkdirs();
196 return isUnified;
197 }
198
199 }