]>
Commit | Line | Data |
---|---|---|
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 | |
6 | Copyright (c) 2006, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | **/\r | |
15 | package org.tianocore.build.global;\r | |
16 | \r | |
17 | import org.apache.tools.ant.Project;\r | |
18 | import 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 | |
26 | public 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 |
4250be6c | 126 | //\r |
127 | // Define TARGET_DIR\r | |
128 | //\r | |
129 | String targetDir = buildDir + File.separatorChar + project.getProperty("TARGET")\r | |
130 | + "_" + project.getProperty("TOOLCHAIN");\r | |
131 | \r | |
a29c47e0 | 132 | //\r |
133 | // Define BIN_DIR and FV_DIR\r | |
134 | //\r | |
4250be6c | 135 | String binDir = targetDir + File.separatorChar + project.getProperty("ARCH") ;\r |
878ddf1f | 136 | \r |
4250be6c | 137 | String fvDir = targetDir + File.separatorChar + "FV";\r |
878ddf1f | 138 | \r |
a29c47e0 | 139 | //\r |
140 | // Define DEST_DIR_OUTPUT and DEST_DIR_DEBUG\r | |
141 | //\r | |
142 | String destDir = binDir + File.separatorChar + project.getProperty("PACKAGE_RELATIVE_DIR")\r | |
143 | + File.separatorChar + project.getProperty("MODULE_RELATIVE_DIR");\r | |
878ddf1f | 144 | \r |
a29c47e0 | 145 | //\r |
146 | // Set properties\r | |
147 | //\r | |
aca6c736 | 148 | project.setProperty("BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));\r |
4250be6c | 149 | project.setProperty("TARGET_DIR", targetDir.replaceAll("(\\\\)", "/"));\r |
aca6c736 | 150 | project.setProperty("FV_DIR", fvDir.replaceAll("(\\\\)", "/"));\r |
151 | project.setProperty("BIN_DIR", binDir.replaceAll("(\\\\)", "/"));\r | |
152 | project.setProperty("DEST_DIR_DEBUG", (destDir + File.separatorChar + "DEBUG").replaceAll("(\\\\)", "/"));\r | |
153 | project.setProperty("DEST_DIR_OUTPUT", (destDir + File.separatorChar + "OUTPUT").replaceAll("(\\\\)", "/"));\r | |
878ddf1f | 154 | \r |
a29c47e0 | 155 | //\r |
156 | // Create all directory if necessary\r | |
157 | //\r | |
158 | (new File(buildDir)).mkdirs();\r | |
159 | (new File(fvDir)).mkdirs();\r | |
160 | (new File(binDir)).mkdirs();\r | |
161 | (new File(destDir + File.separatorChar + "DEBUG")).mkdirs();\r | |
162 | (new File(destDir + File.separatorChar + "OUTPUT")).mkdirs();\r | |
878ddf1f | 163 | }\r |
a29c47e0 | 164 | \r |
165 | public boolean prepareBuildDir(Project project){\r | |
166 | boolean isUnified = true;\r | |
167 | \r | |
168 | if (type.equalsIgnoreCase("MODULE")) {\r | |
169 | isUnified = false;\r | |
170 | }\r | |
171 | \r | |
172 | String buildDir = project.getProperty("PLATFORM_DIR") + File.separatorChar + "Build";\r | |
173 | //\r | |
174 | // If user define BUILD_DIR\r | |
175 | //\r | |
176 | if (userdir != null && ! userdir.equals("")) {\r | |
177 | File buildFile = new File(userdir);\r | |
178 | if (buildFile.isAbsolute()){\r | |
179 | buildDir = userdir;\r | |
180 | }\r | |
181 | //\r | |
182 | // If path is not absolute, then look as related to WORKSPACE_DIR\r | |
183 | //\r | |
184 | else {\r | |
185 | buildDir = GlobalData.getWorkspacePath() + File.separatorChar + userdir;\r | |
186 | }\r | |
187 | }\r | |
82516887 | 188 | \r |
a29c47e0 | 189 | //\r |
190 | // Set to property\r | |
191 | //\r | |
aca6c736 | 192 | project.setProperty("BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));\r |
a29c47e0 | 193 | \r |
194 | //\r | |
195 | // Create all directory if necessary\r | |
196 | //\r | |
197 | (new File(buildDir)).mkdirs();\r | |
198 | return isUnified;\r | |
199 | }\r | |
200 | \r | |
201 | } |