]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Eot/InfParserLite.py
2 # This file is used to parse INF file of EDK project
4 # Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
5 # 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
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.
17 from __future__
import print_function
18 from __future__
import absolute_import
19 import Common
. LongFilePathOs
as os
20 import Common
. EdkLogger
as EdkLogger
21 from Common
. DataType
import *
22 from CommonDataClass
. DataClass
import *
23 from Common
. Identification
import *
24 from Common
. StringUtils
import *
26 from . import Database
28 ## EdkInfParser() class
30 # This class defined basic INF object which is used by inheriting
32 # @param object: Inherited from object class
34 class EdkInfParser ( object ):
37 # @param self: The object pointer
38 # @param Filename: INF file name
39 # @param Database: Eot database
40 # @param SourceFileList: A list for all source file belonging this INF file
41 # @param SourceOverridePath: Override path for source file
42 # @param Edk_Source: Envirnoment variable EDK_SOURCE
43 # @param Efi_Source: Envirnoment variable EFI_SOURCE
45 def __init__ ( self
, Filename
= None , Database
= None , SourceFileList
= None , SourceOverridePath
= None , Edk_Source
= None , Efi_Source
= None ):
46 self
. Identification
= Identification ()
50 self
. Cur
= Database
. Cur
51 self
. TblFile
= Database
. TblFile
52 self
. TblInf
= Database
. TblInf
54 self
. SourceOverridePath
= SourceOverridePath
56 # Load Inf file if filename is not None
57 if Filename
is not None :
58 self
. LoadInfFile ( Filename
)
61 for Item
in SourceFileList
:
62 self
. TblInf
. Insert ( MODEL_EFI_SOURCE_FILE
, Item
, '' , '' , '' , '' , 'COMMON' , - 1 , self
. FileID
, - 1 , - 1 , - 1 , - 1 , 0 )
65 ## LoadInffile() method
67 # Load INF file and insert a record in database
69 # @param self: The object pointer
70 # @param Filename: Input value for filename of Inf file
72 def LoadInfFile ( self
, Filename
= None ):
73 # Insert a record for file
74 Filename
= NormPath ( Filename
)
75 self
. Identification
. FileFullPath
= Filename
76 ( self
. Identification
. FileRelativePath
, self
. Identification
. FileName
) = os
. path
. split ( Filename
)
78 self
. FileID
= self
. TblFile
. InsertFile ( Filename
, MODEL_FILE_INF
)
80 self
. ParseInf ( PreProcess ( Filename
, False ), self
. Identification
. FileRelativePath
, Filename
)
82 ## ParserSource() method
84 # Parse Source section and insert records in database
86 # @param self: The object pointer
87 # @param CurrentSection: current section name
88 # @param SectionItemList: the item belonging current section
89 # @param ArchList: A list for arch for this section
90 # @param ThirdList: A list for third item for this section
92 def ParserSource ( self
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
):
93 for Index
in range ( 0 , len ( ArchList
)):
94 Arch
= ArchList
[ Index
]
95 Third
= ThirdList
[ Index
]
97 Arch
= TAB_ARCH_COMMON
99 for Item
in SectionItemList
:
100 if CurrentSection
. upper () == 'defines' . upper ():
101 ( Name
, Value
) = AddToSelfMacro ( self
. Macros
, Item
[ 0 ])
102 self
. TblInf
. Insert ( MODEL_META_DATA_HEADER
, Name
, Value
, Third
, '' , '' , Arch
, - 1 , self
. FileID
, Item
[ 1 ], - 1 , Item
[ 1 ], - 1 , 0 )
106 # Parse INF file and get sections information
108 # @param self: The object pointer
109 # @param Lines: contents of INF file
110 # @param FileRelativePath: relative path of the file
111 # @param Filename: file name of INF file
113 def ParseInf ( self
, Lines
= [], FileRelativePath
= '' , Filename
= '' ):
114 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
115 [], [], TAB_UNKNOWN
, [], [], []
122 if Line
. startswith ( TAB_SECTION_START
) and Line
. endswith ( TAB_SECTION_END
):
123 self
. ParserSource ( CurrentSection
, SectionItemList
, ArchList
, ThirdList
)
125 # Parse the new section
131 LineList
= GetSplitValueList ( Line
[ len ( TAB_SECTION_START
): len ( Line
) - len ( TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
132 for Item
in LineList
:
133 ItemList
= GetSplitValueList ( Item
, TAB_SPLIT
)
134 if CurrentSection
== '' :
135 CurrentSection
= ItemList
[ 0 ]
137 if CurrentSection
!= ItemList
[ 0 ]:
138 EdkLogger
. error ( "Parser" , PARSER_ERROR
, "Different section names ' %s ' and ' %s ' are found in one section definition, this is not allowed." % ( CurrentSection
, ItemList
[ 0 ]), File
= Filename
, Line
= LineNo
)
141 if len ( ItemList
) > 5 :
142 RaiseParserError ( Line
, CurrentSection
, Filename
, '' , LineNo
)
144 ArchList
. append ( ItemList
[ 1 ]. upper ())
145 ThirdList
. append ( ItemList
[ 2 ])
150 SectionItemList
. append ([ Line
, LineNo
])
153 self
. ParserSource ( CurrentSection
, SectionItemList
, ArchList
, ThirdList
)
158 # This acts like the main() function for the script, unless it is 'import'ed into another
161 if __name__
== '__main__' :
162 EdkLogger
. Initialize ()
163 EdkLogger
. SetLevel ( EdkLogger
. QUIET
)
165 Db
= Database
. Database ( 'Inf.db' )
167 P
= EdkInfParser ( os
. path
. normpath ( "C:\Framework\Edk\Sample\Platform\Nt32\Dxe\PlatformBds\PlatformBds.inf" ), Db
, '' , '' )
168 for Inf
in P
. Sources
:
170 for Item
in P
. Macros
:
171 print ( Item
, P
. Macros
[ Item
])