]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/OutputManager.java
01e24e653f1ed915c33a6e74fc10082a5bdd39c2
[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
20 /**
21 OutputManager class is used to setup output directories (BIN_DIR, DEST_DIR_OUTPUT,
22 DEST_DIR_DEBUG) according to BUILD_MODE.
23
24 @since GenBuild 1.0
25 **/
26 public class OutputManager {
27
28 ///
29 /// Single Module build
30 ///
31 public static final String MODULE_BUILD = "MODULE";
32
33 ///
34 /// Package build
35 ///
36 public static final String PACKAGE_BUILD = "PACKAGE";
37
38 ///
39 /// Platform build
40 ///
41 public static final String PLATFORM_BUILD = "PLATFORM";
42
43 public static String buildMode = MODULE_BUILD;
44
45 ///
46 /// For Package build, PLATFORM represent PACKAGE
47 ///
48 public static String PLATFORM;
49
50 ///
51 /// For Platform build, PLATFORM_DIR represent PACKAGE_DIR
52 ///
53 public static String PLATFORM_DIR;
54
55 ///
56 /// means intermediate files will put under Module's dir
57 ///
58 public static final String MODULE = "MODULE";
59
60 ///
61 /// mean intermediate files will put under a unify dir
62 ///
63 public static final String UNIFIED = "UNIFIED";
64
65 ///
66 /// Flag to ensure the function <code>update</code> will be called only one in the whole build.
67 ///
68 private static boolean flag = true;
69
70 /**
71 If BUILD_MODE is PLATFORM or PACKAGE, record PLATFORM and PLARFORM_DIR.
72 Reminder that for PACKAGE build, here set value PACKAGE to PLATFORM and
73 PACKAGE_DIR to PLARFORM_DIR, and also update the ant properties.
74
75 <p>Note that this function will be called only once in the whole build.</p>
76
77 @param project current ANT build Project
78 **/
79 public synchronized static void update(Project project) {
80 if (flag){
81 flag = false;
82 String str = project.getProperty("BUILD_MODE");
83 if (str != null){
84 if (str.equals(PLATFORM_BUILD)) {
85 buildMode = PLATFORM_BUILD;
86 PLATFORM = project.getProperty("PLATFORM");
87 PLATFORM_DIR = project.getProperty("PLATFORM_DIR");
88 }
89 else if (str.equals(PACKAGE_BUILD)) {
90 buildMode = PACKAGE_BUILD;
91 PLATFORM = project.getProperty("PACKAGE");
92 PLATFORM_DIR = project.getProperty("PACKAGE_DIR");
93 project.setProperty("PLATFORM", PLATFORM);
94 project.setProperty("PLATFORM_DIR", PLATFORM_DIR);
95 }
96 }
97 }
98 }
99
100 /**
101 Setup BIN_DIR, DEST_DIR_OUTPUT and DEST_DIR_OUTPUT, following are the rules:
102
103 <pre>
104 Those three variables are defined as following
105 DEST_DIR_OUTPUT (intermediate files)
106 DEST_DIR_DEBUG (intermediate debug files)
107 BIN_DIR (final files)
108
109 Output Dir (MODULE or UNIFIED):
110 For <b>Module</b> build:
111 All intermediate files are at ${MODULE_DIR}/Build/${TARGET}/${ARCH}/DEBUG|OUTPUT
112 All final files are at ${MODULE_DIR}/Build/${TARGET}/${ARCH}
113
114 For <b>Platform</b> build:
115 If specified with MODULE
116 Intermediate files->${MODULE_DIR}/Build/${PLATFORM}/${TARGET}/${ARCH}/DEBUG|OUTPUT
117 Final files -> ${PLARFORM_DIR}/Build/${TARGET}/${ARCH}
118
119 Else if specified with UNIFIED
120 Intermediate files->${PLARFORM_DIR}/Build/${TARGET}/${ARCH}/${PACKAGE}/${SOURCE_RELATIVE_PATH}/DEBUG|OUTPUT
121 Final files -> ${PLARFORM_DIR}/Build/${TARGET}/${ARCH}
122
123 For <b>Package</b> build:
124 If specified with MODULE
125 Intermediate files->${MODULE_DIR}/Build/${PACKAGE}/${TARGET}/${ARCH}/DEBUG|OUTPUT
126 Final files -> ${PACKAGE_DIR}/Build/${TARGET}/${ARCH}
127
128 Else if specified with UNIFIED
129 Intermediate files->${PACKAGE_DIR}/Build/${TARGET}/${ARCH}/${PACKAGE}/${SOURCE_RELATIVE_PATH}/DEBUG|OUTPUT
130 Final files -> ${PACKAGE_DIR}/Build/${TARGET}/${ARCH}
131 </pre>
132
133 @param project current ANT build Project
134 @param userdir user-defined directory
135 @param type the module build type (MODULE or UNIFIED)
136 **/
137 public synchronized static void update(Project project, String userdir, String type) {
138 //
139 // userdir TBD
140 //
141 if( type == null || ! type.equals(MODULE)){
142 type = UNIFIED;
143 }
144 if (buildMode.equals(MODULE_BUILD)){
145 project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${MODULE_DIR}"
146 + File.separatorChar + "Build" + File.separatorChar + "${TARGET}"
147 + File.separatorChar + "${ARCH}" + File.separatorChar + "OUTPUT"));
148 project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "DEBUG"));
149 project.setProperty("BIN_DIR", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));
150 }
151 else if (buildMode.equals(PLATFORM_BUILD)) {
152 if (type.equals(MODULE)) {
153 project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "OUTPUT"));
154 project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "DEBUG"));
155 project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));
156 }
157 else if (type.equals(UNIFIED)){
158 project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "OUTPUT"));
159 project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "DEBUG"));
160 project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));
161 }
162 }
163 else if (buildMode.equals(PACKAGE_BUILD)) {
164 if (type.equals(MODULE)) {
165 project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "OUTPUT"));
166 project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${MODULE_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${PLATFORM}" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "DEBUG"));
167 project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));
168 }
169 else if (type.equals(UNIFIED)){
170 project.setProperty("DEST_DIR_OUTPUT", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "OUTPUT"));
171 project.setProperty("DEST_DIR_DEBUG", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}" + File.separatorChar + "${PACKAGE}" + File.separatorChar + "${MODULE_RELATIVE_PATH}" + File.separatorChar + "DEBUG"));
172 project.setProperty("BIN_DIR", project.replaceProperties("${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "${TARGET}" + File.separatorChar + "${ARCH}"));
173 }
174 }
175 }
176 }