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