]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFvImageTask.java
Temporary workaround--determine the target architecture from an environment variable...
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFvImageTask.java
1 /** @file
2 GenFvImageTask class.
3
4 GenFvImageTask is to call GenFvImage.exe to generate FvImage.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 package org.tianocore.framework.tasks;
17 import java.io.File;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.taskdefs.Execute;
23 import org.apache.tools.ant.taskdefs.LogStreamHandler;
24 import org.apache.tools.ant.types.Commandline;
25
26 /**
27 GenFvImageTask
28
29 GenFvImageTask is to call GenFvImage.exe to generate the FvImage.
30
31 **/
32 public class GenFvImageTask extends Task implements EfiDefine{
33 ///
34 /// The name of input inf file
35 ///
36 private String infFile="";
37 ///
38 /// The target architecture.
39 ///
40 private String arch="";
41
42 /**
43 execute
44
45 GenFvImageTask execute is to assemble tool command line & execute tool
46 command line.
47 **/
48 public void execute() throws BuildException {
49 Project project = this.getOwningTarget().getProject();
50 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
51 String command = "";
52
53 if (path == null){
54 path = "";
55 }else {
56 path = path + File.separatorChar;
57 }
58
59 // FIXME arch should be passed via schema attributes.
60 arch=System.getenv("ARCH");
61 if (arch == null) {
62 arch = "";
63 }
64 // FIXME end
65
66 if (arch.equalsIgnoreCase("IA32")){
67 command = path + "GenFvImage_Ia32";
68 }
69 else if (arch.equalsIgnoreCase("X64")){
70 command = path + "GenFvImage_X64";
71 }
72 else if (arch.equalsIgnoreCase("IPF")){
73 command = path + "GenFvImage_Ipf";
74 }
75 else {
76 command = path + "GenFvImage";
77 }
78 String argument = infFile;
79
80 try {
81
82 Commandline commandLine = new Commandline();
83 commandLine.setExecutable(command);
84 commandLine.createArgument().setLine(argument);
85
86 LogStreamHandler streamHandler = new LogStreamHandler(this,
87 Project.MSG_INFO,
88 Project.MSG_WARN);
89 //
90 // create a execute object and set it's commandline
91 //
92 Execute runner = new Execute(streamHandler,null);
93 runner.setAntRun(project);
94 runner.setCommandline(commandLine.getCommandline());
95 System.out.println(Commandline.toString(commandLine.getCommandline()));
96
97 int revl = -1;
98 //
99 // user execute class call external programs - GenFvImage
100 //
101 revl = runner.execute();
102 //
103 // execute command line success!
104 //
105 if (EFI_SUCCESS == revl){
106 System.out.println("GenFvImage succeeded!");
107 } else {
108
109 //
110 // execute command line failed!
111 //
112 throw new BuildException("GenFvImage failed !(error =" +
113 Integer.toHexString(revl) + ")");
114 }
115
116 } catch (Exception e) {
117 System.out.println(e.getMessage());
118 }
119 }
120 /**
121 getInfFile
122
123 This function is to get class member of infFile
124 @return String name of infFile
125 **/
126 public String getInfFile() {
127 return infFile;
128 }
129
130 /**
131 setInfFile
132
133 This function is to set class member of infFile.
134
135 @param infFile name of infFile
136 **/
137 public void setInfFile(String infFile) {
138 this.infFile = "-I " + infFile;
139 }
140
141 /**
142 getArch
143
144 This function is to get class member of arch.
145 @return The target architecture.
146 **/
147 public String getArch() {
148 return arch;
149 }
150
151 /**
152 setArch
153
154 This function is to set class member of arch.
155
156 @param arch The target architecture.
157 **/
158 public void setArch(String arch) {
159 this.arch = arch;
160 }
161 }