1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
/** @file
This file is to define an ANT task which wraps StrGather.exe tool.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.framework.tasks;
import java.util.*;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.types.Commandline;
/**
StrGather Task Class
class memberg
-commandType : command type [parse/scan/dump]
-baseName : base name of component
-verbose : level of verbose [all/read/write]
-outputDatabase : file name of output database file
-databaseList : file name list of database files
-inputFileList : file name list of input files
-newDatabase : whether to need new database [ture/false]
-unquotedString : whether to unquoted strings are used [ture/false]
-includePathList: path list of include paths
-ignoreNotFound : whether to ignore a given STRING_TOKEN(STR) is not found in database [ture/false]
-skipExtList : skip scan of files with extension name
-outputString : write string data to filename
-outputDefines : write string defines to filename
-outputUnicode : dump database to unicode file filename
-lang : only dump for the language
-indirectionFile: specify an indirection file
-outputHpk : create an HII export pack of the strings
**/
public class StrGatherTask extends Task implements EfiDefine {
///
/// common options
///
private String commandType = "";
private String baseName = "";
///
/// "all/read/write"
///
private String verbose = "";
private String outputDatabase = "";
private List<Object> databaseList = new ArrayList<Object>();
private List<Object> inputFileList = new ArrayList<Object>();
///
/// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"
///
private String newDatabase = "";
private String unquotedString = "";
private List<Object> includePathList = new ArrayList<Object>();
///
/// scan options ignoreNotFound -- "ture/false"
///
private String ignoreNotFound = "";
private List<Object> skipExtList = new ArrayList<Object>();
///
/// dump options
///
private String outputString = "";
private String outputDefines = "";
private String outputUnicode = "";
private String lang = "";
private String indirectionFile = "";
private String outputHpk = "";
///
/// global variable
///
static private Project project;
/**
assemble tool command line & execute tool command line
@throws BuildException
**/
public void execute() throws BuildException {
project = this.getOwningTarget().getProject();
///
/// absolute path of efi tools
///
String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
String command;
if (path == null) {
command = "strgather";
} else {
command = path + "/" + "strgather";
}
///
/// transfer nested elements into string
///
String databases = list2Str(databaseList, "-db");
String skipExts = list2Str(skipExtList, "-skipext");
String includePaths = list2Str(includePathList, "-I");
String inputFiles = list2Str(inputFileList, "");
///
/// assemble argument
///
String argument = commandType + verbose + databases + baseName
+ outputDatabase + includePaths + newDatabase + unquotedString
+ skipExts + ignoreNotFound + outputString + outputDefines
+ outputUnicode + lang + indirectionFile + outputHpk
+ inputFiles;
///
/// return value of fwimage execution
///
int revl = -1;
try {
Commandline cmdline = new Commandline();
cmdline.setExecutable(command);
cmdline.createArgument().setLine(argument);
LogStreamHandler streamHandler = new LogStreamHandler(this,
Project.MSG_INFO, Project.MSG_WARN);
Execute runner = new Execute(streamHandler, null);
runner.setAntRun(project);
runner.setCommandline(cmdline.getCommandline());
System.out.println(Commandline.toString(cmdline.getCommandline()));
revl = runner.execute();
if (EFI_SUCCESS == revl) {
///
/// command execution success
///
System.out.println("strgather succeeded!");
} else {
///
/// command execution fail
///
System.out.println("strgather failed. (error="
+ Integer.toHexString(revl) + ")");
throw new BuildException("strgather failed. (error="
+ Integer.toHexString(revl) + ")");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
}
/**
get class member "commandType"
@returns commandType parameter
**/
public String getCommandType() {
return this.commandType;
}
/**
set class member ""
@param commandType type of strgather command [parse/scan/dump]
**/
public void setCommandType(String commandType) {
this.commandType = " -" + commandType;
}
/**
get class member "verbose"
@returns verbose parameter
**/
public String getVerbose() {
return this.verbose;
}
/**
set class member "verbose"
@param verbose verbose level [all/read/write]
**/
public void setVerbose(String verbose) {
if (verbose.equals("all")) {
///
/// for verbose output
///
this.verbose = " -v ";
} else if (verbose.equals("read")) {
///
/// for verbose output when reading database
///
this.verbose = " -vdbr ";
} else if (verbose.equals("write")) {
///
/// for verbose output when writing database
///
this.verbose = " -vdbw ";
}
}
/**
get class member baseName
@returns baseName parameter
**/
public String getBaseName() {
return this.baseName;
}
/**
set class member baseName
@param baseName name of the output files of .c and .h
**/
public void setBaseName(String baseName) {
this.baseName = " -bn " + baseName;
}
/**
get class member "outputDatabase"
@returns outputDatabase parameter
**/
public String getOutputDatabase() {
return this.outputDatabase;
}
/**
set class member "outputDatabase"
@param outputDatabase filename of output database file
**/
public void setOutputDatabase(String outputDatabase) {
this.outputDatabase = " -od " + outputDatabase;
}
/**
get class member "newDatabase"
@returns newDatabase parameter
**/
public String getNewDatabse() {
return this.newDatabase;
}
/**
set class member "newDatabase"
@param newDatabase whether to not read in existing database file
**/
public void setNewDatabase(String newDatabase) {
if (newDatabase.equals("true")) {
this.newDatabase = " -newdb ";
}
}
/**
get class member "unquotedString"
@returns unquotedString parameter
**/
public String getUnquotedString() {
return this.unquotedString;
}
/**
set class member "unquotedString"
@param unquotedString :
whether to indicate that unquoted strings are used
**/
public void setUnquotedString(String unquotedString) {
if (unquotedString.equals("true")) {
this.unquotedString = " -uqs ";
}
}
/**
get class member "ignoreNotFound"
@returns ignoreNotFound parameter
**/
public String getIgnoreNotFound() {
return this.ignoreNotFound;
}
/**
set class member "ignoreNotFound"
@param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR)
is not found in the database
**/
public void setIgnoreNotFound(String ignoreNotFound) {
if (ignoreNotFound.equals("true")) {
this.ignoreNotFound = " -ignorenotfound ";
}
}
/**
get class member "outputString"
@returns outputString parameter
**/
public String getOutputString() {
return this.outputString;
}
/**
set class member "outputString"
@param outputString filename of string data file
**/
public void setOutputString(String outputString) {
this.outputString = " -oc " + outputString;
}
/**
get class member "outputDefines"
@returns outputDefines parameter
**/
public String getOutputDefines() {
return this.outputDefines;
}
/**
set class member "outputDefines"
@param outputDefines filename of string defines file
**/
public void setOutputDefines(String outputDefines) {
this.outputDefines = " -oh " + outputDefines;
}
/**
get class member "outputUnicode"
@returns outputUnicode parameter
**/
public String getOutputUnicode() {
return this.outputUnicode;
}
/**
set class member "outputUnicode"
@param outputUnicode filename of unicode file to be dumped database
**/
public void setOutputUnicode(String outputUnicode) {
this.outputUnicode = " -ou " + outputUnicode;
}
/**
get class member "lang"
@returns lang parameter
**/
public String getLang() {
return this.lang;
}
/**
set class member "lang"
@param lang language of dump
**/
public void setLang(String lang) {
this.lang = " -lang " + lang;
}
/**
get class member "indirectionFile"
@returns indirectionFile parameter
**/
public String getIndirectionFile() {
return this.indirectionFile;
}
/**
set class member "indirectionFile"
@param indirectionFile filename of indirection file
**/
public void setIndirectionFile(String indirectionFile) {
this.indirectionFile = " -if " + indirectionFile;
}
/**
get class member "outputHpk"
@returns outputHpk parameter
**/
public String getOutputHpk() {
return this.outputHpk;
}
/**
set class member "outputHpk"
@param outputHpk filename of output HII export pack of the strings
**/
public void setOutputHpk(String outputHpk) {
this.outputHpk = " -hpk " + outputHpk;
}
/**
add a skipExt element into list
@param skipExt skipExt element
**/
public void addSkipext(SkipExt skipExt) {
skipExtList.add(skipExt);
};
/**
add a includePath element into list
@param includePath includePath element
**/
public void addIncludepath(IncludePath includePath) {
includePathList.add(includePath);
};
/**
add a inputFile element into list
@param inputFile inputFile element
**/
public void addInputfile(InputFile inputFile) {
inputFileList.add(inputFile);
};
/**
add a database element into list
@param database :
database element
**/
public void addDatabase(Database database) {
databaseList.add(database);
}
/**
transfer List to String
@param list nested element list
@param tag interval tag of parameter
@returns string line of parameters
**/
private String list2Str(List list, String tag) {
///
/// string line for return
///
String paraStr = "";
///
/// nested element in list
///
NestElement element;
///
/// iterator of nested element list
///
Iterator elementIter = list.iterator();
///
/// string parameter list
///
List<Object> strList = new ArrayList<Object>();
while (elementIter.hasNext()) {
element = (NestElement) elementIter.next();
if (null != element.getFile()) {
///
/// nested element include file
///
FileParser.loadFile(project, strList, element.getFile(), tag);
}
if (element.getName().length() > 0) {
///
/// nested element include name
///
paraStr = paraStr + " " + element.getName();
}
List<String> nameList = element.getList();
if (nameList.size() > 0) {
Iterator nameIter = nameList.iterator();
while (nameIter.hasNext()) {
paraStr = paraStr + " " + tag + " " + (String)nameIter.next();
}
}
}
///
/// iterator of string parameter list
///
Iterator strIter = strList.iterator();
while (strIter.hasNext()) {
paraStr = paraStr + " " + strIter.next();
}
return paraStr;
}
}
|