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