2 This file is to define an ANT task which wraps VfrCompile.exe tool
\r
4 Copyright (c) 2006, Intel Corporation
\r
5 All rights reserved. This program and the accompanying materials
\r
6 are licensed and made available under the terms and conditions of the BSD License
\r
7 which accompanies this distribution. The full text of the license may be found at
\r
8 http://opensource.org/licenses/bsd-license.php
\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
14 package org.tianocore.framework.tasks;
\r
16 import java.io.File;
\r
17 import java.io.IOException;
\r
18 import java.util.ArrayList;
\r
19 import java.util.List;
\r
21 import org.apache.tools.ant.BuildException;
\r
22 import org.apache.tools.ant.Project;
\r
23 import org.apache.tools.ant.Task;
\r
24 import org.apache.tools.ant.taskdefs.Execute;
\r
25 import org.apache.tools.ant.taskdefs.LogStreamHandler;
\r
26 import org.apache.tools.ant.types.Commandline;
\r
28 import org.tianocore.common.logger.EdkLog;
\r
31 VfrcompilerTask Task Class
\r
33 -createListFile : create an output IFR listing file.
\r
34 -outPutDir : deposit all output files to directory OutputDir (default=cwd)
\r
35 -createIfrBinFile: create an IFR HII pack file
\r
36 -vfrFile : name of the input VFR script file
\r
37 -processArg : c processer argument
\r
38 -includepathList : add IncPath to the search path for VFR included files
\r
40 public class VfrCompilerTask extends Task implements EfiDefine {
\r
41 private static String toolName = "VfrCompile";
\r
43 private ToolArg createListFile = new ToolArg();
\r
44 private ToolArg createIfrBinFile = new ToolArg();
\r
45 private ToolArg processerArg = new ToolArg();
\r
46 private FileArg vfrFile = new FileArg();
\r
47 private IncludePath includepathList = new IncludePath();
\r
48 private FileArg outPutDir = new FileArg(" -od ", ".");
\r
49 private String dllPath = "";
\r
52 get class member of createList file
\r
54 @returns file name of createList
\r
56 public boolean getCreateListFile() {
\r
57 return this.createListFile.getValue().length() > 0;
\r
61 set class member of createList file
\r
63 @param createListFile if createList string equal "on" set '-l' flag
\r
65 public void setCreateListFile(boolean createListFile) {
\r
66 if (createListFile) {
\r
67 this.createListFile.setArg(" -", "l");
\r
74 @returns name of output dir
\r
76 public String getOutPutDir() {
\r
77 return this.outPutDir.getValue();
\r
81 set class member of outPutDir
\r
83 @param outPutDir The directory name for ouput file
\r
85 public void setOutPutDir(String outPutDir) {
\r
86 this.outPutDir.setArg(" -od ", outPutDir);
\r
91 get class member of ifrBinFile
\r
93 @return file name of ifrBinFile
\r
95 public boolean getCreateIfrBinFile() {
\r
96 return this.createIfrBinFile.getValue().length() > 0;
\r
100 set class member of ifrBinFile
\r
102 @param createIfrBinFile The flag to specify if the IFR binary file should
\r
103 be generated or not
\r
105 public void setCreateIfrBinFile(boolean createIfrBinFile) {
\r
106 if (createIfrBinFile) {
\r
107 this.createIfrBinFile.setArg(" -", "ibin");
\r
112 get class member of vfrFile
\r
114 @returns name of vfrFile
\r
116 public String getVfrFile() {
\r
117 return this.vfrFile.getValue();
\r
121 set class member of vfrFile
\r
123 @param vfrFile The name of VFR file
\r
125 public void setVfrFile(String vfrFile) {
\r
126 this.vfrFile.setArg(" ", vfrFile);
\r
130 add includePath in includepath List
\r
132 @param includepath The IncludePath object which represents include path
\r
134 public void addConfiguredIncludepath(IncludePath includepath){
\r
135 this.includepathList.insert(includepath);
\r
139 get class member of processerArg
\r
141 @returns processer argument
\r
143 public String getProcesserArg() {
\r
144 return this.processerArg.getValue();
\r
149 set class member of processerArg
\r
151 @param processerArg The processor argument
\r
153 public void setProcesserArg(String processerArg) {
\r
154 this.processerArg.setArg(" -ppflag ", processerArg);
\r
157 public void setDllPath(String dllPath) {
\r
158 this.dllPath = dllPath;
\r
162 The standard execute method of ANT task.
\r
164 public void execute() throws BuildException {
\r
165 Project project = this.getProject();
\r
166 String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");
\r
168 if (toolPath == null) {
\r
169 command = toolName;
\r
171 command = toolPath + File.separator + toolName;
\r
174 String argument = "" + createIfrBinFile
\r
182 /// constructs the command-line
\r
184 Commandline commandLine = new Commandline();
\r
185 commandLine.setExecutable(command);
\r
186 commandLine.createArgument().setLine(argument);
\r
189 /// configures the Execute object
\r
191 LogStreamHandler streamHandler = new LogStreamHandler(this,
\r
195 Execute runner = new Execute(streamHandler,null);
\r
196 runner.setAntRun(project);
\r
197 runner.setCommandline(commandLine.getCommandline());
\r
198 runner.setWorkingDirectory(new File(outPutDir.getValue()));
\r
199 runner.setEnvironment(new String[]{"PATH", dllPath});
\r
201 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));
\r
202 EdkLog.log(this, vfrFile.toFileList());
\r
204 int returnVal = runner.execute();
\r
205 if (EFI_SUCCESS == returnVal) {
\r
206 EdkLog.log(this, EdkLog.EDK_VERBOSE, "VfrCompile succeeded!");
\r
208 EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));
\r
209 throw new BuildException("VfrCompile failed!");
\r
211 } catch (IOException e) {
\r
212 throw new BuildException(e.getMessage());
\r