]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | This file is to define an ANT task which wraps VfrCompile.exe tool\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | package org.tianocore.framework.tasks;\r | |
15 | \r | |
219e2247 | 16 | import java.io.File;\r |
878ddf1f | 17 | import java.io.IOException;\r |
18 | import java.util.ArrayList;\r | |
19 | import java.util.List;\r | |
20 | \r | |
21 | import org.apache.tools.ant.BuildException;\r | |
22 | import org.apache.tools.ant.Project;\r | |
23 | import org.apache.tools.ant.Task;\r | |
24 | import org.apache.tools.ant.taskdefs.Execute;\r | |
25 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
26 | import 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 | |
38 | public 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 | |
170 | List<Object> includePath = new ArrayList<Object>(); \r | |
171 | String incPath = ""; \r | |
172 | \r | |
82810f3b | 173 | int count = includepathList.size(); \r |
878ddf1f | 174 | for (int i = 0; i < count; i++) {\r |
82810f3b | 175 | incPath += includepathList.get(i).toString();\r |
878ddf1f | 176 | }\r |
82810f3b | 177 | \r |
878ddf1f | 178 | String argument = this.createIfrBinFile +\r |
179 | this.processerArg + \r | |
180 | incPath +\r | |
181 | this.outPutDir + \r | |
182 | this.createListFile +\r | |
183 | this.vfrFile ;\r | |
184 | try {\r | |
185 | ///\r | |
186 | /// constructs the command-line\r | |
187 | ///\r | |
188 | Commandline commandLine = new Commandline();\r | |
189 | commandLine.setExecutable(command);\r | |
190 | commandLine.createArgument().setLine(argument);\r | |
191 | \r | |
192 | ///\r | |
193 | /// configures the Execute object\r | |
194 | ///\r | |
195 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
196 | Project.MSG_INFO,\r | |
197 | Project.MSG_WARN);\r | |
198 | \r | |
199 | Execute runner = new Execute(streamHandler,null);\r | |
200 | runner.setAntRun(project);\r | |
caa44816 | 201 | \r |
878ddf1f | 202 | runner.setCommandline(commandLine.getCommandline());\r |
caa44816 | 203 | \r |
204 | if (outPutFile != null && outPutFile.exists()) {\r | |
205 | runner.setWorkingDirectory(outPutFile); \r | |
206 | }\r | |
878ddf1f | 207 | \r |
219e2247 | 208 | log(Commandline.toString(commandLine.getCommandline()), Project.MSG_VERBOSE);\r |
209 | log(vfrFileName);\r | |
878ddf1f | 210 | int returnVal = runner.execute();\r |
211 | if (EFI_SUCCESS == returnVal) {\r | |
3f7b510e | 212 | log("VfrCompile succeeded!", Project.MSG_VERBOSE);\r |
878ddf1f | 213 | } else {\r |
219e2247 | 214 | log("ERROR = " + Integer.toHexString(returnVal));\r |
3f7b510e | 215 | throw new BuildException("VfrCompile failed!");\r |
878ddf1f | 216 | }\r |
878ddf1f | 217 | } catch (IOException e) {\r |
218 | throw new BuildException(e.getMessage());\r | |
219 | }\r | |
220 | }\r | |
3f7b510e | 221 | }\r |