]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/AutoGen/InfSectionParser.py
BaseTools: add new command line option to support override PCD value
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / InfSectionParser.py
CommitLineData
97fa0ee9
YL
1## @file\r
2# Parser a Inf file and Get specify section data.\r
3#\r
4# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
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
17import Common.EdkLogger as EdkLogger\r
18from Common.BuildToolError import *\r
19from Common.DataType import *\r
20 \r
21\r
22class InfSectionParser():\r
23 def __init__(self, FilePath):\r
24 self._FilePath = FilePath\r
25 self._FileSectionDataList = []\r
26 self._ParserInf()\r
27 \r
28 def _ParserInf(self):\r
29 Filename = self._FilePath\r
30 FileLinesList = []\r
31 UserExtFind = False\r
32 FindEnd = True\r
33 FileLastLine = False\r
34 SectionLine = ''\r
35 SectionData = []\r
36 \r
37 try:\r
38 FileLinesList = open(Filename, "r", 0).readlines()\r
39 except BaseException:\r
40 EdkLogger.error("build", AUTOGEN_ERROR, 'File %s is opened failed.' % Filename)\r
41 \r
42 for Index in range(0, len(FileLinesList)):\r
43 line = str(FileLinesList[Index]).strip()\r
44 if Index + 1 == len(FileLinesList):\r
45 FileLastLine = True\r
46 NextLine = ''\r
47 else:\r
48 NextLine = str(FileLinesList[Index + 1]).strip()\r
49 if UserExtFind and FindEnd == False:\r
50 if line:\r
51 SectionData.append(line)\r
52 if line.lower().startswith(TAB_SECTION_START) and line.lower().endswith(TAB_SECTION_END):\r
53 SectionLine = line\r
54 UserExtFind = True\r
55 FindEnd = False\r
56 \r
57 if (NextLine != '' and NextLine[0] == TAB_SECTION_START and \\r
58 NextLine[-1] == TAB_SECTION_END) or FileLastLine:\r
59 UserExtFind = False\r
60 FindEnd = True\r
61 self._FileSectionDataList.append({SectionLine: SectionData[:]})\r
62 SectionData = []\r
63 SectionLine = ''\r
64 \r
65\r
66 # Get depex expresion\r
67 #\r
68 # @return: a list include some dictionary that key is section and value is a list contain all data.\r
69 def GetDepexExpresionList(self):\r
70 DepexExpresionList = []\r
71 if not self._FileSectionDataList:\r
72 return DepexExpresionList\r
73 for SectionDataDict in self._FileSectionDataList:\r
74 for key in SectionDataDict.keys():\r
75 if key.lower() == "[depex]" or key.lower().startswith("[depex."):\r
76 SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END)\r
77 SubSectionList = [SectionLine]\r
78 if str(SectionLine).find(TAB_COMMA_SPLIT) > -1:\r
79 SubSectionList = str(SectionLine).split(TAB_COMMA_SPLIT)\r
80 for SubSection in SubSectionList:\r
81 SectionList = SubSection.split(TAB_SPLIT)\r
82 SubKey = ()\r
83 if len(SectionList) == 1:\r
84 SubKey = (TAB_ARCH_COMMON, TAB_ARCH_COMMON)\r
85 elif len(SectionList) == 2:\r
86 SubKey = (SectionList[1], TAB_ARCH_COMMON)\r
87 elif len(SectionList) == 3:\r
88 SubKey = (SectionList[1], SectionList[2])\r
89 else:\r
90 EdkLogger.error("build", AUTOGEN_ERROR, 'Section %s is invalid.' % key)\r
91 DepexExpresionList.append({SubKey: SectionDataDict[key]})\r
92 return DepexExpresionList\r
93\r
94\r
95\r
96\r
97\r
98\r
99\r
100\r
101\r
102\r
103\r
104\r
105\r
106\r
107\r