]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/FileProcess.java
e0a0fff2d528efb5319151d5925047b47f521df9
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" },
78 {".i", "", "PPCode"}};
80 /// Current ANT context.
82 private Project project
;
85 /// Current module's include pathes
87 private Set
<String
> includes
;
92 private Document document
;
95 /// The flag to ensure all unicode files build before others.
97 private boolean unicodeFirst
= true;
100 /// The flag present whether current module contains Unicode files or not.
102 private boolean unicodeExist
= false;
105 Initialize the project, includes, sourceFiles, document members.
107 @param project ANT project
108 @param includes Module include pathes
109 @param sourceFiles Modules source files
110 @param document XML document
112 public void init(Project project
, Set
<String
> includes
, Document document
) {
113 this.document
= document
;
114 this.includes
= includes
;
115 this.project
= project
;
119 Parse file without file type.
121 @param filename Source file name
122 @param root Root node
123 @param unicodeFirst whether build Unicode file firstly or not
125 public synchronized void parseFile(String filename
, Node root
, boolean unicodeFirst
) {
126 this.unicodeFirst
= unicodeFirst
;
127 parseFile(filename
, root
);
131 Get whether current module contains Unicode files or not.
133 @return Whether current module contains Unicode files or not
135 public boolean isUnicodeExist() {
142 @param filename Source file name
143 @param filetype Source file type
144 @param root Root node
145 @param unicodeFirst whether build Unicode file firstly or not
147 public synchronized void parseFile(String filename
, String filetype
, Node root
, boolean unicodeFirst
) {
148 this.unicodeFirst
= unicodeFirst
;
149 parseFile(filename
, filetype
, root
);
153 Find out source file's type.
155 @param filename Source file name
156 @param root Root node
158 public synchronized void parseFile(String filename
, Node root
) throws BuildException
{
159 boolean flag
= false;
160 for (int i
= 0; i
< fileTypes
.length
; i
++) {
161 if (filename
.endsWith(fileTypes
[i
][0])) {
163 parseFile(filename
, fileTypes
[i
][2], root
);
167 throw new BuildException("File [" + filename
+ "] is not known from its suffix.");
172 Parse file. If flag <code>unicodeFirst</code> is true, then build all
173 unicode files firstly.
175 <p>Note that AutoGen.c is processed specially. It's output path is always
176 <code>${DEST_DIR_OUTPUT}</code>, others are <code>${DEST_DIR_OUTPUT}</code>
177 and relative to module path. </p>
179 @param filename Source file name
180 @param filetype Source file type
181 @param root Root node
183 public synchronized void parseFile(String filename
, String filetype
, Node root
) {
185 if ( ! filetype
.equalsIgnoreCase("UNI")){
190 if (filetype
.equalsIgnoreCase("UNI")){
196 // If file is C or ASM header file, skip it
198 if (filetype
.equalsIgnoreCase("CHeader") || filetype
.equalsIgnoreCase("ASMHeader")) {
203 // If file is pre-processor file, skip it
205 if (filetype
.equalsIgnoreCase("PPCode")) {
210 // If define CC_EXT in tools_def.txt file, the source file with
211 // different suffix is skipped
213 String toolsDefExtName
= project
.getProperty(filetype
+ "_EXT");
214 if (toolsDefExtName
!= null) {
215 String
[] exts
= toolsDefExtName
.split(" ");
216 for (int i
= 0; i
< exts
.length
; i
++) {
217 if ( ! filename
.endsWith(exts
[i
])) {
223 String module_path
= project
.getProperty("MODULE_DIR");
224 File moduleFile
= new File(module_path
);
225 File sourceFile
= new File(filename
);
228 // If source file is AutoGen.c, then Filepath is .
230 String sourceFilepath
= "";
231 String sourceFilename
= "";
232 String sourceFileext
= "";
233 if (sourceFile
.getPath().endsWith("AutoGen.c")) {
234 sourceFilepath
= ".";
235 sourceFilename
= "AutoGen";
236 sourceFileext
= ".c";
237 filetype
= "AUTOGEN";
240 String str
= sourceFile
.getPath().substring(moduleFile
.getPath().length() + 1);
241 int index
= str
.lastIndexOf(File
.separatorChar
);
242 sourceFilepath
= ".";
244 sourceFilepath
= str
.substring(0, index
);
245 str
= str
.substring(index
+ 1);
247 sourceFilename
= str
;
248 index
= str
.lastIndexOf('.');
250 sourceFilename
= str
.substring(0, index
);
251 sourceFileext
= str
.substring(index
);
254 // <Build_filetype FILEPATH="" FILENAME="" />
255 Element ele
= document
.createElement("Build_" + filetype
);
256 ele
.setAttribute("FILEPATH", sourceFilepath
);
257 ele
.setAttribute("FILENAME", sourceFilename
);
258 ele
.setAttribute("FILEEXT", sourceFileext
.substring(1));
259 String
[] includePaths
= includes
.toArray(new String
[includes
.size()]);
260 Element includesEle
= document
.createElement("EXTRA.INC");
261 for (int i
= 0; i
< includePaths
.length
; i
++) {
262 Element includeEle
= document
.createElement("includepath");
263 includeEle
.setAttribute("path", includePaths
[i
]);
264 includesEle
.appendChild(includeEle
);
266 ele
.appendChild(includesEle
);
267 root
.appendChild(ele
);