]> git.proxmox.com Git - mirror_edk2.git/blame - 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
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
82810f3b 47 private List<IncludePath> includepathList = new ArrayList<IncludePath>();\r
878ddf1f 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
878ddf1f 170 String incPath = ""; \r
171\r
82810f3b 172 int count = includepathList.size(); \r
878ddf1f 173 for (int i = 0; i < count; i++) {\r
82810f3b 174 incPath += includepathList.get(i).toString();\r
878ddf1f 175 }\r
82810f3b 176\r
878ddf1f 177 String argument = this.createIfrBinFile +\r
178 this.processerArg + \r
179 incPath +\r
180 this.outPutDir + \r
181 this.createListFile +\r
182 this.vfrFile ;\r
183 try {\r
184 ///\r
185 /// constructs the command-line\r
186 ///\r
187 Commandline commandLine = new Commandline();\r
188 commandLine.setExecutable(command);\r
189 commandLine.createArgument().setLine(argument);\r
190\r
191 ///\r
192 /// configures the Execute object\r
193 ///\r
194 LogStreamHandler streamHandler = new LogStreamHandler(this,\r
195 Project.MSG_INFO,\r
196 Project.MSG_WARN);\r
197\r
198 Execute runner = new Execute(streamHandler,null);\r
199 runner.setAntRun(project);\r
caa44816 200 \r
878ddf1f 201 runner.setCommandline(commandLine.getCommandline());\r
caa44816 202 \r
203 if (outPutFile != null && outPutFile.exists()) {\r
204 runner.setWorkingDirectory(outPutFile); \r
205 }\r
878ddf1f 206\r
219e2247 207 log(Commandline.toString(commandLine.getCommandline()), Project.MSG_VERBOSE);\r
208 log(vfrFileName);\r
878ddf1f 209 int returnVal = runner.execute();\r
210 if (EFI_SUCCESS == returnVal) {\r
3f7b510e 211 log("VfrCompile succeeded!", Project.MSG_VERBOSE);\r
878ddf1f 212 } else {\r
219e2247 213 log("ERROR = " + Integer.toHexString(returnVal));\r
3f7b510e 214 throw new BuildException("VfrCompile failed!");\r
878ddf1f 215 }\r
878ddf1f 216 } catch (IOException e) {\r
217 throw new BuildException(e.getMessage());\r
218 }\r
219 }\r
3f7b510e 220}\r