]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Trim/Trim.py
2 # Trim files preprocessed by compiler
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 import Common
. LongFilePathOs
as os
14 from io
import BytesIO
16 from optparse
import OptionParser
17 from optparse
import make_option
18 from Common
. BuildToolError
import *
19 from Common
. Misc
import *
20 from Common
. DataType
import *
21 from Common
. BuildVersion
import gBUILD_VERSION
22 import Common
. EdkLogger
as EdkLogger
23 from Common
. LongFilePathSupport
import OpenLongFilePath
as open
25 # Version and Copyright
26 __version_number__
= ( "0.10" + " " + gBUILD_VERSION
)
27 __version__
= "%prog Version " + __version_number__
28 __copyright__
= "Copyright (c) 2007-2018, Intel Corporation. All rights reserved."
30 ## Regular expression for matching Line Control directive like "#line xxx"
31 gLineControlDirective
= re
. compile ( '^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"' )
32 ## Regular expression for matching "typedef struct"
33 gTypedefPattern
= re
. compile ( "^\s*typedef\s+struct(\s+\w+)?\s*[{]*$" , re
. MULTILINE
)
34 ## Regular expression for matching "#pragma pack"
35 gPragmaPattern
= re
. compile ( "^\s*#pragma\s+pack" , re
. MULTILINE
)
36 ## Regular expression for matching "typedef"
37 gTypedef_SinglePattern
= re
. compile ( "^\s*typedef" , re
. MULTILINE
)
38 ## Regular expression for matching "typedef struct, typedef union, struct, union"
39 gTypedef_MulPattern
= re
. compile ( "^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]*$" , re
. MULTILINE
)
42 # The following number pattern match will only match if following criteria is met:
43 # There is leading non-(alphanumeric or _) character, and no following alphanumeric or _
44 # as the pattern is greedily match, so it is ok for the gDecNumberPattern or gHexNumberPattern to grab the maximum match
46 ## Regular expression for matching HEX number
47 gHexNumberPattern
= re
. compile ( "(?<=[^a-zA-Z0-9_])(0[xX])([0-9a-fA-F]+)(U(?=$|[^a-zA-Z0-9_]))?" )
48 ## Regular expression for matching decimal number with 'U' postfix
49 gDecNumberPattern
= re
. compile ( "(?<=[^a-zA-Z0-9_])([0-9]+)U(?=$|[^a-zA-Z0-9_])" )
50 ## Regular expression for matching constant with 'ULL' 'LL' postfix
51 gLongNumberPattern
= re
. compile ( "(?<=[^a-zA-Z0-9_])(0[xX][0-9a-fA-F]+|[0-9]+)U?LL(?=$|[^a-zA-Z0-9_])" )
53 ## Regular expression for matching "Include ()" in asl file
54 gAslIncludePattern
= re
. compile ( "^(\s*)[iI]nclude\s*\( \" ?([^ \" \(\)]+) \" \)" , re
. MULTILINE
)
55 ## Regular expression for matching C style #include "XXX.asl" in asl file
56 gAslCIncludePattern
= re
. compile ( r
'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])' , re
. MULTILINE
)
57 ## Patterns used to convert EDK conventions to EDK2 ECP conventions
59 ## Regular expression for finding header file inclusions
60 gIncludePattern
= re
. compile ( r
"^[ \t]*[%]?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\" <] ?
[ \t ]*)([- \w
. \\ /() \t ]+)( ?
:[ \t ]*[ \" >] ?\
) ?
) ", re.MULTILINE | re.UNICODE | re.IGNORECASE)
63 ## file cache to avoid circular include in ASL file
66 ## Trim preprocessed source code
68 # Remove extra content made by preprocessor. The preprocessor must enable the
69 # line number generation option when preprocessing.
71 # @param Source File to be trimmed
72 # @param Target File to store the trimmed content
73 # @param Convert If True, convert standard HEX format to MASM format
75 def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
76 CreateDirectory(os.path.dirname(Target))
78 with open(Source, " r
") as File:
79 Lines = File.readlines()
81 EdkLogger.error(" Trim
", FILE_OPEN_FAILURE, ExtraData=Source)
83 EdkLogger.error(" Trim
", AUTOGEN_ERROR, " TrimPreprocessedFile
: Error
while processing
file ", File=Source)
87 LineIndexOfOriginalFile = None
89 LineControlDirectiveFound = False
90 for Index in range(len(Lines)):
93 # Find out the name of files injected by preprocessor from the lines
94 # with Line Control directive
96 MatchList = gLineControlDirective.findall(Line)
98 MatchList = MatchList[0]
99 if len(MatchList) == 2:
100 LineNumber = int(MatchList[0], 0)
101 InjectedFile = MatchList[1]
102 InjectedFile = os.path.normpath(InjectedFile)
103 InjectedFile = os.path.normcase(InjectedFile)
104 # The first injected file must be the preprocessed file itself
105 if PreprocessedFile == " ":
106 PreprocessedFile = InjectedFile
107 LineControlDirectiveFound = True
109 elif PreprocessedFile == " " or InjectedFile != PreprocessedFile:
112 if LineIndexOfOriginalFile is None:
114 # Any non-empty lines must be from original preprocessed file.
115 # And this must be the first one.
117 LineIndexOfOriginalFile = Index
118 EdkLogger.verbose(" Found original
file content starting
from line
%d "
119 % (LineIndexOfOriginalFile + 1))
122 Line = gLongNumberPattern.sub(r" \
1 ", Line)
123 # convert HEX number format if indicated
125 Line = gHexNumberPattern.sub(r" 0 \
2 h
", Line)
127 Line = gHexNumberPattern.sub(r" \
1 \
2 ", Line)
129 # convert Decimal number format
130 Line = gDecNumberPattern.sub(r" \
1 ", Line)
132 if LineNumber is not None:
133 EdkLogger.verbose(" Got line directive
: line
= %d " % LineNumber)
134 # in case preprocessor removed some lines, like blank or comment lines
135 if LineNumber <= len(NewLines):
137 NewLines[LineNumber - 1] = Line
139 if LineNumber > (len(NewLines) + 1):
140 for LineIndex in range(len(NewLines), LineNumber-1):
141 NewLines.append(TAB_LINE_BREAK)
142 NewLines.append(Line)
144 EdkLogger.verbose(" Now we have lines
: %d " % len(NewLines))
146 NewLines.append(Line)
148 # in case there's no line directive or linemarker found
149 if (not LineControlDirectiveFound) and NewLines == []:
150 MulPatternFlag = False
151 SinglePatternFlag = False
153 for Index in range(len(Lines)):
155 if MulPatternFlag == False and gTypedef_MulPattern.search(Line) is None:
156 if SinglePatternFlag == False and gTypedef_SinglePattern.search(Line) is None:
157 # remove " #pragram pack" directive
158 if gPragmaPattern
. search ( Line
) is None :
159 NewLines
. append ( Line
)
161 elif SinglePatternFlag
== False :
162 SinglePatternFlag
= True
163 if Line
. find ( ";" ) >= 0 :
164 SinglePatternFlag
= False
165 elif MulPatternFlag
== False :
166 # found "typedef struct, typedef union, union, struct", keep its position and set a flag
167 MulPatternFlag
= True
169 # match { and } to find the end of typedef definition
170 if Line
. find ( "{" ) >= 0 :
172 elif Line
. find ( "}" ) >= 0 :
175 # "typedef struct, typedef union, union, struct" must end with a ";"
176 if Brace
== 0 and Line
. find ( ";" ) >= 0 :
177 MulPatternFlag
= False
181 with
open ( Target
, 'w' ) as File
:
182 File
. writelines ( NewLines
)
184 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= Target
)
186 ## Trim preprocessed VFR file
188 # Remove extra content made by preprocessor. The preprocessor doesn't need to
189 # enable line number generation option when preprocessing.
191 # @param Source File to be trimmed
192 # @param Target File to store the trimmed content
194 def TrimPreprocessedVfr ( Source
, Target
):
195 CreateDirectory ( os
. path
. dirname ( Target
))
198 with
open ( Source
, "r" ) as File
:
199 Lines
= File
. readlines ()
201 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= Source
)
208 for Index
in range ( len ( Lines
)):
210 # don't trim the lines from "formset" definition to the end of file
211 if Line
. strip () == 'formset' :
214 if FoundTypedef
== False and ( Line
. find ( '#line' ) == 0 or Line
. find ( '# ' ) == 0 ):
215 # empty the line number directive if it's not aomong "typedef struct"
219 if FoundTypedef
== False and gTypedefPattern
. search ( Line
) is None :
220 # keep "#pragram pack" directive
221 if gPragmaPattern
. search ( Line
) is None :
224 elif FoundTypedef
== False :
225 # found "typedef struct", keept its position and set a flag
229 # match { and } to find the end of typedef definition
230 if Line
. find ( "{" ) >= 0 :
232 elif Line
. find ( "}" ) >= 0 :
235 # "typedef struct" must end with a ";"
236 if Brace
== 0 and Line
. find ( ";" ) >= 0 :
239 # keep all "typedef struct" except to GUID, EFI_PLABEL and PAL_CALL_RETURN
240 if Line
. strip ( "} ; \r\n " ) in [ TAB_GUID
, "EFI_PLABEL" , "PAL_CALL_RETURN" ]:
241 for i
in range ( TypedefStart
, TypedefEnd
+ 1 ):
244 # save all lines trimmed
246 with
open ( Target
, 'w' ) as File
:
247 File
. writelines ( Lines
)
249 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= Target
)
251 ## Read the content ASL file, including ASL included, recursively
253 # @param Source File to be read
254 # @param Indent Spaces before the Include() statement
255 # @param IncludePathList The list of external include file
256 # @param LocalSearchPath If LocalSearchPath is specified, this path will be searched
257 # first for the included file; otherwise, only the path specified
258 # in the IncludePathList will be searched.
260 def DoInclude ( Source
, Indent
= '' , IncludePathList
=[], LocalSearchPath
= None , IncludeFileList
= None , filetype
= None ):
262 if IncludeFileList
is None :
266 # Search LocalSearchPath first if it is specified.
269 SearchPathList
= [ LocalSearchPath
] + IncludePathList
271 SearchPathList
= IncludePathList
273 for IncludePath
in SearchPathList
:
274 IncludeFile
= os
. path
. join ( IncludePath
, Source
)
275 if os
. path
. isfile ( IncludeFile
):
277 with
open ( IncludeFile
, "r" ) as File
:
280 with codecs
. open ( IncludeFile
, "r" , encoding
= 'utf-8' ) as File
:
284 EdkLogger
. warn ( "Trim" , "Failed to find include file %s " % Source
)
287 EdkLogger
. warn ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= Source
)
291 # avoid A "include" B and B "include" A
292 IncludeFile
= os
. path
. abspath ( os
. path
. normpath ( IncludeFile
))
293 if IncludeFile
in gIncludedAslFile
:
294 EdkLogger
. warn ( "Trim" , "Circular include" ,
295 ExtraData
= " %s -> %s " % ( " -> " . join ( gIncludedAslFile
), IncludeFile
))
297 gIncludedAslFile
. append ( IncludeFile
)
298 IncludeFileList
. append ( IncludeFile
. strip ())
300 LocalSearchPath
= None
301 if filetype
== "ASL" :
302 Result
= gAslIncludePattern
. findall ( Line
)
304 Result
= gAslCIncludePattern
. findall ( Line
)
305 if len ( Result
) == 0 or os
. path
. splitext ( Result
[ 0 ][ 1 ])[ 1 ]. lower () not in [ ".asl" , ".asi" ]:
306 NewFileContent
. append ( " %s%s " % ( Indent
, Line
))
309 # We should first search the local directory if current file are using pattern #include "XXX"
311 if Result
[ 0 ][ 2 ] == '"' :
312 LocalSearchPath
= os
. path
. dirname ( IncludeFile
)
313 CurrentIndent
= Indent
+ Result
[ 0 ][ 0 ]
314 IncludedFile
= Result
[ 0 ][ 1 ]
315 NewFileContent
. extend ( DoInclude ( IncludedFile
, CurrentIndent
, IncludePathList
, LocalSearchPath
, IncludeFileList
, filetype
))
316 NewFileContent
. append ( " \n " )
317 elif filetype
== "ASM" :
318 Result
= gIncludePattern
. findall ( Line
)
320 NewFileContent
. append ( " %s%s " % ( Indent
, Line
))
323 IncludedFile
= Result
[ 0 ]
325 IncludedFile
= IncludedFile
. strip ()
326 IncludedFile
= os
. path
. normpath ( IncludedFile
)
327 NewFileContent
. extend ( DoInclude ( IncludedFile
, '' , IncludePathList
, LocalSearchPath
, IncludeFileList
, filetype
))
328 NewFileContent
. append ( " \n " )
330 gIncludedAslFile
. pop ()
332 return NewFileContent
337 # Replace ASL include statement with the content the included file
339 # @param Source File to be trimmed
340 # @param Target File to store the trimmed content
341 # @param IncludePathFile The file to log the external include path
343 def TrimAslFile ( Source
, Target
, IncludePathFile
, AslDeps
= False ):
344 CreateDirectory ( os
. path
. dirname ( Target
))
346 SourceDir
= os
. path
. dirname ( Source
)
351 # Add source directory as the first search directory
353 IncludePathList
= [ SourceDir
]
356 # If additional include path file is specified, append them all
357 # to the search directory list.
362 with
open ( IncludePathFile
, 'r' ) as File
:
363 FileLines
= File
. readlines ()
364 for Line
in FileLines
:
366 if Line
. startswith ( "/I" ) or Line
. startswith ( "-I" ):
367 IncludePathList
. append ( Line
[ 2 :]. strip ())
369 EdkLogger
. warn ( "Trim" , "Invalid include line in include list file." , IncludePathFile
, LineNum
)
371 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= IncludePathFile
)
373 Lines
= DoInclude ( Source
, '' , IncludePathList
, IncludeFileList
= AslIncludes
, filetype
= 'ASL' )
374 AslIncludes
= [ item
for item
in AslIncludes
if item
!= Source
]
375 SaveFileOnChange ( os
. path
. join ( os
. path
. dirname ( Target
), os
. path
. basename ( Source
))+ ".trim.deps" , " \\\n " . join ([ Source
+ ":" ] + AslIncludes
), False )
378 # Undef MIN and MAX to avoid collision in ASL source code
380 Lines
. insert ( 0 , "#undef MIN \n #undef MAX \n " )
382 # save all lines trimmed
384 with
open ( Target
, 'w' ) as File
:
385 File
. writelines ( Lines
)
387 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= Target
)
391 # Output ASM include statement with the content the included file
393 # @param Source File to be trimmed
394 # @param Target File to store the trimmed content
395 # @param IncludePathFile The file to log the external include path
397 def TrimAsmFile ( Source
, Target
, IncludePathFile
):
398 CreateDirectory ( os
. path
. dirname ( Target
))
400 SourceDir
= os
. path
. dirname ( Source
)
405 # Add source directory as the first search directory
407 IncludePathList
= [ SourceDir
]
409 # If additional include path file is specified, append them all
410 # to the search directory list.
415 with
open ( IncludePathFile
, 'r' ) as File
:
416 FileLines
= File
. readlines ()
417 for Line
in FileLines
:
419 if Line
. startswith ( "/I" ) or Line
. startswith ( "-I" ):
420 IncludePathList
. append ( Line
[ 2 :]. strip ())
422 EdkLogger
. warn ( "Trim" , "Invalid include line in include list file." , IncludePathFile
, LineNum
)
424 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= IncludePathFile
)
426 Lines
= DoInclude ( Source
, '' , IncludePathList
, IncludeFileList
= AsmIncludes
, filetype
= 'ASM' )
427 AsmIncludes
= [ item
for item
in AsmIncludes
if item
!= Source
]
429 SaveFileOnChange ( os
. path
. join ( os
. path
. dirname ( Target
), os
. path
. basename ( Source
))+ ".trim.deps" , " \\\n " . join ([ Source
+ ":" ] + AsmIncludes
), False )
430 # save all lines trimmed
432 with
open ( Target
, 'w' ) as File
:
433 File
. writelines ( Lines
)
435 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, ExtraData
= Target
)
437 def GenerateVfrBinSec ( ModuleName
, DebugDir
, OutputFile
):
439 if os
. path
. isdir ( DebugDir
):
440 for CurrentDir
, Dirs
, Files
in os
. walk ( DebugDir
):
441 for FileName
in Files
:
442 Name
, Ext
= os
. path
. splitext ( FileName
)
443 if Ext
== '.c' and Name
!= 'AutoGen' :
444 VfrNameList
. append ( Name
+ 'Bin' )
446 VfrNameList
. append ( ModuleName
+ 'Strings' )
448 EfiFileName
= os
. path
. join ( DebugDir
, ModuleName
+ '.efi' )
449 MapFileName
= os
. path
. join ( DebugDir
, ModuleName
+ '.map' )
450 VfrUniOffsetList
= GetVariableOffset ( MapFileName
, EfiFileName
, VfrNameList
)
452 if not VfrUniOffsetList
:
456 fInputfile
= open ( OutputFile
, "wb+" )
458 EdkLogger
. error ( "Trim" , FILE_OPEN_FAILURE
, "File open failed for %s " % OutputFile
, None )
460 # Use a instance of BytesIO to cache data
461 fStringIO
= BytesIO ()
463 for Item
in VfrUniOffsetList
:
464 if ( Item
[ 0 ]. find ( "Strings" ) != - 1 ):
466 # UNI offset in image.
468 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
470 UniGuid
= b
' \xe0\xc5\x13\x89\xf6 3 \x86 M \x9b\xf1 C \xef\x89\xfc\x06 f'
471 fStringIO
. write ( UniGuid
)
472 UniValue
= pack ( 'Q' , int ( Item
[ 1 ], 16 ))
473 fStringIO
. write ( UniValue
)
476 # VFR binary offset in image.
478 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
480 VfrGuid
= b
' \xb4 | \xbc\xd0 Gj_I \xaa\x11 q \x07 F \xda\x06\xa2 '
481 fStringIO
. write ( VfrGuid
)
483 VfrValue
= pack ( 'Q' , int ( Item
[ 1 ], 16 ))
484 fStringIO
. write ( VfrValue
)
487 # write data into file.
490 fInputfile
. write ( fStringIO
. getvalue ())
492 EdkLogger
. error ( "Trim" , FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the file been locked or using by other applications." % OutputFile
, None )
498 ## Parse command line options
500 # Using standard Python module optparse to parse command line option of this tool.
502 # @retval Options A optparse.Values object containing the parsed options
503 # @retval InputFile Path of file to be trimmed
507 make_option ( "-s" , "--source-code" , dest
= "FileType" , const
= "SourceCode" , action
= "store_const" ,
508 help = "The input file is preprocessed source code, including C or assembly code" ),
509 make_option ( "-r" , "--vfr-file" , dest
= "FileType" , const
= "Vfr" , action
= "store_const" ,
510 help = "The input file is preprocessed VFR file" ),
511 make_option ( "--Vfr-Uni-Offset" , dest
= "FileType" , const
= "VfrOffsetBin" , action
= "store_const" ,
512 help = "The input file is EFI image" ),
513 make_option ( "--asl-deps" , dest
= "AslDeps" , const
= "True" , action
= "store_const" ,
514 help = "Generate Asl dependent files." ),
515 make_option ( "-a" , "--asl-file" , dest
= "FileType" , const
= "Asl" , action
= "store_const" ,
516 help = "The input file is ASL file" ),
517 make_option ( "--asm-file" , dest
= "FileType" , const
= "Asm" , action
= "store_const" ,
518 help = "The input file is asm file" ),
519 make_option ( "-c" , "--convert-hex" , dest
= "ConvertHex" , action
= "store_true" ,
520 help = "Convert standard hex format (0xabcd) to MASM format (abcdh)" ),
522 make_option ( "-l" , "--trim-long" , dest
= "TrimLong" , action
= "store_true" ,
523 help = "Remove postfix of long number" ),
524 make_option ( "-i" , "--include-path-file" , dest
= "IncludePathFile" ,
525 help = "The input file is include path list to search for ASL include file" ),
526 make_option ( "-o" , "--output" , dest
= "OutputFile" ,
527 help = "File to store the trimmed content" ),
528 make_option ( "--ModuleName" , dest
= "ModuleName" , help = "The module's BASE_NAME" ),
529 make_option ( "--DebugDir" , dest
= "DebugDir" ,
530 help = "Debug Output directory to store the output files" ),
531 make_option ( "-v" , "--verbose" , dest
= "LogLevel" , action
= "store_const" , const
= EdkLogger
. VERBOSE
,
532 help = "Run verbosely" ),
533 make_option ( "-d" , "--debug" , dest
= "LogLevel" , type = "int" ,
534 help = "Run with debug information" ),
535 make_option ( "-q" , "--quiet" , dest
= "LogLevel" , action
= "store_const" , const
= EdkLogger
. QUIET
,
537 make_option ( "-?" , action
= "help" , help = "show this help message and exit" ),
540 # use clearer usage to override default usage message
541 UsageString
= "%prog [-s|-r|-a|--Vfr-Uni-Offset] [-c] [-v|-d <debug_level>|-q] [-i <include_path_file>] [-o <output_file>] [--ModuleName <ModuleName>] [--DebugDir <DebugDir>] [<input_file>]"
543 Parser
= OptionParser ( description
= __copyright__
, version
= __version__
, option_list
= OptionList
, usage
= UsageString
)
544 Parser
. set_defaults ( FileType
= "Vfr" )
545 Parser
. set_defaults ( ConvertHex
= False )
546 Parser
. set_defaults ( LogLevel
= EdkLogger
. INFO
)
548 Options
, Args
= Parser
. parse_args ()
551 if Options
. FileType
== 'VfrOffsetBin' :
555 EdkLogger
. error ( "Trim" , OPTION_NOT_SUPPORTED
, ExtraData
= Parser
. get_usage ())
557 EdkLogger
. error ( "Trim" , OPTION_MISSING
, ExtraData
= Parser
. get_usage ())
559 EdkLogger
. error ( "Trim" , OPTION_NOT_SUPPORTED
, ExtraData
= Parser
. get_usage ())
562 return Options
, InputFile
566 # This method mainly dispatch specific methods per the command line options.
567 # If no error found, return zero value so the caller of this tool can know
568 # if it's executed successfully or not.
570 # @retval 0 Tool was successful
571 # @retval 1 Tool failed
575 EdkLogger
. Initialize ()
576 CommandOptions
, InputFile
= Options ()
577 if CommandOptions
. LogLevel
< EdkLogger
. DEBUG_9
:
578 EdkLogger
. SetLevel ( CommandOptions
. LogLevel
+ 1 )
580 EdkLogger
. SetLevel ( CommandOptions
. LogLevel
)
581 except FatalError
as X
:
585 if CommandOptions
. FileType
== "Vfr" :
586 if CommandOptions
. OutputFile
is None :
587 CommandOptions
. OutputFile
= os
. path
. splitext ( InputFile
)[ 0 ] + '.iii'
588 TrimPreprocessedVfr ( InputFile
, CommandOptions
. OutputFile
)
589 elif CommandOptions
. FileType
== "Asl" :
590 if CommandOptions
. OutputFile
is None :
591 CommandOptions
. OutputFile
= os
. path
. splitext ( InputFile
)[ 0 ] + '.iii'
592 TrimAslFile ( InputFile
, CommandOptions
. OutputFile
, CommandOptions
. IncludePathFile
, CommandOptions
. AslDeps
)
593 elif CommandOptions
. FileType
== "VfrOffsetBin" :
594 GenerateVfrBinSec ( CommandOptions
. ModuleName
, CommandOptions
. DebugDir
, CommandOptions
. OutputFile
)
595 elif CommandOptions
. FileType
== "Asm" :
596 TrimAsmFile ( InputFile
, CommandOptions
. OutputFile
, CommandOptions
. IncludePathFile
)
598 if CommandOptions
. OutputFile
is None :
599 CommandOptions
. OutputFile
= os
. path
. splitext ( InputFile
)[ 0 ] + '.iii'
600 TrimPreprocessedFile ( InputFile
, CommandOptions
. OutputFile
, CommandOptions
. ConvertHex
, CommandOptions
. TrimLong
)
601 except FatalError
as X
:
604 if CommandOptions
is not None and CommandOptions
. LogLevel
<= EdkLogger
. DEBUG_9
:
605 EdkLogger
. quiet ( "(Python %s on %s ) " % ( platform
. python_version (), sys
. platform
) + traceback
. format_exc ())
613 "Unknown fatal error when trimming [ %s ]" % InputFile
,
614 ExtraData
= " \n (Please send email to %s for help, attaching following call stack trace!) \n " % MSG_EDKII_MAIL_ADDR
,
617 EdkLogger
. quiet ( "(Python %s on %s ) " % ( platform
. python_version (), sys
. platform
) + traceback
. format_exc ())
622 if __name__
== '__main__' :
624 ## 0-127 is a safe return range, and 1 is a standard default error
625 if r
< 0 or r
> 127 : r
= 1