]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java
- Fixed EDKT146; The override warning message has been reduced to almost none.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / VfrCompilerTask.java
CommitLineData
878ddf1f 1/** @file\r
2This file is to define an ANT task which wraps VfrCompile.exe tool\r
3\r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14package org.tianocore.framework.tasks;\r
15\r
219e2247 16import java.io.File;\r
878ddf1f 17import java.io.IOException;\r
18import java.util.ArrayList;\r
19import java.util.List;\r
20\r
21import org.apache.tools.ant.BuildException;\r
22import org.apache.tools.ant.Project;\r
23import org.apache.tools.ant.Task;\r
24import org.apache.tools.ant.taskdefs.Execute;\r
25import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
26import org.apache.tools.ant.types.Commandline;\r
27\r
28/**\r
29 VfrcompilerTask Task Class\r
30 class member \r
31 -createListFile : create an output IFR listing file.\r
32 -outPutDir : deposit all output files to directory OutputDir (default=cwd)\r
33 -createIfrBinFile: create an IFR HII pack file\r
34 -vfrFile : name of the input VFR script file\r
35 -processArg : c processer argument\r
36 -includepathList : add IncPath to the search path for VFR included files\r
37 **/\r
38public class VfrCompilerTask extends Task implements EfiDefine {\r
39 private String createListFile = "";\r
40 private String outPutDir = "";\r
caa44816 41 private File outPutFile;\r
878ddf1f 42 private String createIfrBinFile = "";\r
43 private String processerArg ="";\r
219e2247 44 private String vfrFile = "";\r
45 private String vfrFileName = "";\r
878ddf1f 46\r
47 private List<Object> includepathList = new ArrayList<Object>();\r
48\r
49 /**\r
50 get class member of createList file\r
51\r
52 @returns file name of createList\r
53 **/\r
54 public String getCreateListFile() {\r
55 return createListFile;\r
56 }\r
57\r
58 /**\r
59 set class member of createList file\r
60\r
61 @param createListFile if createList string equal "on" set '-l' flag\r
62 **/\r
63 public void setCreateListFile(String createListFile) {\r
64 if (createListFile.equals("ON")||createListFile.equals("on"))\r
65 this.createListFile = " -l";\r
66 }\r
67\r
68 /**\r
69 get output dir \r
70\r
71 @returns name of output dir\r
72 **/\r
73 public String getOutPutDir() {\r
74 return outPutDir;\r
75 }\r
76\r
77 /**\r
78 set class member of outPutDir\r
79\r
80 @param outPutDir The directory name for ouput file\r
81 **/\r
82 public void setOutPutDir(String outPutDir) {\r
caa44816 83 if (outPutDir != null) {\r
84 outPutFile = new File(outPutDir);\r
85 }\r
878ddf1f 86 this.outPutDir = " -od " + outPutDir;\r
87 }\r
88\r
89\r
90 /**\r
91 get class member of ifrBinFile\r
92\r
93 @return file name of ifrBinFile\r
94 **/\r
95 public String getCreateIfrBinFile() {\r
96 return createIfrBinFile;\r
97 }\r
98\r
99 /**\r
100 set class member of ifrBinFile \r
101\r
102 @param createIfrBinFile The flag to specify if the IFR binary file should\r
103 be generated or not\r
104 */\r
105 public void setCreateIfrBinFile(String createIfrBinFile) {\r
106 if (createIfrBinFile.equals("ON") || createIfrBinFile.equals("on"));\r
107 this.createIfrBinFile = " -ibin";\r
108 }\r
109\r
110 /**\r
111 get class member of vfrFile\r
112\r
113 @returns name of vfrFile\r
114 **/\r
115 public String getVfrFile() {\r
116 return vfrFile;\r
117 }\r
118\r
119 /**\r
120 set class member of vfrFile \r
121\r
122 @param vfrFile The name of VFR file\r
123 **/\r
124 public void setVfrFile(String vfrFile) {\r
219e2247 125 this.vfrFileName = (new File(vfrFile)).getName();\r
878ddf1f 126 this.vfrFile = " " + vfrFile;\r
127 }\r
128\r
129 /**\r
130 add includePath in includepath List \r
131\r
132 @param includepath The IncludePath object which represents include path\r
133 **/\r
134 public void addIncludepath(IncludePath includepath){\r
135 includepathList.add(includepath);\r
136 }\r
137\r
138\r
139 /**\r
140 get class member of processerArg\r
141\r
142 @returns processer argument\r
143 **/\r
144 public String getProcesserArg() {\r
145 return processerArg;\r
146 }\r
147\r
148\r
149 /**\r
150 set class member of processerArg\r
151\r
152 @param processerArg The processor argument\r
153 */\r
154 public void setProcesserArg(String processerArg) {\r
155 this.processerArg = " -ppflag " + processerArg;\r
156 }\r
157\r
158 /**\r
159 The standard execute method of ANT task.\r
160 **/\r
161 public void execute() throws BuildException {\r
162 Project project = this.getProject();\r
2da8968b 163 String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
878ddf1f 164 String command;\r
165 if (toolPath == null) {\r
166 command = "VfrCompile";\r
167 } else {\r
168 command = toolPath + "/" + "VfrCompile";\r
169 }\r
170 List<Object> includePath = new ArrayList<Object>(); \r
171 String incPath = ""; \r
172\r
173 int count = includepathList.size(); \r
174 IncludePath path;\r
175 for (int i = 0; i < count; i++) {\r
176 path = (IncludePath) includepathList.get(i);\r
177 if (path.getFile() != null) {\r
178 FileParser.loadFile( project,includePath,path.getFile(), "-I"); \r
179 }\r
180 }\r
181 for (int i = 0; i < count; i++) {\r
182 incPath = incPath + " " + includepathList.get(i);\r
183 }\r
184 count = includePath.size();\r
185 for (int i = 0; i < count; i++) {\r
186 incPath = incPath + " " + includePath.get(i);\r
187 }\r
188 String argument = this.createIfrBinFile +\r
189 this.processerArg + \r
190 incPath +\r
191 this.outPutDir + \r
192 this.createListFile +\r
193 this.vfrFile ;\r
194 try {\r
195 ///\r
196 /// constructs the command-line\r
197 ///\r
198 Commandline commandLine = new Commandline();\r
199 commandLine.setExecutable(command);\r
200 commandLine.createArgument().setLine(argument);\r
201\r
202 ///\r
203 /// configures the Execute object\r
204 ///\r
205 LogStreamHandler streamHandler = new LogStreamHandler(this,\r
206 Project.MSG_INFO,\r
207 Project.MSG_WARN);\r
208\r
209 Execute runner = new Execute(streamHandler,null);\r
210 runner.setAntRun(project);\r
caa44816 211 \r
878ddf1f 212 runner.setCommandline(commandLine.getCommandline());\r
caa44816 213 \r
214 if (outPutFile != null && outPutFile.exists()) {\r
215 runner.setWorkingDirectory(outPutFile); \r
216 }\r
878ddf1f 217\r
219e2247 218 log(Commandline.toString(commandLine.getCommandline()), Project.MSG_VERBOSE);\r
219 log(vfrFileName);\r
878ddf1f 220 int returnVal = runner.execute();\r
221 if (EFI_SUCCESS == returnVal) {\r
3f7b510e 222 log("VfrCompile succeeded!", Project.MSG_VERBOSE);\r
878ddf1f 223 } else {\r
219e2247 224 log("ERROR = " + Integer.toHexString(returnVal));\r
3f7b510e 225 throw new BuildException("VfrCompile failed!");\r
878ddf1f 226 }\r
878ddf1f 227 } catch (IOException e) {\r
228 throw new BuildException(e.getMessage());\r
229 }\r
230 }\r
3f7b510e 231}\r