]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Parser/InfPackageSectionParser.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfPackageSectionParser.py
1 ## @file
2 # This file contained the parser for [Packages] sections in INF file
3 #
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8 '''
9 InfPackageSectionParser
10 '''
11 ##
12 # Import Modules
13 #
14
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.Parsing import MacroParser
21 from Library.Misc import GetSplitValueList
22 from Object.Parser.InfCommonObject import InfLineCommentObject
23 from Parser.InfParserMisc import InfParserSectionRoot
24
25 class InfPackageSectionParser(InfParserSectionRoot):
26 ## InfPackageParser
27 #
28 #
29 def InfPackageParser(self, SectionString, InfSectionObject, FileName):
30 #
31 # Macro defined in this section
32 #
33 SectionMacros = {}
34 ValueList = []
35 PackageList = []
36 StillCommentFalg = False
37 HeaderComments = []
38 LineComment = None
39 #
40 # Parse section content
41 #
42 for Line in SectionString:
43 PkgLineContent = Line[0]
44 PkgLineNo = Line[1]
45
46 if PkgLineContent.strip() == '':
47 continue
48
49 #
50 # Find Header Comments
51 #
52 if PkgLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):
53 #
54 # Last line is comments, and this line go on.
55 #
56 if StillCommentFalg:
57 HeaderComments.append(Line)
58 continue
59 #
60 # First time encounter comment
61 #
62 else:
63 #
64 # Clear original data
65 #
66 HeaderComments = []
67 HeaderComments.append(Line)
68 StillCommentFalg = True
69 continue
70 else:
71 StillCommentFalg = False
72
73 if len(HeaderComments) >= 1:
74 LineComment = InfLineCommentObject()
75 LineCommentContent = ''
76 for Item in HeaderComments:
77 LineCommentContent += Item[0] + DT.END_OF_LINE
78 LineComment.SetHeaderComments(LineCommentContent)
79
80 #
81 # Find Tail comment.
82 #
83 if PkgLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
84 TailComments = PkgLineContent[PkgLineContent.find(DT.TAB_COMMENT_SPLIT):]
85 PkgLineContent = PkgLineContent[:PkgLineContent.find(DT.TAB_COMMENT_SPLIT)]
86 if LineComment is None:
87 LineComment = InfLineCommentObject()
88 LineComment.SetTailComments(TailComments)
89 #
90 # Find Macro
91 #
92 Name, Value = MacroParser((PkgLineContent, PkgLineNo),
93 FileName,
94 DT.MODEL_META_DATA_PACKAGE,
95 self.FileLocalMacros)
96 if Name is not None:
97 SectionMacros[Name] = Value
98 LineComment = None
99 HeaderComments = []
100 continue
101
102 TokenList = GetSplitValueList(PkgLineContent, DT.TAB_VALUE_SPLIT, 1)
103 ValueList[0:len(TokenList)] = TokenList
104
105 #
106 # Replace with Local section Macro and [Defines] section Macro.
107 #
108 ValueList = [InfExpandMacro(Value, (FileName, PkgLineContent, PkgLineNo),
109 self.FileLocalMacros, SectionMacros, True)
110 for Value in ValueList]
111
112 PackageList.append((ValueList, LineComment,
113 (PkgLineContent, PkgLineNo, FileName)))
114 ValueList = []
115 LineComment = None
116 TailComments = ''
117 HeaderComments = []
118 continue
119
120 #
121 # Current section archs
122 #
123 ArchList = []
124 for Item in self.LastSectionHeaderContent:
125 if Item[1] not in ArchList:
126 ArchList.append(Item[1])
127
128 if not InfSectionObject.SetPackages(PackageList, Arch = ArchList):
129 Logger.Error('InfParser',
130 FORMAT_INVALID,
131 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\
132 %("[Packages]"),
133 File=FileName,
134 Line=Item[3])