Polished the build tools' screen output to be in a more coherent form
[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 /**
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 String createListFile = "";
40 private String outPutDir = "";
41 private String createIfrBinFile = "";
42 private String processerArg ="";
43 private String vfrFile = "";
44 private String vfrFileName = "";
45
46 private List<Object> includepathList = new ArrayList<Object>();
47
48 /**
49 get class member of createList file
50
51 @returns file name of createList
52 **/
53 public String getCreateListFile() {
54 return createListFile;
55 }
56
57 /**
58 set class member of createList file
59
60 @param createListFile if createList string equal "on" set '-l' flag
61 **/
62 public void setCreateListFile(String createListFile) {
63 if (createListFile.equals("ON")||createListFile.equals("on"))
64 this.createListFile = " -l";
65 }
66
67 /**
68 get output dir
69
70 @returns name of output dir
71 **/
72 public String getOutPutDir() {
73 return outPutDir;
74 }
75
76 /**
77 set class member of outPutDir
78
79 @param outPutDir The directory name for ouput file
80 **/
81 public void setOutPutDir(String outPutDir) {
82 this.outPutDir = " -od " + outPutDir;
83 }
84
85
86 /**
87 get class member of ifrBinFile
88
89 @return file name of ifrBinFile
90 **/
91 public String getCreateIfrBinFile() {
92 return createIfrBinFile;
93 }
94
95 /**
96 set class member of ifrBinFile
97
98 @param createIfrBinFile The flag to specify if the IFR binary file should
99 be generated or not
100 */
101 public void setCreateIfrBinFile(String createIfrBinFile) {
102 if (createIfrBinFile.equals("ON") || createIfrBinFile.equals("on"));
103 this.createIfrBinFile = " -ibin";
104 }
105
106 /**
107 get class member of vfrFile
108
109 @returns name of vfrFile
110 **/
111 public String getVfrFile() {
112 return vfrFile;
113 }
114
115 /**
116 set class member of vfrFile
117
118 @param vfrFile The name of VFR file
119 **/
120 public void setVfrFile(String vfrFile) {
121 this.vfrFileName = (new File(vfrFile)).getName();
122 this.vfrFile = " " + vfrFile;
123 }
124
125 /**
126 add includePath in includepath List
127
128 @param includepath The IncludePath object which represents include path
129 **/
130 public void addIncludepath(IncludePath includepath){
131 includepathList.add(includepath);
132 }
133
134
135 /**
136 get class member of processerArg
137
138 @returns processer argument
139 **/
140 public String getProcesserArg() {
141 return processerArg;
142 }
143
144
145 /**
146 set class member of processerArg
147
148 @param processerArg The processor argument
149 */
150 public void setProcesserArg(String processerArg) {
151 this.processerArg = " -ppflag " + processerArg;
152 }
153
154 /**
155 The standard execute method of ANT task.
156 **/
157 public void execute() throws BuildException {
158 Project project = this.getProject();
159 String toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");
160 String command;
161 if (toolPath == null) {
162 command = "VfrCompile";
163 } else {
164 command = toolPath + "/" + "VfrCompile";
165 }
166 List<Object> includePath = new ArrayList<Object>();
167 String incPath = "";
168
169 int count = includepathList.size();
170 IncludePath path;
171 for (int i = 0; i < count; i++) {
172 path = (IncludePath) includepathList.get(i);
173 if (path.getFile() != null) {
174 FileParser.loadFile( project,includePath,path.getFile(), "-I");
175 }
176 }
177 for (int i = 0; i < count; i++) {
178 incPath = incPath + " " + includepathList.get(i);
179 }
180 count = includePath.size();
181 for (int i = 0; i < count; i++) {
182 incPath = incPath + " " + includePath.get(i);
183 }
184 String argument = this.createIfrBinFile +
185 this.processerArg +
186 incPath +
187 this.outPutDir +
188 this.createListFile +
189 this.vfrFile ;
190 try {
191 ///
192 /// constructs the command-line
193 ///
194 Commandline commandLine = new Commandline();
195 commandLine.setExecutable(command);
196 commandLine.createArgument().setLine(argument);
197
198 ///
199 /// configures the Execute object
200 ///
201 LogStreamHandler streamHandler = new LogStreamHandler(this,
202 Project.MSG_INFO,
203 Project.MSG_WARN);
204
205 Execute runner = new Execute(streamHandler,null);
206 runner.setAntRun(project);
207 runner.setCommandline(commandLine.getCommandline());
208
209 log(Commandline.toString(commandLine.getCommandline()), Project.MSG_VERBOSE);
210 log(vfrFileName);
211 int returnVal = runner.execute();
212 if (EFI_SUCCESS == returnVal) {
213 log("VfrCompiler succeeded!", Project.MSG_VERBOSE);
214 } else {
215 log("ERROR = " + Integer.toHexString(returnVal));
216 throw new BuildException("VfrCompiler failed!");
217 }
218 } catch (IOException e) {
219 throw new BuildException(e.getMessage());
220 }
221 }
222 }