]>
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
.Project
;
20 import org
.w3c
.dom
.Document
;
21 import org
.w3c
.dom
.Element
;
22 import org
.w3c
.dom
.Node
;
25 <p><code>FileProcess</code> is class to generate ANT script to build source
28 <p>If file does not specify file type, <code>FileProcess</code> will judge
29 by its extension. Following is the current supported extensions. </p>
34 .s | IPF_Assembly_Code
40 .dxs | Dependency_File
47 public class FileProcess
{
49 /// The mapping information about source suffix, result suffix, file type.
51 public final String
[][] fileTypes
= { { ".c", ".obj", "C_Code" }, { ".asm", ".obj", "Assembly" },
52 { ".s", ".obj", "IPF_Assembly_Code" }, { ".h", "", "Header" },
53 { ".lib", "", "Static_Library" }, { ".src", ".c", "" },
54 { ".i", ".obj", "IPF_PP_Code" }, { ".vfr", ".obj", "Vfr" },
55 { ".uni", "", "Unicode" }, { ".dxs", "", "Dependency_File" },
56 { ".bmp", "", "Graphics" }, { ".efi", "", "EFI" } };
59 /// Current ANT context.
61 private Project project
;
64 /// Current module's include pathes
66 private Set
<String
> includes
;
69 /// Current source files.
71 private Set
<String
> sourceFiles
;
76 private Document document
;
79 /// The flag to ensure all unicode files build before others.
81 private boolean unicodeFirst
= true;
84 /// The flag present whether current module contains Unicode files or not.
86 private boolean unicodeExist
= false;
89 Initialize the project, includes, sourceFiles, document members.
91 @param project ANT project
92 @param includes Module include pathes
93 @param sourceFiles Modules source files
94 @param document XML document
96 public void init(Project project
, Set
<String
> includes
, Set
<String
> sourceFiles
, Document document
) {
97 this.document
= document
;
98 this.includes
= includes
;
99 this.project
= project
;
100 this.sourceFiles
= sourceFiles
;
104 Parse file without file type.
106 @param filename Source file name
107 @param root Root node
108 @param unicodeFirst whether build Unicode file firstly or not
110 public synchronized void parseFile(String filename
, Node root
, boolean unicodeFirst
) {
111 this.unicodeFirst
= unicodeFirst
;
112 parseFile(filename
, root
);
116 Get whether current module contains Unicode files or not.
118 @return Whether current module contains Unicode files or not
120 public boolean isUnicodeExist() {
127 @param filename Source file name
128 @param filetype Source file type
129 @param root Root node
130 @param unicodeFirst whether build Unicode file firstly or not
132 public synchronized void parseFile(String filename
, String filetype
, Node root
, boolean unicodeFirst
) {
133 this.unicodeFirst
= unicodeFirst
;
134 parseFile(filename
, filetype
, root
);
138 Find out source file's type.
140 @param filename Source file name
141 @param root Root node
143 public synchronized void parseFile(String filename
, Node root
) {
144 boolean flag
= false;
145 for (int i
= 0; i
< fileTypes
.length
; i
++) {
146 if (filename
.toLowerCase().endsWith(fileTypes
[i
][0])) {
148 parseFile(filename
, fileTypes
[i
][2], root
);
152 System
.out
.println("Warning: File " + filename
+ " is not known from its suffix.");
157 Parse file. If flag <code>unicodeFirst</code> is true, then build all
158 unicode files firstly.
160 <p>Note that AutoGen.c is processed specially. It's output path is always
161 <code>${DEST_DIR_OUTPUT}</code>, others are <code>${DEST_DIR_OUTPUT}</code>
162 and relative to module path. </p>
164 @param filename Source file name
165 @param filetype Source file type
166 @param root Root node
168 public synchronized void parseFile(String filename
, String filetype
, Node root
) {
170 if ( ! filetype
.equalsIgnoreCase("Unicode")){
175 if (filetype
.equalsIgnoreCase("Unicode")){
179 sourceFiles
.add(filename
);
180 if (filetype
.equalsIgnoreCase("Header")) {
183 if (filetype
.equalsIgnoreCase("IPF_PP_Code")) {
186 String module_path
= project
.getProperty("MODULE_DIR");
187 File moduleFile
= new File(module_path
);
188 File sourceFile
= new File(filename
);
189 // If source file is AutoGen.c, then Filepath is .
190 String sourceFilepath
;
191 String sourceFilename
;
192 if (sourceFile
.getPath().endsWith("AutoGen.c")) {
193 sourceFilepath
= ".";
194 sourceFilename
= "AutoGen";
195 filetype
= "AUTOGEN";
198 String str
= sourceFile
.getPath().substring(moduleFile
.getPath().length() + 1);
199 int index
= str
.lastIndexOf(File
.separatorChar
);
200 sourceFilepath
= ".";
202 sourceFilepath
= str
.substring(0, index
);
203 str
= str
.substring(index
+ 1);
205 sourceFilename
= str
;
206 index
= str
.lastIndexOf('.');
208 sourceFilename
= str
.substring(0, index
);
211 // <Build_filetype FILEPATH="" FILENAME="" />
212 Element ele
= document
.createElement("Build_" + filetype
);
213 ele
.setAttribute("FILEPATH", sourceFilepath
);
214 ele
.setAttribute("FILENAME", sourceFilename
);
215 String
[] includePaths
= includes
.toArray(new String
[includes
.size()]);
216 Element includesEle
= document
.createElement("EXTRA.INC");
217 for (int i
= 0; i
< includePaths
.length
; i
++) {
218 Element includeEle
= document
.createElement("includepath");
219 includeEle
.setAttribute("path", includePaths
[i
]);
220 includesEle
.appendChild(includeEle
);
222 ele
.appendChild(includesEle
);
223 root
.appendChild(ele
);