]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Eot/InfParserLite.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / Eot / InfParserLite.py
1 ## @file
2 # This file is used to parse INF file of EDK project
3 #
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
9 #
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.
12 #
13
14 ##
15 # Import Modules
16 #
17 from __future__ import print_function
18 from __future__ import absolute_import
19
20 import Common.LongFilePathOs as os
21 import Common.EdkLogger as EdkLogger
22 from Common.DataType import *
23 from CommonDataClass.DataClass import *
24 from Eot.Identification import Identification
25 from Common.StringUtils import *
26 from Eot.Parser import *
27 from Eot import Database
28 from Eot import EotGlobalData
29
30 ## EdkInfParser() class
31 #
32 # This class defined basic INF object which is used by inheriting
33 #
34 # @param object: Inherited from object class
35 #
36 class EdkInfParser(object):
37 ## The constructor
38 #
39 # @param self: The object pointer
40 # @param Filename: INF file name
41 # @param Database: Eot database
42 # @param SourceFileList: A list for all source file belonging this INF file
43 # @param SourceOverridePath: Override path for source file
44 # @param Edk_Source: Environment variable EDK_SOURCE
45 # @param Efi_Source: Environment variable EFI_SOURCE
46 #
47 def __init__(self, Filename = None, Database = None, SourceFileList = None, SourceOverridePath = None, Edk_Source = None, Efi_Source = None):
48 self.Identification = Identification()
49 self.Sources = []
50 self.Macros = {}
51
52 self.Cur = Database.Cur
53 self.TblFile = Database.TblFile
54 self.TblInf = Database.TblInf
55 self.FileID = -1
56 self.SourceOverridePath = SourceOverridePath
57
58 # Load Inf file if filename is not None
59 if Filename is not None:
60 self.LoadInfFile(Filename)
61
62 if SourceFileList:
63 for Item in SourceFileList:
64 self.TblInf.Insert(MODEL_EFI_SOURCE_FILE, Item, '', '', '', '', 'COMMON', -1, self.FileID, -1, -1, -1, -1, 0)
65
66
67 ## LoadInffile() method
68 #
69 # Load INF file and insert a record in database
70 #
71 # @param self: The object pointer
72 # @param Filename: Input value for filename of Inf file
73 #
74 def LoadInfFile(self, Filename = None):
75 # Insert a record for file
76 Filename = NormPath(Filename)
77 self.Identification.FileFullPath = Filename
78 (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)
79
80 self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_INF)
81
82 self.ParseInf(PreProcess(Filename, False), self.Identification.FileRelativePath, Filename)
83
84 ## ParserSource() method
85 #
86 # Parse Source section and insert records in database
87 #
88 # @param self: The object pointer
89 # @param CurrentSection: current section name
90 # @param SectionItemList: the item belonging current section
91 # @param ArchList: A list for arch for this section
92 # @param ThirdList: A list for third item for this section
93 #
94 def ParserSource(self, CurrentSection, SectionItemList, ArchList, ThirdList):
95 for Index in range(0, len(ArchList)):
96 Arch = ArchList[Index]
97 Third = ThirdList[Index]
98 if Arch == '':
99 Arch = TAB_ARCH_COMMON
100
101 for Item in SectionItemList:
102 if CurrentSection.upper() == 'defines'.upper():
103 (Name, Value) = AddToSelfMacro(self.Macros, Item[0])
104 self.TblInf.Insert(MODEL_META_DATA_HEADER, Name, Value, Third, '', '', Arch, -1, self.FileID, Item[1], -1, Item[1], -1, 0)
105
106 ## ParseInf() method
107 #
108 # Parse INF file and get sections information
109 #
110 # @param self: The object pointer
111 # @param Lines: contents of INF file
112 # @param FileRelativePath: relative path of the file
113 # @param Filename: file name of INF file
114 #
115 def ParseInf(self, Lines = [], FileRelativePath = '', Filename = ''):
116 IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \
117 [], [], TAB_UNKNOWN, [], [], []
118 LineNo = 0
119
120 for Line in Lines:
121 LineNo = LineNo + 1
122 if Line == '':
123 continue
124 if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):
125 self.ParserSource(CurrentSection, SectionItemList, ArchList, ThirdList)
126
127 # Parse the new section
128 SectionItemList = []
129 ArchList = []
130 ThirdList = []
131 # Parse section name
132 CurrentSection = ''
133 LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)
134 for Item in LineList:
135 ItemList = GetSplitValueList(Item, TAB_SPLIT)
136 if CurrentSection == '':
137 CurrentSection = ItemList[0]
138 else:
139 if CurrentSection != ItemList[0]:
140 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 ItemList.append('')
142 ItemList.append('')
143 if len(ItemList) > 5:
144 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)
145 else:
146 ArchList.append(ItemList[1].upper())
147 ThirdList.append(ItemList[2])
148
149 continue
150
151 # Add a section item
152 SectionItemList.append([Line, LineNo])
153 # End of parse
154
155 self.ParserSource(CurrentSection, SectionItemList, ArchList, ThirdList)
156 #End of For
157
158