]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Eot/InfParserLite.py
BaseTools: Remove the logic SourceOverridePath
[mirror_edk2.git] / BaseTools / Source / Python / Eot / InfParserLite.py
CommitLineData
52302d4d
LG
1## @file\r
2# This file is used to parse INF file of EDK project\r
3#\r
47f15da1 4# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
40d841f6 5# This program and the accompanying materials\r
52302d4d
LG
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14##\r
15# Import Modules\r
16#\r
72443dd2 17from __future__ import print_function\r
64429fbd 18from __future__ import absolute_import\r
44957929 19\r
1be2ed90 20import Common.LongFilePathOs as os\r
52302d4d
LG
21import Common.EdkLogger as EdkLogger\r
22from Common.DataType import *\r
23from CommonDataClass.DataClass import *\r
44957929 24from Eot.Identification import Identification\r
5a57246e 25from Common.StringUtils import *\r
47f15da1
HC
26from Eot.Parser import *\r
27from Eot import Database\r
28from Eot import EotGlobalData\r
52302d4d
LG
29\r
30## EdkInfParser() class\r
31#\r
32# This class defined basic INF object which is used by inheriting\r
33#\r
34# @param object: Inherited from object class\r
35#\r
36class EdkInfParser(object):\r
37 ## The constructor\r
38 #\r
39 # @param self: The object pointer\r
40 # @param Filename: INF file name\r
41 # @param Database: Eot database\r
42 # @param SourceFileList: A list for all source file belonging this INF file\r
52302d4d 43 #\r
2f2c51ac 44 def __init__(self, Filename = None, Database = None, SourceFileList = None):\r
52302d4d
LG
45 self.Identification = Identification()\r
46 self.Sources = []\r
47 self.Macros = {}\r
48\r
49 self.Cur = Database.Cur\r
50 self.TblFile = Database.TblFile\r
51 self.TblInf = Database.TblInf\r
52 self.FileID = -1\r
52302d4d
LG
53\r
54 # Load Inf file if filename is not None\r
4231a819 55 if Filename is not None:\r
52302d4d
LG
56 self.LoadInfFile(Filename)\r
57\r
58 if SourceFileList:\r
59 for Item in SourceFileList:\r
60 self.TblInf.Insert(MODEL_EFI_SOURCE_FILE, Item, '', '', '', '', 'COMMON', -1, self.FileID, -1, -1, -1, -1, 0)\r
61\r
62\r
63 ## LoadInffile() method\r
64 #\r
65 # Load INF file and insert a record in database\r
66 #\r
67 # @param self: The object pointer\r
68 # @param Filename: Input value for filename of Inf file\r
69 #\r
70 def LoadInfFile(self, Filename = None):\r
71 # Insert a record for file\r
72 Filename = NormPath(Filename)\r
73 self.Identification.FileFullPath = Filename\r
74 (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
75\r
76 self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_INF)\r
77\r
78 self.ParseInf(PreProcess(Filename, False), self.Identification.FileRelativePath, Filename)\r
79\r
80 ## ParserSource() method\r
81 #\r
82 # Parse Source section and insert records in database\r
83 #\r
84 # @param self: The object pointer\r
85 # @param CurrentSection: current section name\r
86 # @param SectionItemList: the item belonging current section\r
87 # @param ArchList: A list for arch for this section\r
88 # @param ThirdList: A list for third item for this section\r
89 #\r
90 def ParserSource(self, CurrentSection, SectionItemList, ArchList, ThirdList):\r
91 for Index in range(0, len(ArchList)):\r
92 Arch = ArchList[Index]\r
93 Third = ThirdList[Index]\r
94 if Arch == '':\r
95 Arch = TAB_ARCH_COMMON\r
96\r
97 for Item in SectionItemList:\r
98 if CurrentSection.upper() == 'defines'.upper():\r
99 (Name, Value) = AddToSelfMacro(self.Macros, Item[0])\r
100 self.TblInf.Insert(MODEL_META_DATA_HEADER, Name, Value, Third, '', '', Arch, -1, self.FileID, Item[1], -1, Item[1], -1, 0)\r
101\r
102 ## ParseInf() method\r
103 #\r
104 # Parse INF file and get sections information\r
105 #\r
106 # @param self: The object pointer\r
107 # @param Lines: contents of INF file\r
108 # @param FileRelativePath: relative path of the file\r
109 # @param Filename: file name of INF file\r
110 #\r
111 def ParseInf(self, Lines = [], FileRelativePath = '', Filename = ''):\r
112 IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \\r
113 [], [], TAB_UNKNOWN, [], [], []\r
114 LineNo = 0\r
115\r
116 for Line in Lines:\r
117 LineNo = LineNo + 1\r
118 if Line == '':\r
119 continue\r
120 if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
121 self.ParserSource(CurrentSection, SectionItemList, ArchList, ThirdList)\r
122\r
123 # Parse the new section\r
124 SectionItemList = []\r
125 ArchList = []\r
126 ThirdList = []\r
127 # Parse section name\r
128 CurrentSection = ''\r
129 LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
130 for Item in LineList:\r
131 ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
132 if CurrentSection == '':\r
133 CurrentSection = ItemList[0]\r
134 else:\r
135 if CurrentSection != ItemList[0]:\r
136 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)\r
137 ItemList.append('')\r
138 ItemList.append('')\r
139 if len(ItemList) > 5:\r
140 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
141 else:\r
142 ArchList.append(ItemList[1].upper())\r
143 ThirdList.append(ItemList[2])\r
144\r
145 continue\r
146\r
147 # Add a section item\r
148 SectionItemList.append([Line, LineNo])\r
149 # End of parse\r
150\r
151 self.ParserSource(CurrentSection, SectionItemList, ArchList, ThirdList)\r
152 #End of For\r
153\r
47f15da1 154\r