]>
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 - 2018, 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 *
25 from Eot
. Parser
import *
26 from Eot
import Database
27 from Eot
import EotGlobalData
29 ## EdkInfParser() class
31 # This class defined basic INF object which is used by inheriting
33 # @param object: Inherited from object class
35 class EdkInfParser ( object ):
38 # @param self: The object pointer
39 # @param Filename: INF file name
40 # @param Database: Eot database
41 # @param SourceFileList: A list for all source file belonging this INF file
42 # @param SourceOverridePath: Override path for source file
43 # @param Edk_Source: Envirnoment variable EDK_SOURCE
44 # @param Efi_Source: Envirnoment variable EFI_SOURCE
46 def __init__ ( self
, Filename
= None , Database
= None , SourceFileList
= None , SourceOverridePath
= None , Edk_Source
= None , Efi_Source
= None ):
47 self
. Identification
= Identification ()
51 self
. Cur
= Database
. Cur
52 self
. TblFile
= Database
. TblFile
53 self
. TblInf
= Database
. TblInf
55 self
. SourceOverridePath
= SourceOverridePath
57 # Load Inf file if filename is not None
58 if Filename
is not None :
59 self
. LoadInfFile ( Filename
)
62 for Item
in SourceFileList
:
63 self
. TblInf
. Insert ( MODEL_EFI_SOURCE_FILE
, Item
, '' , '' , '' , '' , 'COMMON' , - 1 , self
. FileID
, - 1 , - 1 , - 1 , - 1 , 0 )
66 ## LoadInffile() method
68 # Load INF file and insert a record in database
70 # @param self: The object pointer
71 # @param Filename: Input value for filename of Inf file
73 def LoadInfFile ( self
, Filename
= None ):
74 # Insert a record for file
75 Filename
= NormPath ( Filename
)
76 self
. Identification
. FileFullPath
= Filename
77 ( self
. Identification
. FileRelativePath
, self
. Identification
. FileName
) = os
. path
. split ( Filename
)
79 self
. FileID
= self
. TblFile
. InsertFile ( Filename
, MODEL_FILE_INF
)
81 self
. ParseInf ( PreProcess ( Filename
, False ), self
. Identification
. FileRelativePath
, Filename
)
83 ## ParserSource() method
85 # Parse Source section and insert records in database
87 # @param self: The object pointer
88 # @param CurrentSection: current section name
89 # @param SectionItemList: the item belonging current section
90 # @param ArchList: A list for arch for this section
91 # @param ThirdList: A list for third item for this section
93 def ParserSource ( self
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
):
94 for Index
in range ( 0 , len ( ArchList
)):
95 Arch
= ArchList
[ Index
]
96 Third
= ThirdList
[ Index
]
98 Arch
= TAB_ARCH_COMMON
100 for Item
in SectionItemList
:
101 if CurrentSection
. upper () == 'defines' . upper ():
102 ( Name
, Value
) = AddToSelfMacro ( self
. Macros
, Item
[ 0 ])
103 self
. TblInf
. Insert ( MODEL_META_DATA_HEADER
, Name
, Value
, Third
, '' , '' , Arch
, - 1 , self
. FileID
, Item
[ 1 ], - 1 , Item
[ 1 ], - 1 , 0 )
107 # Parse INF file and get sections information
109 # @param self: The object pointer
110 # @param Lines: contents of INF file
111 # @param FileRelativePath: relative path of the file
112 # @param Filename: file name of INF file
114 def ParseInf ( self
, Lines
= [], FileRelativePath
= '' , Filename
= '' ):
115 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
116 [], [], TAB_UNKNOWN
, [], [], []
123 if Line
. startswith ( TAB_SECTION_START
) and Line
. endswith ( TAB_SECTION_END
):
124 self
. ParserSource ( CurrentSection
, SectionItemList
, ArchList
, ThirdList
)
126 # Parse the new section
132 LineList
= GetSplitValueList ( Line
[ len ( TAB_SECTION_START
): len ( Line
) - len ( TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
133 for Item
in LineList
:
134 ItemList
= GetSplitValueList ( Item
, TAB_SPLIT
)
135 if CurrentSection
== '' :
136 CurrentSection
= ItemList
[ 0 ]
138 if CurrentSection
!= ItemList
[ 0 ]:
139 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
)
142 if len ( ItemList
) > 5 :
143 RaiseParserError ( Line
, CurrentSection
, Filename
, '' , LineNo
)
145 ArchList
. append ( ItemList
[ 1 ]. upper ())
146 ThirdList
. append ( ItemList
[ 2 ])
151 SectionItemList
. append ([ Line
, LineNo
])
154 self
. ParserSource ( CurrentSection
, SectionItemList
, ArchList
, ThirdList
)