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