]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java
13b855cdd881038fa46e18b54da15f44c7df82bc
[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
50 /**
51 get class member of createList file
52
53 @returns file name of createList
54 **/
55 public boolean getCreateListFile() {
56 return this.createListFile.getValue().length() > 0;
57 }
58
59 /**
60 set class member of createList file
61
62 @param createListFile if createList string equal "on" set '-l' flag
63 **/
64 public void setCreateListFile(boolean createListFile) {
65 if (createListFile) {
66 this.createListFile.setArg(" -", "l");
67 }
68 }
69
70 /**
71 get output dir
72
73 @returns name of output dir
74 **/
75 public String getOutPutDir() {
76 return this.outPutDir.getValue();
77 }
78
79 /**
80 set class member of outPutDir
81
82 @param outPutDir The directory name for ouput file
83 **/
84 public void setOutPutDir(String outPutDir) {
85 this.outPutDir.setArg(" -od ", outPutDir);
86 }
87
88
89 /**
90 get class member of ifrBinFile
91
92 @return file name of ifrBinFile
93 **/
94 public boolean getCreateIfrBinFile() {
95 return this.createIfrBinFile.getValue().length() > 0;
96 }
97
98 /**
99 set class member of ifrBinFile
100
101 @param createIfrBinFile The flag to specify if the IFR binary file should
102 be generated or not
103 */
104 public void setCreateIfrBinFile(boolean createIfrBinFile) {
105 if (createIfrBinFile) {
106 this.createIfrBinFile.setArg(" -", "ibin");
107 }
108 }
109
110 /**
111 get class member of vfrFile
112
113 @returns name of vfrFile
114 **/
115 public String getVfrFile() {
116 return this.vfrFile.getValue();
117 }
118
119 /**
120 set class member of vfrFile
121
122 @param vfrFile The name of VFR file
123 **/
124 public void setVfrFile(String vfrFile) {
125 this.vfrFile.setArg(" ", vfrFile);
126 }
127
128 /**
129 add includePath in includepath List
130
131 @param includepath The IncludePath object which represents include path
132 **/
133 public void addConfiguredIncludepath(IncludePath includepath){
134 this.includepathList.insert(includepath);
135 }
136
137 /**
138 get class member of processerArg
139
140 @returns processer argument
141 **/
142 public String getProcesserArg() {
143 return this.processerArg.getValue();
144 }
145
146
147 /**
148 set class member of processerArg
149
150 @param processerArg The processor argument
151 */
152 public void setProcesserArg(String processerArg) {
153 this.processerArg.setArg(" -ppflag ", processerArg);
154 }
155
156 /**
157 The standard execute method of ANT task.
158 **/
159 public void execute() throws BuildException {
160 Project project = this.getProject();
161 String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");
162 String command;
163 if (toolPath == null) {
164 command = toolName;
165 } else {
166 command = toolPath + File.separator + toolName;
167 }
168
169 String argument = "" + createIfrBinFile
170 + processerArg
171 + includepathList
172 + outPutDir
173 + createListFile
174 + vfrFile;
175 try {
176 ///
177 /// constructs the command-line
178 ///
179 Commandline commandLine = new Commandline();
180 commandLine.setExecutable(command);
181 commandLine.createArgument().setLine(argument);
182
183 ///
184 /// configures the Execute object
185 ///
186 LogStreamHandler streamHandler = new LogStreamHandler(this,
187 Project.MSG_INFO,
188 Project.MSG_WARN);
189
190 Execute runner = new Execute(streamHandler,null);
191 runner.setAntRun(project);
192 runner.setCommandline(commandLine.getCommandline());
193 runner.setWorkingDirectory(new File(outPutDir.getValue()));
194
195 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));
196 EdkLog.log(this, vfrFile.toFileList());
197
198 int returnVal = runner.execute();
199 if (EFI_SUCCESS == returnVal) {
200 EdkLog.log(this, EdkLog.EDK_VERBOSE, "VfrCompile succeeded!");
201 } else {
202 EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));
203 throw new BuildException("VfrCompile failed!");
204 }
205 } catch (IOException e) {
206 throw new BuildException(e.getMessage());
207 }
208 }
209 }