]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/InfSectionParser.py
2 # Parser a Inf file and Get specify section data.
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 import Common
.EdkLogger
as EdkLogger
12 from Common
.BuildToolError
import *
13 from Common
.DataType
import *
16 class InfSectionParser():
17 def __init__(self
, FilePath
):
18 self
._FilePath
= FilePath
19 self
._FileSectionDataList
= []
31 with
open(self
._FilePath
, "r") as File
:
32 FileLinesList
= File
.readlines()
34 EdkLogger
.error("build", AUTOGEN_ERROR
, 'File %s is opened failed.' % self
._FilePath
)
36 for Index
in range(0, len(FileLinesList
)):
37 line
= str(FileLinesList
[Index
]).strip()
38 if Index
+ 1 == len(FileLinesList
):
42 NextLine
= str(FileLinesList
[Index
+ 1]).strip()
43 if UserExtFind
and FindEnd
== False:
45 SectionData
.append(line
)
46 if line
.startswith(TAB_SECTION_START
) and line
.endswith(TAB_SECTION_END
):
51 if (NextLine
!= '' and NextLine
[0] == TAB_SECTION_START
and \
52 NextLine
[-1] == TAB_SECTION_END
) or FileLastLine
:
55 self
._FileSectionDataList
.append({SectionLine
: SectionData
[:]})
59 # Get user extension TianoCore data
61 # @return: a list include some dictionary that key is section and value is a list contain all data.
62 def GetUserExtensionTianoCore(self
):
63 UserExtensionTianoCore
= []
64 if not self
._FileSectionDataList
:
65 return UserExtensionTianoCore
66 for SectionDataDict
in self
._FileSectionDataList
:
67 for key
in SectionDataDict
:
68 if key
.lower().startswith("[userextensions") and key
.lower().find('.tianocore.') > -1:
69 SectionLine
= key
.lstrip(TAB_SECTION_START
).rstrip(TAB_SECTION_END
)
70 SubSectionList
= [SectionLine
]
71 if str(SectionLine
).find(TAB_COMMA_SPLIT
) > -1:
72 SubSectionList
= str(SectionLine
).split(TAB_COMMA_SPLIT
)
73 for SubSection
in SubSectionList
:
74 if SubSection
.lower().find('.tianocore.') > -1:
75 UserExtensionTianoCore
.append({SubSection
: SectionDataDict
[key
]})
76 return UserExtensionTianoCore
78 # Get depex expression
80 # @return: a list include some dictionary that key is section and value is a list contain all data.
81 def GetDepexExpresionList(self
):
82 DepexExpressionList
= []
83 if not self
._FileSectionDataList
:
84 return DepexExpressionList
85 for SectionDataDict
in self
._FileSectionDataList
:
86 for key
in SectionDataDict
:
87 if key
.lower() == "[depex]" or key
.lower().startswith("[depex."):
88 SectionLine
= key
.lstrip(TAB_SECTION_START
).rstrip(TAB_SECTION_END
)
89 SubSectionList
= [SectionLine
]
90 if str(SectionLine
).find(TAB_COMMA_SPLIT
) > -1:
91 SubSectionList
= str(SectionLine
).split(TAB_COMMA_SPLIT
)
92 for SubSection
in SubSectionList
:
93 SectionList
= SubSection
.split(TAB_SPLIT
)
95 if len(SectionList
) == 1:
96 SubKey
= (TAB_ARCH_COMMON
, TAB_ARCH_COMMON
)
97 elif len(SectionList
) == 2:
98 SubKey
= (SectionList
[1], TAB_ARCH_COMMON
)
99 elif len(SectionList
) == 3:
100 SubKey
= (SectionList
[1], SectionList
[2])
102 EdkLogger
.error("build", AUTOGEN_ERROR
, 'Section %s is invalid.' % key
)
103 DepexExpressionList
.append({SubKey
: SectionDataDict
[key
]})
104 return DepexExpressionList