]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java
- Fixed EDKT240. Now the Blank.pad file for alignment purpose will no longer be needed.
[mirror_edk2.git] / Tools / Java / Source / FrameworkTasks / org / tianocore / framework / tasks / VfrCompilerTask.java
1 /** @file
2 This file is to define an ANT task which wraps VfrCompile.exe tool
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 package org.tianocore.framework.tasks;
15
16 import java.io.File;
17 import java.io.IOException;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.taskdefs.Execute;
23 import org.apache.tools.ant.taskdefs.LogStreamHandler;
24 import org.apache.tools.ant.types.Commandline;
25
26 import org.tianocore.common.logger.EdkLog;
27
28 /**
29 VfrcompilerTask Task Class
30 class member
31 -createListFile : create an output IFR listing file.
32 -outPutDir : deposit all output files to directory OutputDir (default=cwd)
33 -createIfrBinFile: create an IFR HII pack file
34 -vfrFile : name of the input VFR script file
35 -processArg : c processer argument
36 -includepathList : add IncPath to the search path for VFR included files
37 **/
38 public class VfrCompilerTask extends Task implements EfiDefine {
39 private static String toolName = "VfrCompile";
40
41 private ToolArg createListFile = new ToolArg();
42 private ToolArg createIfrBinFile = new ToolArg();
43 private ToolArg processerArg = new ToolArg();
44 private FileArg vfrFile = new FileArg();
45 private IncludePath includepathList = new IncludePath();
46 private FileArg outPutDir = new FileArg(" -od ", ".");
47 private String dllPath = "";
48
49 /**
50 get class member of createList file
51
52 @returns file name of createList
53 **/
54 public boolean getCreateListFile() {
55 return this.createListFile.getValue().length() > 0;
56 }
57
58 /**
59 set class member of createList file
60
61 @param createListFile if createList string equal "on" set '-l' flag
62 **/
63 public void setCreateListFile(boolean createListFile) {
64 if (createListFile) {
65 this.createListFile.setArg(" -", "l");
66 }
67 }
68
69 /**
70 get output dir
71
72 @returns name of output dir
73 **/
74 public String getOutPutDir() {
75 return this.outPutDir.getValue();
76 }
77
78 /**
79 set class member of outPutDir
80
81 @param outPutDir The directory name for ouput file
82 **/
83 public void setOutPutDir(String outPutDir) {
84 this.outPutDir.setArg(" -od ", outPutDir);
85 }
86
87
88 /**
89 get class member of ifrBinFile
90
91 @return file name of ifrBinFile
92 **/
93 public boolean getCreateIfrBinFile() {
94 return this.createIfrBinFile.getValue().length() > 0;
95 }
96
97 /**
98 set class member of ifrBinFile
99
100 @param createIfrBinFile The flag to specify if the IFR binary file should
101 be generated or not
102 */
103 public void setCreateIfrBinFile(boolean createIfrBinFile) {
104 if (createIfrBinFile) {
105 this.createIfrBinFile.setArg(" -", "ibin");
106 }
107 }
108
109 /**
110 get class member of vfrFile
111
112 @returns name of vfrFile
113 **/
114 public String getVfrFile() {
115 return this.vfrFile.getValue();
116 }
117
118 /**
119 set class member of vfrFile
120
121 @param vfrFile The name of VFR file
122 **/
123 public void setVfrFile(String vfrFile) {
124 this.vfrFile.setArg(" ", vfrFile);
125 }
126
127 /**
128 add includePath in includepath List
129
130 @param includepath The IncludePath object which represents include path
131 **/
132 public void addConfiguredIncludepath(IncludePath includepath){
133 this.includepathList.insert(includepath);
134 }
135
136 /**
137 get class member of processerArg
138
139 @returns processer argument
140 **/
141 public String getProcesserArg() {
142 return this.processerArg.getValue();
143 }
144
145
146 /**
147 set class member of processerArg
148
149 @param processerArg The processor argument
150 */
151 public void setProcesserArg(String processerArg) {
152 this.processerArg.setArg(" -ppflag ", processerArg);
153 }
154
155 public void setDllPath(String dllPath) {
156 this.dllPath = dllPath;
157 }
158
159 /**
160 The standard execute method of ANT task.
161 **/
162 public void execute() throws BuildException {
163 Project project = this.getProject();
164 String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");
165 String command;
166 if (toolPath == null) {
167 command = toolName;
168 } else {
169 command = toolPath + File.separator + toolName;
170 }
171
172 String argument = "" + createIfrBinFile
173 + processerArg
174 + includepathList
175 + outPutDir
176 + createListFile
177 + vfrFile;
178 try {
179 ///
180 /// constructs the command-line
181 ///
182 Commandline commandLine = new Commandline();
183 commandLine.setExecutable(command);
184 commandLine.createArgument().setLine(argument);
185
186 ///
187 /// configures the Execute object
188 ///
189 LogStreamHandler streamHandler = new LogStreamHandler(this,
190 Project.MSG_INFO,
191 Project.MSG_WARN);
192
193 Execute runner = new Execute(streamHandler,null);
194 runner.setAntRun(project);
195 runner.setCommandline(commandLine.getCommandline());
196 runner.setWorkingDirectory(new File(outPutDir.getValue()));
197 runner.setEnvironment(new String[]{"PATH", dllPath});
198
199 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));
200 EdkLog.log(this, vfrFile.toFileList());
201
202 int returnVal = runner.execute();
203 if (EFI_SUCCESS == returnVal) {
204 EdkLog.log(this, EdkLog.EDK_VERBOSE, "VfrCompile succeeded!");
205 } else {
206 EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));
207 throw new BuildException("VfrCompile failed!");
208 }
209 } catch (IOException e) {
210 throw new BuildException(e.getMessage());
211 }
212 }
213 }