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 File outPutFile
;
42 private String createIfrBinFile
= "";
43 private String processerArg
="";
44 private String vfrFile
= "";
45 private String vfrFileName
= "";
47 private List
<IncludePath
> includepathList
= new ArrayList
<IncludePath
>();
50 get class member of createList file
52 @returns file name of createList
54 public String
getCreateListFile() {
55 return createListFile
;
59 set class member of createList file
61 @param createListFile if createList string equal "on" set '-l' flag
63 public void setCreateListFile(String createListFile
) {
64 if (createListFile
.equals("ON")||createListFile
.equals("on"))
65 this.createListFile
= " -l";
71 @returns name of output dir
73 public String
getOutPutDir() {
78 set class member of outPutDir
80 @param outPutDir The directory name for ouput file
82 public void setOutPutDir(String outPutDir
) {
83 if (outPutDir
!= null) {
84 outPutFile
= new File(outPutDir
);
86 this.outPutDir
= " -od " + outPutDir
;
91 get class member of ifrBinFile
93 @return file name of ifrBinFile
95 public String
getCreateIfrBinFile() {
96 return createIfrBinFile
;
100 set class member of ifrBinFile
102 @param createIfrBinFile The flag to specify if the IFR binary file should
105 public void setCreateIfrBinFile(String createIfrBinFile
) {
106 if (createIfrBinFile
.equals("ON") || createIfrBinFile
.equals("on"));
107 this.createIfrBinFile
= " -ibin";
111 get class member of vfrFile
113 @returns name of vfrFile
115 public String
getVfrFile() {
120 set class member of vfrFile
122 @param vfrFile The name of VFR file
124 public void setVfrFile(String vfrFile
) {
125 this.vfrFileName
= (new File(vfrFile
)).getName();
126 this.vfrFile
= " " + vfrFile
;
130 add includePath in includepath List
132 @param includepath The IncludePath object which represents include path
134 public void addIncludepath(IncludePath includepath
){
135 includepathList
.add(includepath
);
140 get class member of processerArg
142 @returns processer argument
144 public String
getProcesserArg() {
150 set class member of processerArg
152 @param processerArg The processor argument
154 public void setProcesserArg(String processerArg
) {
155 this.processerArg
= " -ppflag " + processerArg
;
159 The standard execute method of ANT task.
161 public void execute() throws BuildException
{
162 Project project
= this.getProject();
163 String toolPath
= project
.getProperty("env.FRAMEWORK_TOOLS_PATH");
165 if (toolPath
== null) {
166 command
= "VfrCompile";
168 command
= toolPath
+ "/" + "VfrCompile";
170 List
<Object
> includePath
= new ArrayList
<Object
>();
173 int count
= includepathList
.size();
174 for (int i
= 0; i
< count
; i
++) {
175 incPath
+= includepathList
.get(i
).toString();
178 String argument
= this.createIfrBinFile
+
182 this.createListFile
+
186 /// constructs the command-line
188 Commandline commandLine
= new Commandline();
189 commandLine
.setExecutable(command
);
190 commandLine
.createArgument().setLine(argument
);
193 /// configures the Execute object
195 LogStreamHandler streamHandler
= new LogStreamHandler(this,
199 Execute runner
= new Execute(streamHandler
,null);
200 runner
.setAntRun(project
);
202 runner
.setCommandline(commandLine
.getCommandline());
204 if (outPutFile
!= null && outPutFile
.exists()) {
205 runner
.setWorkingDirectory(outPutFile
);
208 log(Commandline
.toString(commandLine
.getCommandline()), Project
.MSG_VERBOSE
);
210 int returnVal
= runner
.execute();
211 if (EFI_SUCCESS
== returnVal
) {
212 log("VfrCompile succeeded!", Project
.MSG_VERBOSE
);
214 log("ERROR = " + Integer
.toHexString(returnVal
));
215 throw new BuildException("VfrCompile failed!");
217 } catch (IOException e
) {
218 throw new BuildException(e
.getMessage());