2 # This file contained the parser for [Depex] sections in INF file
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 import Logger
.Log
as Logger
22 from Logger
import StringTable
as ST
23 from Logger
.ToolError
import FORMAT_INVALID
24 from Parser
.InfParserMisc
import InfExpandMacro
25 from Library
import DataType
as DT
26 from Library
.Misc
import GetSplitValueList
27 from Parser
.InfParserMisc
import InfParserSectionRoot
29 class InfDepexSectionParser(InfParserSectionRoot
):
32 # For now, only separate Depex String and comments.
33 # Have two types of section header.
34 # 1. [Depex.Arch.ModuleType, ...]
35 # 2. [Depex.Arch|FFE, ...]
37 def InfDepexParser(self
, SectionString
, InfSectionObject
, FileName
):
42 # Parse section content
44 for Line
in SectionString
:
51 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
52 DepexComment
.append((LineContent
, LineNo
))
55 # Replace with [Defines] section Macro
57 LineContent
= InfExpandMacro(LineContent
,
58 (FileName
, LineContent
, Line
[1]),
62 CommentCount
= LineContent
.find(DT
.TAB_COMMENT_SPLIT
)
65 DepexComment
.append((LineContent
[CommentCount
:], LineNo
))
66 LineContent
= LineContent
[:CommentCount
-1]
70 DepexContent
.append((LineContent
, LineNo
))
72 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_COMMENT_SPLIT
)
73 ValueList
[0:len(TokenList
)] = TokenList
76 # Current section archs
80 for Item
in self
.LastSectionHeaderContent
:
82 if (Item
[1], Item
[2], Item
[3]) not in KeyList
:
83 KeyList
.append((Item
[1], Item
[2], Item
[3]))
87 ReFormatComment
= re
.compile(r
"""#(?:\s*)\[(.*?)\](?:.*)""", re
.DOTALL
)
88 for CommentItem
in DepexComment
:
89 CommentContent
= CommentItem
[0]
90 if ReFormatComment
.match(CommentContent
) != None:
91 FormatCommentLn
= CommentItem
[1] + 1
94 if CommentItem
[1] != FormatCommentLn
:
95 NewCommentList
.append(CommentContent
)
97 FormatCommentLn
= CommentItem
[1] + 1
99 if not InfSectionObject
.SetDepex(DepexContent
, KeyList
= KeyList
, CommentList
= NewCommentList
):
100 Logger
.Error('InfParser',
102 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[Depex]"),