2 This file is to define an ANT task which wraps VfrCompile.exe tool
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 package org
.tianocore
.framework
.tasks
;
17 import java
.io
.IOException
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.apache
.tools
.ant
.BuildException
;
22 import org
.apache
.tools
.ant
.Project
;
23 import org
.apache
.tools
.ant
.Task
;
24 import org
.apache
.tools
.ant
.taskdefs
.Execute
;
25 import org
.apache
.tools
.ant
.taskdefs
.LogStreamHandler
;
26 import org
.apache
.tools
.ant
.types
.Commandline
;
29 VfrcompilerTask Task Class
31 -createListFile : create an output IFR listing file.
32 -outPutDir : deposit all output files to directory OutputDir (default=cwd)
33 -createIfrBinFile: create an IFR HII pack file
34 -vfrFile : name of the input VFR script file
35 -processArg : c processer argument
36 -includepathList : add IncPath to the search path for VFR included files
38 public class VfrCompilerTask
extends Task
implements EfiDefine
{
39 private String createListFile
= "";
40 private String outPutDir
= "";
41 private String createIfrBinFile
= "";
42 private String processerArg
="";
43 private String vfrFile
= "";
44 private String vfrFileName
= "";
46 private List
<Object
> includepathList
= new ArrayList
<Object
>();
49 get class member of createList file
51 @returns file name of createList
53 public String
getCreateListFile() {
54 return createListFile
;
58 set class member of createList file
60 @param createListFile if createList string equal "on" set '-l' flag
62 public void setCreateListFile(String createListFile
) {
63 if (createListFile
.equals("ON")||createListFile
.equals("on"))
64 this.createListFile
= " -l";
70 @returns name of output dir
72 public String
getOutPutDir() {
77 set class member of outPutDir
79 @param outPutDir The directory name for ouput file
81 public void setOutPutDir(String outPutDir
) {
82 this.outPutDir
= " -od " + outPutDir
;
87 get class member of ifrBinFile
89 @return file name of ifrBinFile
91 public String
getCreateIfrBinFile() {
92 return createIfrBinFile
;
96 set class member of ifrBinFile
98 @param createIfrBinFile The flag to specify if the IFR binary file should
101 public void setCreateIfrBinFile(String createIfrBinFile
) {
102 if (createIfrBinFile
.equals("ON") || createIfrBinFile
.equals("on"));
103 this.createIfrBinFile
= " -ibin";
107 get class member of vfrFile
109 @returns name of vfrFile
111 public String
getVfrFile() {
116 set class member of vfrFile
118 @param vfrFile The name of VFR file
120 public void setVfrFile(String vfrFile
) {
121 this.vfrFileName
= (new File(vfrFile
)).getName();
122 this.vfrFile
= " " + vfrFile
;
126 add includePath in includepath List
128 @param includepath The IncludePath object which represents include path
130 public void addIncludepath(IncludePath includepath
){
131 includepathList
.add(includepath
);
136 get class member of processerArg
138 @returns processer argument
140 public String
getProcesserArg() {
146 set class member of processerArg
148 @param processerArg The processor argument
150 public void setProcesserArg(String processerArg
) {
151 this.processerArg
= " -ppflag " + processerArg
;
155 The standard execute method of ANT task.
157 public void execute() throws BuildException
{
158 Project project
= this.getProject();
159 String toolPath
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
161 if (toolPath
== null) {
162 command
= "VfrCompile";
164 command
= toolPath
+ "/" + "VfrCompile";
166 List
<Object
> includePath
= new ArrayList
<Object
>();
169 int count
= includepathList
.size();
171 for (int i
= 0; i
< count
; i
++) {
172 path
= (IncludePath
) includepathList
.get(i
);
173 if (path
.getFile() != null) {
174 FileParser
.loadFile( project
,includePath
,path
.getFile(), "-I");
177 for (int i
= 0; i
< count
; i
++) {
178 incPath
= incPath
+ " " + includepathList
.get(i
);
180 count
= includePath
.size();
181 for (int i
= 0; i
< count
; i
++) {
182 incPath
= incPath
+ " " + includePath
.get(i
);
184 String argument
= this.createIfrBinFile
+
188 this.createListFile
+
192 /// constructs the command-line
194 Commandline commandLine
= new Commandline();
195 commandLine
.setExecutable(command
);
196 commandLine
.createArgument().setLine(argument
);
199 /// configures the Execute object
201 LogStreamHandler streamHandler
= new LogStreamHandler(this,
205 Execute runner
= new Execute(streamHandler
,null);
206 runner
.setAntRun(project
);
207 runner
.setCommandline(commandLine
.getCommandline());
209 log(Commandline
.toString(commandLine
.getCommandline()), Project
.MSG_VERBOSE
);
211 int returnVal
= runner
.execute();
212 if (EFI_SUCCESS
== returnVal
) {
213 log("VfrCompiler succeeded!", Project
.MSG_VERBOSE
);
215 log("ERROR = " + Integer
.toHexString(returnVal
));
216 throw new BuildException("VfrCompiler failed!");
218 } catch (IOException e
) {
219 throw new BuildException(e
.getMessage());