]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/FileProcess.java
2 File is FileProcess class which is used to generate ANT script to build
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 package org
.tianocore
.build
;
19 import org
.apache
.tools
.ant
.BuildException
;
20 import org
.apache
.tools
.ant
.Project
;
21 import org
.w3c
.dom
.Document
;
22 import org
.w3c
.dom
.Element
;
23 import org
.w3c
.dom
.Node
;
26 <p><code>FileProcess</code> is class to generate ANT script to build source
29 <p>If file does not specify file type, <code>FileProcess</code> will judge
30 by its extension. Following is the current supported extensions. </p>
33 Source File Suffix File Type Description
34 .h CHeader C header file
35 .c CCode C source file
36 .inc ASMHeader Assembly header file
37 .asm ASM Assembly source file, usually for IA32 and X64 Arch and MSFT tool chain
38 .S ASM Assembly source file, usually for IPF Arch
39 .s ASM Assembly source file, usually for IA32 and X64 Arch and GCC tool chain
41 .vfr VFR Visual Forms Representation File
42 .fv FV Firmware Volume
43 .SEC FFS Firmware File System file
44 .PEI FFS Firmware File System file
45 .DXE FFS Firmware File System file
46 .APP FFS Firmware File System file
47 .FVI FFS Firmware File System file
48 .FFS FFS Firmware File System file
50 .i PPCode IPF PreProcessor Code
55 public class FileProcess
{
57 /// The mapping information about source suffix, result suffix, file type.
59 public final String
[][] fileTypes
= { {".h", "", "CHeader" },
61 {".inc", "", "ASMHeader" },
77 {".i", "", "PPCode"}};
79 /// Current ANT context.
81 private Project project
;
84 /// Current module's include pathes
86 private Set
<String
> includes
;
91 private Document document
;
94 /// The flag to ensure all unicode files build before others.
96 private boolean unicodeFirst
= true;
99 /// The flag present whether current module contains Unicode files or not.
101 private boolean unicodeExist
= false;
104 Initialize the project, includes, sourceFiles, document members.
106 @param project ANT project
107 @param includes Module include pathes
108 @param sourceFiles Modules source files
109 @param document XML document
111 public void init(Project project
, Set
<String
> includes
, Document document
) {
112 this.document
= document
;
113 this.includes
= includes
;
114 this.project
= project
;
118 Parse file without file type.
120 @param filename Source file name
121 @param root Root node
122 @param unicodeFirst whether build Unicode file firstly or not
124 public synchronized void parseFile(String filename
, Node root
, boolean unicodeFirst
) {
125 this.unicodeFirst
= unicodeFirst
;
126 parseFile(filename
, root
);
130 Get whether current module contains Unicode files or not.
132 @return Whether current module contains Unicode files or not
134 public boolean isUnicodeExist() {
141 @param filename Source file name
142 @param filetype Source file type
143 @param root Root node
144 @param unicodeFirst whether build Unicode file firstly or not
146 public synchronized void parseFile(String filename
, String filetype
, Node root
, boolean unicodeFirst
) {
147 this.unicodeFirst
= unicodeFirst
;
148 parseFile(filename
, filetype
, root
);
152 Find out source file's type.
154 @param filename Source file name
155 @param root Root node
157 public synchronized void parseFile(String filename
, Node root
) throws BuildException
{
158 boolean flag
= false;
159 for (int i
= 0; i
< fileTypes
.length
; i
++) {
160 if (filename
.endsWith(fileTypes
[i
][0])) {
162 parseFile(filename
, fileTypes
[i
][2], root
);
166 throw new BuildException("File [" + filename
+ "] is not known from its suffix.");
171 Parse file. If flag <code>unicodeFirst</code> is true, then build all
172 unicode files firstly.
174 <p>Note that AutoGen.c is processed specially. It's output path is always
175 <code>${DEST_DIR_OUTPUT}</code>, others are <code>${DEST_DIR_OUTPUT}</code>
176 and relative to module path. </p>
178 @param filename Source file name
179 @param filetype Source file type
180 @param root Root node
182 public synchronized void parseFile(String filename
, String filetype
, Node root
) {
184 if ( ! filetype
.equalsIgnoreCase("UNI")){
189 if (filetype
.equalsIgnoreCase("UNI")){
195 // If file is C or ASM header file, skip it
197 if (filetype
.equalsIgnoreCase("CHeader") || filetype
.equalsIgnoreCase("ASMHeader")) {
202 // If file is pre-processor file, skip it
204 if (filetype
.equalsIgnoreCase("PPCode")) {
209 // If define CC_EXT in tools_def.txt file, the source file with
210 // different suffix is skipped
212 String toolsDefExtName
= project
.getProperty(filetype
+ "_EXT");
213 if (toolsDefExtName
!= null) {
214 String
[] exts
= toolsDefExtName
.split(" ");
215 for (int i
= 0; i
< exts
.length
; i
++) {
216 if ( ! filename
.endsWith(exts
[i
])) {
222 String module_path
= project
.getProperty("MODULE_DIR");
223 File moduleFile
= new File(module_path
);
224 File sourceFile
= new File(filename
);
227 // If source file is AutoGen.c, then Filepath is .
229 String sourceFilepath
= "";
230 String sourceFilename
= "";
231 String sourceFileext
= "";
232 if (sourceFile
.getPath().endsWith("AutoGen.c")) {
233 sourceFilepath
= ".";
234 sourceFilename
= "AutoGen";
235 sourceFileext
= ".c";
236 filetype
= "AUTOGEN";
239 String str
= sourceFile
.getPath().substring(moduleFile
.getPath().length() + 1);
240 int index
= str
.lastIndexOf(File
.separatorChar
);
241 sourceFilepath
= ".";
243 sourceFilepath
= str
.substring(0, index
);
244 str
= str
.substring(index
+ 1);
246 sourceFilename
= str
;
247 index
= str
.lastIndexOf('.');
249 sourceFilename
= str
.substring(0, index
);
250 sourceFileext
= str
.substring(index
);
253 // <Build_filetype FILEPATH="" FILENAME="" />
254 Element ele
= document
.createElement("Build_" + filetype
);
255 ele
.setAttribute("FILEPATH", sourceFilepath
);
256 ele
.setAttribute("FILENAME", sourceFilename
);
257 ele
.setAttribute("FILEEXT", sourceFileext
.substring(1));
258 String
[] includePaths
= includes
.toArray(new String
[includes
.size()]);
259 Element includesEle
= document
.createElement("EXTRA.INC");
260 for (int i
= 0; i
< includePaths
.length
; i
++) {
261 Element includeEle
= document
.createElement("includepath");
262 includeEle
.setAttribute("path", includePaths
[i
]);
263 includesEle
.appendChild(includeEle
);
265 ele
.appendChild(includesEle
);
266 root
.appendChild(ele
);