]>
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 |
878ddf1f | 18 | \r |
19 | import org.apache.tools.ant.BuildException;\r | |
20 | import org.apache.tools.ant.Project;\r | |
21 | import org.apache.tools.ant.Task;\r | |
22 | import org.apache.tools.ant.taskdefs.Execute;\r | |
23 | import org.apache.tools.ant.taskdefs.LogStreamHandler;\r | |
24 | import org.apache.tools.ant.types.Commandline;\r | |
25 | \r | |
93f5dd0a | 26 | import org.tianocore.common.logger.EdkLog;\r |
27 | \r | |
878ddf1f | 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 | |
93f5dd0a | 39 | private static String toolName = "VfrCompile";\r |
878ddf1f | 40 | \r |
93f5dd0a | 41 | private ToolArg createListFile = new ToolArg();\r |
42 | private ToolArg createIfrBinFile = new ToolArg();\r | |
43 | private ToolArg processerArg = new ToolArg();\r | |
44 | private FileArg vfrFile = new FileArg();\r | |
45 | private IncludePath includepathList = new IncludePath();\r | |
46 | private FileArg outPutDir = new FileArg(" -od ", ".");\r | |
e4b5a8c3 | 47 | private String dllPath = "";\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 | |
93f5dd0a | 54 | public boolean getCreateListFile() {\r |
55 | return this.createListFile.getValue().length() > 0;\r | |
878ddf1f | 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 | |
93f5dd0a | 63 | public void setCreateListFile(boolean createListFile) {\r |
64 | if (createListFile) {\r | |
65 | this.createListFile.setArg(" -", "l");\r | |
66 | }\r | |
878ddf1f | 67 | }\r |
68 | \r | |
69 | /**\r | |
70 | get output dir \r | |
71 | \r | |
72 | @returns name of output dir\r | |
73 | **/\r | |
74 | public String getOutPutDir() {\r | |
93f5dd0a | 75 | return this.outPutDir.getValue();\r |
878ddf1f | 76 | }\r |
77 | \r | |
78 | /**\r | |
79 | set class member of outPutDir\r | |
80 | \r | |
81 | @param outPutDir The directory name for ouput file\r | |
82 | **/\r | |
83 | public void setOutPutDir(String outPutDir) {\r | |
93f5dd0a | 84 | this.outPutDir.setArg(" -od ", outPutDir);\r |
878ddf1f | 85 | }\r |
86 | \r | |
87 | \r | |
88 | /**\r | |
89 | get class member of ifrBinFile\r | |
90 | \r | |
91 | @return file name of ifrBinFile\r | |
92 | **/\r | |
93f5dd0a | 93 | public boolean getCreateIfrBinFile() {\r |
94 | return this.createIfrBinFile.getValue().length() > 0;\r | |
878ddf1f | 95 | }\r |
96 | \r | |
97 | /**\r | |
98 | set class member of ifrBinFile \r | |
99 | \r | |
100 | @param createIfrBinFile The flag to specify if the IFR binary file should\r | |
101 | be generated or not\r | |
102 | */\r | |
93f5dd0a | 103 | public void setCreateIfrBinFile(boolean createIfrBinFile) {\r |
104 | if (createIfrBinFile) {\r | |
105 | this.createIfrBinFile.setArg(" -", "ibin");\r | |
106 | }\r | |
878ddf1f | 107 | }\r |
108 | \r | |
109 | /**\r | |
110 | get class member of vfrFile\r | |
111 | \r | |
112 | @returns name of vfrFile\r | |
113 | **/\r | |
114 | public String getVfrFile() {\r | |
93f5dd0a | 115 | return this.vfrFile.getValue();\r |
878ddf1f | 116 | }\r |
117 | \r | |
118 | /**\r | |
119 | set class member of vfrFile \r | |
120 | \r | |
121 | @param vfrFile The name of VFR file\r | |
122 | **/\r | |
123 | public void setVfrFile(String vfrFile) {\r | |
93f5dd0a | 124 | this.vfrFile.setArg(" ", vfrFile);\r |
878ddf1f | 125 | }\r |
126 | \r | |
127 | /**\r | |
128 | add includePath in includepath List \r | |
129 | \r | |
130 | @param includepath The IncludePath object which represents include path\r | |
131 | **/\r | |
93f5dd0a | 132 | public void addConfiguredIncludepath(IncludePath includepath){\r |
133 | this.includepathList.insert(includepath);\r | |
878ddf1f | 134 | }\r |
135 | \r | |
878ddf1f | 136 | /**\r |
137 | get class member of processerArg\r | |
138 | \r | |
139 | @returns processer argument\r | |
140 | **/\r | |
141 | public String getProcesserArg() {\r | |
93f5dd0a | 142 | return this.processerArg.getValue();\r |
878ddf1f | 143 | }\r |
144 | \r | |
145 | \r | |
146 | /**\r | |
147 | set class member of processerArg\r | |
148 | \r | |
149 | @param processerArg The processor argument\r | |
150 | */\r | |
151 | public void setProcesserArg(String processerArg) {\r | |
93f5dd0a | 152 | this.processerArg.setArg(" -ppflag ", processerArg);\r |
878ddf1f | 153 | }\r |
154 | \r | |
e4b5a8c3 | 155 | public void setDllPath(String dllPath) {\r |
156 | this.dllPath = dllPath;\r | |
157 | }\r | |
158 | \r | |
878ddf1f | 159 | /**\r |
160 | The standard execute method of ANT task.\r | |
161 | **/\r | |
162 | public void execute() throws BuildException {\r | |
163 | Project project = this.getProject();\r | |
2da8968b | 164 | String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r |
878ddf1f | 165 | String command;\r |
166 | if (toolPath == null) {\r | |
93f5dd0a | 167 | command = toolName;\r |
878ddf1f | 168 | } else {\r |
93f5dd0a | 169 | command = toolPath + File.separator + toolName;\r |
878ddf1f | 170 | }\r |
878ddf1f | 171 | \r |
93f5dd0a | 172 | String argument = "" + createIfrBinFile\r |
173 | + processerArg \r | |
174 | + includepathList\r | |
175 | + outPutDir\r | |
176 | + createListFile\r | |
177 | + vfrFile;\r | |
878ddf1f | 178 | try {\r |
179 | ///\r | |
180 | /// constructs the command-line\r | |
181 | ///\r | |
182 | Commandline commandLine = new Commandline();\r | |
183 | commandLine.setExecutable(command);\r | |
184 | commandLine.createArgument().setLine(argument);\r | |
185 | \r | |
186 | ///\r | |
187 | /// configures the Execute object\r | |
188 | ///\r | |
189 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
190 | Project.MSG_INFO,\r | |
191 | Project.MSG_WARN);\r | |
192 | \r | |
193 | Execute runner = new Execute(streamHandler,null);\r | |
93f5dd0a | 194 | runner.setAntRun(project); \r |
878ddf1f | 195 | runner.setCommandline(commandLine.getCommandline());\r |
93f5dd0a | 196 | runner.setWorkingDirectory(new File(outPutDir.getValue())); \r |
e4b5a8c3 | 197 | runner.setEnvironment(new String[]{"PATH", dllPath});\r |
caa44816 | 198 | \r |
93f5dd0a | 199 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));\r |
200 | EdkLog.log(this, vfrFile.toFileList());\r | |
878ddf1f | 201 | \r |
878ddf1f | 202 | int returnVal = runner.execute();\r |
203 | if (EFI_SUCCESS == returnVal) {\r | |
93f5dd0a | 204 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "VfrCompile succeeded!");\r |
878ddf1f | 205 | } else {\r |
93f5dd0a | 206 | EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));\r |
3f7b510e | 207 | throw new BuildException("VfrCompile failed!");\r |
878ddf1f | 208 | }\r |
878ddf1f | 209 | } catch (IOException e) {\r |
210 | throw new BuildException(e.getMessage());\r | |
211 | }\r | |
212 | }\r | |
3f7b510e | 213 | }\r |