]>
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 | |
93f5dd0a | 28 | import org.tianocore.common.logger.EdkLog;\r |
29 | \r | |
878ddf1f | 30 | /**\r |
31 | VfrcompilerTask Task Class\r | |
32 | class member \r | |
33 | -createListFile : create an output IFR listing file.\r | |
34 | -outPutDir : deposit all output files to directory OutputDir (default=cwd)\r | |
35 | -createIfrBinFile: create an IFR HII pack file\r | |
36 | -vfrFile : name of the input VFR script file\r | |
37 | -processArg : c processer argument\r | |
38 | -includepathList : add IncPath to the search path for VFR included files\r | |
39 | **/\r | |
40 | public class VfrCompilerTask extends Task implements EfiDefine {\r | |
93f5dd0a | 41 | private static String toolName = "VfrCompile";\r |
878ddf1f | 42 | \r |
93f5dd0a | 43 | private ToolArg createListFile = new ToolArg();\r |
44 | private ToolArg createIfrBinFile = new ToolArg();\r | |
45 | private ToolArg processerArg = new ToolArg();\r | |
46 | private FileArg vfrFile = new FileArg();\r | |
47 | private IncludePath includepathList = new IncludePath();\r | |
48 | private FileArg outPutDir = new FileArg(" -od ", ".");\r | |
878ddf1f | 49 | \r |
50 | /**\r | |
51 | get class member of createList file\r | |
52 | \r | |
53 | @returns file name of createList\r | |
54 | **/\r | |
93f5dd0a | 55 | public boolean getCreateListFile() {\r |
56 | return this.createListFile.getValue().length() > 0;\r | |
878ddf1f | 57 | }\r |
58 | \r | |
59 | /**\r | |
60 | set class member of createList file\r | |
61 | \r | |
62 | @param createListFile if createList string equal "on" set '-l' flag\r | |
63 | **/\r | |
93f5dd0a | 64 | public void setCreateListFile(boolean createListFile) {\r |
65 | if (createListFile) {\r | |
66 | this.createListFile.setArg(" -", "l");\r | |
67 | }\r | |
878ddf1f | 68 | }\r |
69 | \r | |
70 | /**\r | |
71 | get output dir \r | |
72 | \r | |
73 | @returns name of output dir\r | |
74 | **/\r | |
75 | public String getOutPutDir() {\r | |
93f5dd0a | 76 | return this.outPutDir.getValue();\r |
878ddf1f | 77 | }\r |
78 | \r | |
79 | /**\r | |
80 | set class member of outPutDir\r | |
81 | \r | |
82 | @param outPutDir The directory name for ouput file\r | |
83 | **/\r | |
84 | public void setOutPutDir(String outPutDir) {\r | |
93f5dd0a | 85 | this.outPutDir.setArg(" -od ", outPutDir);\r |
878ddf1f | 86 | }\r |
87 | \r | |
88 | \r | |
89 | /**\r | |
90 | get class member of ifrBinFile\r | |
91 | \r | |
92 | @return file name of ifrBinFile\r | |
93 | **/\r | |
93f5dd0a | 94 | public boolean getCreateIfrBinFile() {\r |
95 | return this.createIfrBinFile.getValue().length() > 0;\r | |
878ddf1f | 96 | }\r |
97 | \r | |
98 | /**\r | |
99 | set class member of ifrBinFile \r | |
100 | \r | |
101 | @param createIfrBinFile The flag to specify if the IFR binary file should\r | |
102 | be generated or not\r | |
103 | */\r | |
93f5dd0a | 104 | public void setCreateIfrBinFile(boolean createIfrBinFile) {\r |
105 | if (createIfrBinFile) {\r | |
106 | this.createIfrBinFile.setArg(" -", "ibin");\r | |
107 | }\r | |
878ddf1f | 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 | |
93f5dd0a | 116 | return this.vfrFile.getValue();\r |
878ddf1f | 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 | |
93f5dd0a | 125 | this.vfrFile.setArg(" ", vfrFile);\r |
878ddf1f | 126 | }\r |
127 | \r | |
128 | /**\r | |
129 | add includePath in includepath List \r | |
130 | \r | |
131 | @param includepath The IncludePath object which represents include path\r | |
132 | **/\r | |
93f5dd0a | 133 | public void addConfiguredIncludepath(IncludePath includepath){\r |
134 | this.includepathList.insert(includepath);\r | |
878ddf1f | 135 | }\r |
136 | \r | |
878ddf1f | 137 | /**\r |
138 | get class member of processerArg\r | |
139 | \r | |
140 | @returns processer argument\r | |
141 | **/\r | |
142 | public String getProcesserArg() {\r | |
93f5dd0a | 143 | return this.processerArg.getValue();\r |
878ddf1f | 144 | }\r |
145 | \r | |
146 | \r | |
147 | /**\r | |
148 | set class member of processerArg\r | |
149 | \r | |
150 | @param processerArg The processor argument\r | |
151 | */\r | |
152 | public void setProcesserArg(String processerArg) {\r | |
93f5dd0a | 153 | this.processerArg.setArg(" -ppflag ", processerArg);\r |
878ddf1f | 154 | }\r |
155 | \r | |
156 | /**\r | |
157 | The standard execute method of ANT task.\r | |
158 | **/\r | |
159 | public void execute() throws BuildException {\r | |
160 | Project project = this.getProject();\r | |
2da8968b | 161 | String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r |
878ddf1f | 162 | String command;\r |
163 | if (toolPath == null) {\r | |
93f5dd0a | 164 | command = toolName;\r |
878ddf1f | 165 | } else {\r |
93f5dd0a | 166 | command = toolPath + File.separator + toolName;\r |
878ddf1f | 167 | }\r |
878ddf1f | 168 | \r |
93f5dd0a | 169 | String argument = "" + createIfrBinFile\r |
170 | + processerArg \r | |
171 | + includepathList\r | |
172 | + outPutDir\r | |
173 | + createListFile\r | |
174 | + vfrFile;\r | |
878ddf1f | 175 | try {\r |
176 | ///\r | |
177 | /// constructs the command-line\r | |
178 | ///\r | |
179 | Commandline commandLine = new Commandline();\r | |
180 | commandLine.setExecutable(command);\r | |
181 | commandLine.createArgument().setLine(argument);\r | |
182 | \r | |
183 | ///\r | |
184 | /// configures the Execute object\r | |
185 | ///\r | |
186 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
187 | Project.MSG_INFO,\r | |
188 | Project.MSG_WARN);\r | |
189 | \r | |
190 | Execute runner = new Execute(streamHandler,null);\r | |
93f5dd0a | 191 | runner.setAntRun(project); \r |
878ddf1f | 192 | runner.setCommandline(commandLine.getCommandline());\r |
93f5dd0a | 193 | runner.setWorkingDirectory(new File(outPutDir.getValue())); \r |
caa44816 | 194 | \r |
93f5dd0a | 195 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));\r |
196 | EdkLog.log(this, vfrFile.toFileList());\r | |
878ddf1f | 197 | \r |
878ddf1f | 198 | int returnVal = runner.execute();\r |
199 | if (EFI_SUCCESS == returnVal) {\r | |
93f5dd0a | 200 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "VfrCompile succeeded!");\r |
878ddf1f | 201 | } else {\r |
93f5dd0a | 202 | EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));\r |
3f7b510e | 203 | throw new BuildException("VfrCompile failed!");\r |
878ddf1f | 204 | }\r |
878ddf1f | 205 | } catch (IOException e) {\r |
206 | throw new BuildException(e.getMessage());\r | |
207 | }\r | |
208 | }\r | |
3f7b510e | 209 | }\r |