]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java
Remove FrameworkLogger in FrameworkTasks and EdkException in GenBuild. Update EdkLog...
[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 String incPath = "";
171
172 int count = includepathList.size();
173 for (int i = 0; i < count; i++) {
174 incPath += includepathList.get(i).toString();
175 }
176
177 String argument = this.createIfrBinFile +
178 this.processerArg +
179 incPath +
180 this.outPutDir +
181 this.createListFile +
182 this.vfrFile ;
183 try {
184 ///
185 /// constructs the command-line
186 ///
187 Commandline commandLine = new Commandline();
188 commandLine.setExecutable(command);
189 commandLine.createArgument().setLine(argument);
190
191 ///
192 /// configures the Execute object
193 ///
194 LogStreamHandler streamHandler = new LogStreamHandler(this,
195 Project.MSG_INFO,
196 Project.MSG_WARN);
197
198 Execute runner = new Execute(streamHandler,null);
199 runner.setAntRun(project);
200
201 runner.setCommandline(commandLine.getCommandline());
202
203 if (outPutFile != null && outPutFile.exists()) {
204 runner.setWorkingDirectory(outPutFile);
205 }
206
207 log(Commandline.toString(commandLine.getCommandline()), Project.MSG_VERBOSE);
208 log(vfrFileName);
209 int returnVal = runner.execute();
210 if (EFI_SUCCESS == returnVal) {
211 log("VfrCompile succeeded!", Project.MSG_VERBOSE);
212 } else {
213 log("ERROR = " + Integer.toHexString(returnVal));
214 throw new BuildException("VfrCompile failed!");
215 }
216 } catch (IOException e) {
217 throw new BuildException(e.getMessage());
218 }
219 }
220 }