]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
Updated PeiRebase to produce a map file of the relocations done by this tool. This...
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFvImageTask.java
CommitLineData
878ddf1f 1/** @file\r
2 GenFvImageTask class.\r
3\r
4 GenFvImageTask is to call GenFvImage.exe to generate FvImage.\r
5 \r
6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 **/\r
16package org.tianocore.framework.tasks;\r
878ddf1f 17\r
18import org.apache.tools.ant.BuildException;\r
19import org.apache.tools.ant.Project;\r
20import org.apache.tools.ant.Task;\r
21import org.apache.tools.ant.taskdefs.Execute;\r
22import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
23import org.apache.tools.ant.types.Commandline;\r
24\r
a236f1a1 25import java.io.File;\r
26import java.io.IOException;\r
27import java.io.InputStream;\r
28import java.io.InputStreamReader;\r
29import java.lang.ProcessBuilder;\r
30import java.util.ArrayList;\r
31import java.util.LinkedList;\r
32import java.util.List;\r
33import java.util.Map;\r
34\r
878ddf1f 35/**\r
36 GenFvImageTask\r
37 \r
38 GenFvImageTask is to call GenFvImage.exe to generate the FvImage.\r
39 \r
40**/\r
41public class GenFvImageTask extends Task implements EfiDefine{\r
a236f1a1 42 ///\r
43 /// tool name\r
44 ///\r
45 static final private String toolName = "GenFvImage";\r
878ddf1f 46 ///\r
47 /// The name of input inf file\r
48 ///\r
49 private String infFile="";\r
a236f1a1 50 ///\r
51 /// Output directory\r
52 ///\r
53 private String outputDir = ".";\r
54 ///\r
55 /// argument list\r
56 ///\r
57 LinkedList<String> argList = new LinkedList<String>();\r
58\r
878ddf1f 59 /**\r
60 execute\r
61 \r
62 GenFvImageTask execute is to assemble tool command line & execute tool\r
63 command line.\r
64 **/\r
65 public void execute() throws BuildException {\r
66 Project project = this.getOwningTarget().getProject();\r
2da8968b 67 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
a236f1a1 68\r
69 if (path == null) {\r
878ddf1f 70 path = "";\r
a236f1a1 71 } else {\r
72 path += File.separatorChar;\r
878ddf1f 73 }\r
a236f1a1 74 argList.addFirst(path + toolName);\r
8742c000 75\r
a236f1a1 76 /// lauch the program\r
77 ///\r
78 ProcessBuilder pb = new ProcessBuilder(argList);\r
79 pb.directory(new File(outputDir));\r
80 int exitCode = 0;\r
219e2247 81 log((new File(this.infFile)).getName());\r
878ddf1f 82 try {\r
a236f1a1 83 Process cmdProc = pb.start();\r
84 InputStreamReader cmdOut = new InputStreamReader(cmdProc.getInputStream());\r
85 char[] buf = new char[1024];\r
86\r
87 exitCode = cmdProc.waitFor();\r
88 if (exitCode != 0) {\r
89 int len = cmdOut.read(buf, 0, 1024);\r
219e2247 90 log(new String(buf, 0, len));\r
878ddf1f 91 } else {\r
219e2247 92 log("GenFvImage succeeded!", Project.MSG_VERBOSE);\r
878ddf1f 93 }\r
878ddf1f 94 } catch (Exception e) {\r
a236f1a1 95 throw new BuildException(e.getMessage());\r
96 } finally {\r
97 if (exitCode != 0) {\r
59a37259 98 //throw new BuildException("GenFvImage: failed to generate FV file!");\r
a236f1a1 99 }\r
100 }\r
101\r
878ddf1f 102 }\r
103 /**\r
104 getInfFile\r
105 \r
106 This function is to get class member of infFile\r
107 @return String name of infFile\r
108 **/\r
109 public String getInfFile() {\r
110 return infFile;\r
111 }\r
112 \r
113 /**\r
114 setInfFile\r
115 \r
116 This function is to set class member of infFile.\r
117 \r
118 @param infFile name of infFile\r
119 **/\r
120 public void setInfFile(String infFile) {\r
a236f1a1 121 this.infFile = infFile;\r
122 argList.add("-I");\r
123 argList.add(infFile);\r
878ddf1f 124 }\r
125 \r
a236f1a1 126 /**\r
127 getOutputDir\r
128 \r
129 This function is to get output directory.\r
130 \r
131 @return Path of output directory.\r
132 **/\r
133 public String getOutputDir() {\r
134 return outputDir;\r
135 }\r
136\r
137 /**\r
138 setOutputDir\r
139 \r
140 This function is to set output directory.\r
141 \r
142 @param outputDir The output direcotry.\r
143 **/\r
144 public void setOutputDir(String outputDir) {\r
145 this.outputDir = outputDir;\r
146 }\r
8742c000 147}\r