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