1## @file 2# This file contained the parser for [Depex] sections in INF file 3# 4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR> 5# 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 10# 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. 13# 14''' 15InfDepexSectionParser 16''' 17## 18# Import Modules 19# 20import re 21import Logger.Log as Logger 22from Logger import StringTable as ST 23from Logger.ToolError import FORMAT_INVALID 24from Parser.InfParserMisc import InfExpandMacro 25from Library import DataType as DT 26from Library.Misc import GetSplitValueList 27from Parser.InfParserMisc import InfParserSectionRoot 28 29class InfDepexSectionParser(InfParserSectionRoot): 30 ## InfDepexParser 31 # 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, ...] 36 # 37 def InfDepexParser(self, SectionString, InfSectionObject, FileName): 38 DepexContent = [] 39 DepexComment = [] 40 ValueList = [] 41 # 42 # Parse section content 43 # 44 for Line in SectionString: 45 LineContent = Line[0] 46 LineNo = Line[1] 47 48 # 49 # Found comment 50 # 51 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): 52 DepexComment.append((LineContent, LineNo)) 53 continue 54 # 55 # Replace with [Defines] section Macro 56 # 57 LineContent = InfExpandMacro(LineContent, 58 (FileName, LineContent, Line[1]), 59 self.FileLocalMacros, 60 None, True) 61 62 CommentCount = LineContent.find(DT.TAB_COMMENT_SPLIT) 63 64 if CommentCount > -1: 65 DepexComment.append((LineContent[CommentCount:], LineNo)) 66 LineContent = LineContent[:CommentCount-1] 67 68 69 CommentCount = -1 70 DepexContent.append((LineContent, LineNo)) 71 72 TokenList = GetSplitValueList(LineContent, DT.TAB_COMMENT_SPLIT) 73 ValueList[0:len(TokenList)] = TokenList 74 75 # 76 # Current section archs 77 # 78 KeyList = [] 79 LastItem = '' 80 for Item in self.LastSectionHeaderContent: 81 LastItem = Item 82 if (Item[1], Item[2], Item[3]) not in KeyList: 83 KeyList.append((Item[1], Item[2], Item[3])) 84 85 NewCommentList = [] 86 FormatCommentLn = -1 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 92 continue 93 94 if CommentItem[1] != FormatCommentLn: 95 NewCommentList.append(CommentContent) 96 else: 97 FormatCommentLn = CommentItem[1] + 1 98 99 if not InfSectionObject.SetDepex(DepexContent, KeyList = KeyList, CommentList = NewCommentList): 100 Logger.Error('InfParser', 101 FORMAT_INVALID, 102 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Depex]"), 103 File=FileName, 104 Line=LastItem[3])