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
;
16 import java
.io
.IOException
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
20 import org
.apache
.tools
.ant
.BuildException
;
21 import org
.apache
.tools
.ant
.Project
;
22 import org
.apache
.tools
.ant
.Task
;
23 import org
.apache
.tools
.ant
.taskdefs
.Execute
;
24 import org
.apache
.tools
.ant
.taskdefs
.LogStreamHandler
;
25 import org
.apache
.tools
.ant
.types
.Commandline
;
28 VfrcompilerTask Task Class
30 -createListFile : create an output IFR listing file.
31 -outPutDir : deposit all output files to directory OutputDir (default=cwd)
32 -createIfrBinFile: create an IFR HII pack file
33 -vfrFile : name of the input VFR script file
34 -processArg : c processer argument
35 -includepathList : add IncPath to the search path for VFR included files
37 public class VfrCompilerTask
extends Task
implements EfiDefine
{
38 private String createListFile
= "";
39 private String outPutDir
= "";
40 private String createIfrBinFile
= "";
41 private String processerArg
="";
42 private String vfrFile
;
44 private List
<Object
> includepathList
= new ArrayList
<Object
>();
47 get class member of createList file
49 @returns file name of createList
51 public String
getCreateListFile() {
52 return createListFile
;
56 set class member of createList file
58 @param createListFile if createList string equal "on" set '-l' flag
60 public void setCreateListFile(String createListFile
) {
61 if (createListFile
.equals("ON")||createListFile
.equals("on"))
62 this.createListFile
= " -l";
68 @returns name of output dir
70 public String
getOutPutDir() {
75 set class member of outPutDir
77 @param outPutDir The directory name for ouput file
79 public void setOutPutDir(String outPutDir
) {
80 this.outPutDir
= " -od " + outPutDir
;
85 get class member of ifrBinFile
87 @return file name of ifrBinFile
89 public String
getCreateIfrBinFile() {
90 return createIfrBinFile
;
94 set class member of ifrBinFile
96 @param createIfrBinFile The flag to specify if the IFR binary file should
99 public void setCreateIfrBinFile(String createIfrBinFile
) {
100 if (createIfrBinFile
.equals("ON") || createIfrBinFile
.equals("on"));
101 this.createIfrBinFile
= " -ibin";
105 get class member of vfrFile
107 @returns name of vfrFile
109 public String
getVfrFile() {
114 set class member of vfrFile
116 @param vfrFile The name of VFR file
118 public void setVfrFile(String vfrFile
) {
119 this.vfrFile
= " " + vfrFile
;
123 add includePath in includepath List
125 @param includepath The IncludePath object which represents include path
127 public void addIncludepath(IncludePath includepath
){
128 includepathList
.add(includepath
);
133 get class member of processerArg
135 @returns processer argument
137 public String
getProcesserArg() {
143 set class member of processerArg
145 @param processerArg The processor argument
147 public void setProcesserArg(String processerArg
) {
148 this.processerArg
= " -ppflag " + processerArg
;
152 The standard execute method of ANT task.
154 public void execute() throws BuildException
{
155 Project project
= this.getProject();
156 String toolPath
= project
.getProperty("env.Framework_Tools_Path");
158 if (toolPath
== null) {
159 command
= "VfrCompile";
161 command
= toolPath
+ "/" + "VfrCompile";
163 List
<Object
> includePath
= new ArrayList
<Object
>();
166 int count
= includepathList
.size();
168 for (int i
= 0; i
< count
; i
++) {
169 path
= (IncludePath
) includepathList
.get(i
);
170 if (path
.getFile() != null) {
171 FileParser
.loadFile( project
,includePath
,path
.getFile(), "-I");
174 for (int i
= 0; i
< count
; i
++) {
175 incPath
= incPath
+ " " + includepathList
.get(i
);
177 count
= includePath
.size();
178 for (int i
= 0; i
< count
; i
++) {
179 incPath
= incPath
+ " " + includePath
.get(i
);
181 String argument
= this.createIfrBinFile
+
185 this.createListFile
+
189 /// constructs the command-line
191 Commandline commandLine
= new Commandline();
192 commandLine
.setExecutable(command
);
193 commandLine
.createArgument().setLine(argument
);
196 /// configures the Execute object
198 LogStreamHandler streamHandler
= new LogStreamHandler(this,
202 Execute runner
= new Execute(streamHandler
,null);
203 runner
.setAntRun(project
);
204 runner
.setCommandline(commandLine
.getCommandline());
206 System
.out
.println(Commandline
.toString(commandLine
.getCommandline()));
207 int returnVal
= runner
.execute();
208 if (EFI_SUCCESS
== returnVal
) {
209 System
.out
.println("VfrCompiler execution succeeded!");
211 System
.out
.println("VfrCompiler failed. (error=" +
212 Integer
.toHexString(returnVal
) + ")");
213 throw new BuildException("VfrCompiler failed. (error=" +
214 Integer
.toHexString(returnVal
) + ")");
217 } catch (IOException e
) {
218 throw new BuildException(e
.getMessage());