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