2 # This file contained the parser for [Depex] sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 import Logger
.Log
as Logger
16 from Logger
import StringTable
as ST
17 from Logger
.ToolError
import FORMAT_INVALID
18 from Parser
.InfParserMisc
import InfExpandMacro
19 from Library
import DataType
as DT
20 from Library
.Misc
import GetSplitValueList
21 from Parser
.InfParserMisc
import InfParserSectionRoot
23 class InfDepexSectionParser(InfParserSectionRoot
):
26 # For now, only separate Depex String and comments.
27 # Have two types of section header.
28 # 1. [Depex.Arch.ModuleType, ...]
29 # 2. [Depex.Arch|FFE, ...]
31 def InfDepexParser(self
, SectionString
, InfSectionObject
, FileName
):
36 # Parse section content
38 for Line
in SectionString
:
45 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
46 DepexComment
.append((LineContent
, LineNo
))
49 # Replace with [Defines] section Macro
51 LineContent
= InfExpandMacro(LineContent
,
52 (FileName
, LineContent
, Line
[1]),
56 CommentCount
= LineContent
.find(DT
.TAB_COMMENT_SPLIT
)
59 DepexComment
.append((LineContent
[CommentCount
:], LineNo
))
60 LineContent
= LineContent
[:CommentCount
-1]
64 DepexContent
.append((LineContent
, LineNo
))
66 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_COMMENT_SPLIT
)
67 ValueList
[0:len(TokenList
)] = TokenList
70 # Current section archs
74 for Item
in self
.LastSectionHeaderContent
:
76 if (Item
[1], Item
[2], Item
[3]) not in KeyList
:
77 KeyList
.append((Item
[1], Item
[2], Item
[3]))
81 ReFormatComment
= re
.compile(r
"""#(?:\s*)\[(.*?)\](?:.*)""", re
.DOTALL
)
82 for CommentItem
in DepexComment
:
83 CommentContent
= CommentItem
[0]
84 if ReFormatComment
.match(CommentContent
) is not None:
85 FormatCommentLn
= CommentItem
[1] + 1
88 if CommentItem
[1] != FormatCommentLn
:
89 NewCommentList
.append(CommentContent
)
91 FormatCommentLn
= CommentItem
[1] + 1
93 if not InfSectionObject
.SetDepex(DepexContent
, KeyList
= KeyList
, CommentList
= NewCommentList
):
94 Logger
.Error('InfParser',
96 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[Depex]"),