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