]>
Commit | Line | Data |
---|---|---|
97fa0ee9 YL |
1 | ## @file\r |
2 | # Parser a Inf file and Get specify section data.\r | |
3 | #\r | |
9eb87141 | 4 | # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
97fa0ee9 YL |
5 | # This program and the accompanying materials\r |
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 | ## Import Modules\r | |
15 | #\r | |
16 | \r | |
17 | import Common.EdkLogger as EdkLogger\r | |
18 | from Common.BuildToolError import *\r | |
19 | from Common.DataType import *\r | |
f7496d71 | 20 | \r |
97fa0ee9 YL |
21 | \r |
22 | class InfSectionParser():\r | |
23 | def __init__(self, FilePath):\r | |
24 | self._FilePath = FilePath\r | |
25 | self._FileSectionDataList = []\r | |
26 | self._ParserInf()\r | |
f7496d71 | 27 | \r |
97fa0ee9 | 28 | def _ParserInf(self):\r |
97fa0ee9 YL |
29 | FileLinesList = []\r |
30 | UserExtFind = False\r | |
31 | FindEnd = True\r | |
32 | FileLastLine = False\r | |
33 | SectionLine = ''\r | |
34 | SectionData = []\r | |
f7496d71 | 35 | \r |
97fa0ee9 | 36 | try:\r |
1ccc4d89 | 37 | FileLinesList = open(self._FilePath, "r", 0).readlines()\r |
97fa0ee9 | 38 | except BaseException:\r |
6c2d8cb2 | 39 | EdkLogger.error("build", AUTOGEN_ERROR, 'File %s is opened failed.' % self._FilePath)\r |
f7496d71 | 40 | \r |
97fa0ee9 YL |
41 | for Index in range(0, len(FileLinesList)):\r |
42 | line = str(FileLinesList[Index]).strip()\r | |
43 | if Index + 1 == len(FileLinesList):\r | |
44 | FileLastLine = True\r | |
45 | NextLine = ''\r | |
46 | else:\r | |
47 | NextLine = str(FileLinesList[Index + 1]).strip()\r | |
48 | if UserExtFind and FindEnd == False:\r | |
49 | if line:\r | |
50 | SectionData.append(line)\r | |
6c2d8cb2 | 51 | if line.startswith(TAB_SECTION_START) and line.endswith(TAB_SECTION_END):\r |
97fa0ee9 YL |
52 | SectionLine = line\r |
53 | UserExtFind = True\r | |
54 | FindEnd = False\r | |
f7496d71 | 55 | \r |
97fa0ee9 YL |
56 | if (NextLine != '' and NextLine[0] == TAB_SECTION_START and \\r |
57 | NextLine[-1] == TAB_SECTION_END) or FileLastLine:\r | |
58 | UserExtFind = False\r | |
59 | FindEnd = True\r | |
60 | self._FileSectionDataList.append({SectionLine: SectionData[:]})\r | |
6c2d8cb2 | 61 | del SectionData[:]\r |
97fa0ee9 | 62 | SectionLine = ''\r |
f7496d71 | 63 | \r |
dfa41b4a YZ |
64 | # Get user extension TianoCore data\r |
65 | #\r | |
66 | # @return: a list include some dictionary that key is section and value is a list contain all data.\r | |
67 | def GetUserExtensionTianoCore(self):\r | |
68 | UserExtensionTianoCore = []\r | |
69 | if not self._FileSectionDataList:\r | |
70 | return UserExtensionTianoCore\r | |
71 | for SectionDataDict in self._FileSectionDataList:\r | |
9eb87141 | 72 | for key in SectionDataDict:\r |
dfa41b4a YZ |
73 | if key.lower().startswith("[userextensions") and key.lower().find('.tianocore.') > -1:\r |
74 | SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END)\r | |
75 | SubSectionList = [SectionLine]\r | |
76 | if str(SectionLine).find(TAB_COMMA_SPLIT) > -1:\r | |
77 | SubSectionList = str(SectionLine).split(TAB_COMMA_SPLIT)\r | |
78 | for SubSection in SubSectionList:\r | |
79 | if SubSection.lower().find('.tianocore.') > -1:\r | |
80 | UserExtensionTianoCore.append({SubSection: SectionDataDict[key]})\r | |
81 | return UserExtensionTianoCore\r | |
97fa0ee9 YL |
82 | \r |
83 | # Get depex expresion\r | |
84 | #\r | |
85 | # @return: a list include some dictionary that key is section and value is a list contain all data.\r | |
86 | def GetDepexExpresionList(self):\r | |
87 | DepexExpresionList = []\r | |
88 | if not self._FileSectionDataList:\r | |
89 | return DepexExpresionList\r | |
90 | for SectionDataDict in self._FileSectionDataList:\r | |
9eb87141 | 91 | for key in SectionDataDict:\r |
97fa0ee9 YL |
92 | if key.lower() == "[depex]" or key.lower().startswith("[depex."):\r |
93 | SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END)\r | |
94 | SubSectionList = [SectionLine]\r | |
95 | if str(SectionLine).find(TAB_COMMA_SPLIT) > -1:\r | |
96 | SubSectionList = str(SectionLine).split(TAB_COMMA_SPLIT)\r | |
97 | for SubSection in SubSectionList:\r | |
98 | SectionList = SubSection.split(TAB_SPLIT)\r | |
99 | SubKey = ()\r | |
100 | if len(SectionList) == 1:\r | |
101 | SubKey = (TAB_ARCH_COMMON, TAB_ARCH_COMMON)\r | |
102 | elif len(SectionList) == 2:\r | |
103 | SubKey = (SectionList[1], TAB_ARCH_COMMON)\r | |
104 | elif len(SectionList) == 3:\r | |
105 | SubKey = (SectionList[1], SectionList[2])\r | |
106 | else:\r | |
107 | EdkLogger.error("build", AUTOGEN_ERROR, 'Section %s is invalid.' % key)\r | |
108 | DepexExpresionList.append({SubKey: SectionDataDict[key]})\r | |
109 | return DepexExpresionList\r | |
110 | \r | |
111 | \r | |
112 | \r | |
113 | \r | |
114 | \r | |
115 | \r | |
116 | \r | |
117 | \r | |
118 | \r | |
119 | \r | |
120 | \r | |
121 | \r | |
122 | \r | |
123 | \r | |
124 | \r |