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