]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java
Fixed the issue caused by introducing INCLUDE_PATH property;
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / VfrCompilerTask.java
1 /** @file
2 This file is to define an ANT task which wraps VfrCompile.exe tool
3
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
9
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.
12
13 **/
14 package org.tianocore.framework.tasks;
15
16 import java.io.File;
17 import java.io.IOException;
18 import java.util.ArrayList;
19 import java.util.List;
20
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;
27
28 /**
29 VfrcompilerTask Task Class
30 class member
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
37 **/
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 = "";
46
47 private List<IncludePath> includepathList = new ArrayList<IncludePath>();
48
49 /**
50 get class member of createList file
51
52 @returns file name of createList
53 **/
54 public String getCreateListFile() {
55 return createListFile;
56 }
57
58 /**
59 set class member of createList file
60
61 @param createListFile if createList string equal "on" set '-l' flag
62 **/
63 public void setCreateListFile(String createListFile) {
64 if (createListFile.equals("ON")||createListFile.equals("on"))
65 this.createListFile = " -l";
66 }
67
68 /**
69 get output dir
70
71 @returns name of output dir
72 **/
73 public String getOutPutDir() {
74 return outPutDir;
75 }
76
77 /**
78 set class member of outPutDir
79
80 @param outPutDir The directory name for ouput file
81 **/
82 public void setOutPutDir(String outPutDir) {
83 if (outPutDir != null) {
84 outPutFile = new File(outPutDir);
85 }
86 this.outPutDir = " -od " + outPutDir;
87 }
88
89
90 /**
91 get class member of ifrBinFile
92
93 @return file name of ifrBinFile
94 **/
95 public String getCreateIfrBinFile() {
96 return createIfrBinFile;
97 }
98
99 /**
100 set class member of ifrBinFile
101
102 @param createIfrBinFile The flag to specify if the IFR binary file should
103 be generated or not
104 */
105 public void setCreateIfrBinFile(String createIfrBinFile) {
106 if (createIfrBinFile.equals("ON") || createIfrBinFile.equals("on"));
107 this.createIfrBinFile = " -ibin";
108 }
109
110 /**
111 get class member of vfrFile
112
113 @returns name of vfrFile
114 **/
115 public String getVfrFile() {
116 return vfrFile;
117 }
118
119 /**
120 set class member of vfrFile
121
122 @param vfrFile The name of VFR file
123 **/
124 public void setVfrFile(String vfrFile) {
125 this.vfrFileName = (new File(vfrFile)).getName();
126 this.vfrFile = " " + vfrFile;
127 }
128
129 /**
130 add includePath in includepath List
131
132 @param includepath The IncludePath object which represents include path
133 **/
134 public void addIncludepath(IncludePath includepath){
135 includepathList.add(includepath);
136 }
137
138
139 /**
140 get class member of processerArg
141
142 @returns processer argument
143 **/
144 public String getProcesserArg() {
145 return processerArg;
146 }
147
148
149 /**
150 set class member of processerArg
151
152 @param processerArg The processor argument
153 */
154 public void setProcesserArg(String processerArg) {
155 this.processerArg = " -ppflag " + processerArg;
156 }
157
158 /**
159 The standard execute method of ANT task.
160 **/
161 public void execute() throws BuildException {
162 Project project = this.getProject();
163 String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");
164 String command;
165 if (toolPath == null) {
166 command = "VfrCompile";
167 } else {
168 command = toolPath + "/" + "VfrCompile";
169 }
170 List<Object> includePath = new ArrayList<Object>();
171 String incPath = "";
172
173 int count = includepathList.size();
174 for (int i = 0; i < count; i++) {
175 incPath += includepathList.get(i).toString();
176 }
177
178 String argument = this.createIfrBinFile +
179 this.processerArg +
180 incPath +
181 this.outPutDir +
182 this.createListFile +
183 this.vfrFile ;
184 try {
185 ///
186 /// constructs the command-line
187 ///
188 Commandline commandLine = new Commandline();
189 commandLine.setExecutable(command);
190 commandLine.createArgument().setLine(argument);
191
192 ///
193 /// configures the Execute object
194 ///
195 LogStreamHandler streamHandler = new LogStreamHandler(this,
196 Project.MSG_INFO,
197 Project.MSG_WARN);
198
199 Execute runner = new Execute(streamHandler,null);
200 runner.setAntRun(project);
201
202 runner.setCommandline(commandLine.getCommandline());
203
204 if (outPutFile != null && outPutFile.exists()) {
205 runner.setWorkingDirectory(outPutFile);
206 }
207
208 log(Commandline.toString(commandLine.getCommandline()), Project.MSG_VERBOSE);
209 log(vfrFileName);
210 int returnVal = runner.execute();
211 if (EFI_SUCCESS == returnVal) {
212 log("VfrCompile succeeded!", Project.MSG_VERBOSE);
213 } else {
214 log("ERROR = " + Integer.toHexString(returnVal));
215 throw new BuildException("VfrCompile failed!");
216 }
217 } catch (IOException e) {
218 throw new BuildException(e.getMessage());
219 }
220 }
221 }