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
<Object
> includepathList
= new ArrayList
<Object
>();
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();
175 for (int i
= 0; i
< count
; i
++) {
176 path
= (IncludePath
) includepathList
.get(i
);
177 if (path
.getFile() != null) {
178 FileParser
.loadFile( project
,includePath
,path
.getFile(), "-I");
181 for (int i
= 0; i
< count
; i
++) {
182 incPath
= incPath
+ " " + includepathList
.get(i
);
184 count
= includePath
.size();
185 for (int i
= 0; i
< count
; i
++) {
186 incPath
= incPath
+ " " + includePath
.get(i
);
188 String argument
= this.createIfrBinFile
+
192 this.createListFile
+
196 /// constructs the command-line
198 Commandline commandLine
= new Commandline();
199 commandLine
.setExecutable(command
);
200 commandLine
.createArgument().setLine(argument
);
203 /// configures the Execute object
205 LogStreamHandler streamHandler
= new LogStreamHandler(this,
209 Execute runner
= new Execute(streamHandler
,null);
210 runner
.setAntRun(project
);
212 runner
.setCommandline(commandLine
.getCommandline());
214 if (outPutFile
!= null && outPutFile
.exists()) {
215 runner
.setWorkingDirectory(outPutFile
);
218 log(Commandline
.toString(commandLine
.getCommandline()), Project
.MSG_VERBOSE
);
220 int returnVal
= runner
.execute();
221 if (EFI_SUCCESS
== returnVal
) {
222 log("VfrCompile succeeded!", Project
.MSG_VERBOSE
);
224 log("ERROR = " + Integer
.toHexString(returnVal
));
225 throw new BuildException("VfrCompile failed!");
227 } catch (IOException e
) {
228 throw new BuildException(e
.getMessage());