]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file\r |
2 | # This file contained the parser for [Packages] sections in INF file \r | |
3 | #\r | |
4 | # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | #\r | |
6 | # This program and the accompanying materials are licensed and made available \r | |
7 | # under the terms and conditions of the BSD License which accompanies this \r | |
8 | # distribution. The full text of the license may be found at \r | |
9 | # http://opensource.org/licenses/bsd-license.php\r | |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | #\r | |
14 | '''\r | |
15 | InfPackageSectionParser\r | |
16 | '''\r | |
17 | ##\r | |
18 | # Import Modules\r | |
19 | #\r | |
20 | \r | |
21 | import Logger.Log as Logger\r | |
22 | from Logger import StringTable as ST\r | |
23 | from Logger.ToolError import FORMAT_INVALID\r | |
24 | from Parser.InfParserMisc import InfExpandMacro\r | |
25 | from Library import DataType as DT\r | |
26 | from Library.Parsing import MacroParser\r | |
27 | from Library.Misc import GetSplitValueList\r | |
28 | from Object.Parser.InfCommonObject import InfLineCommentObject\r | |
29 | from Parser.InfParserMisc import InfParserSectionRoot\r | |
30 | \r | |
31 | class InfPackageSectionParser(InfParserSectionRoot):\r | |
32 | ## InfPackageParser\r | |
33 | #\r | |
34 | # \r | |
35 | def InfPackageParser(self, SectionString, InfSectionObject, FileName):\r | |
36 | #\r | |
37 | # Macro defined in this section \r | |
38 | #\r | |
39 | SectionMacros = {}\r | |
40 | ValueList = []\r | |
41 | PackageList = []\r | |
42 | StillCommentFalg = False\r | |
43 | HeaderComments = []\r | |
44 | LineComment = None \r | |
45 | #\r | |
46 | # Parse section content\r | |
47 | #\r | |
48 | for Line in SectionString:\r | |
49 | PkgLineContent = Line[0]\r | |
50 | PkgLineNo = Line[1] \r | |
51 | \r | |
52 | if PkgLineContent.strip() == '':\r | |
53 | continue\r | |
54 | \r | |
55 | #\r | |
56 | # Find Header Comments \r | |
57 | #\r | |
58 | if PkgLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
59 | #\r | |
60 | # Last line is comments, and this line go on.\r | |
61 | #\r | |
62 | if StillCommentFalg:\r | |
63 | HeaderComments.append(Line)\r | |
64 | continue\r | |
65 | #\r | |
66 | # First time encounter comment \r | |
67 | #\r | |
68 | else:\r | |
69 | #\r | |
70 | # Clear original data\r | |
71 | #\r | |
72 | HeaderComments = []\r | |
73 | HeaderComments.append(Line)\r | |
74 | StillCommentFalg = True\r | |
75 | continue\r | |
76 | else:\r | |
77 | StillCommentFalg = False\r | |
78 | \r | |
79 | if len(HeaderComments) >= 1:\r | |
80 | LineComment = InfLineCommentObject()\r | |
81 | LineCommentContent = ''\r | |
82 | for Item in HeaderComments:\r | |
83 | LineCommentContent += Item[0] + DT.END_OF_LINE\r | |
84 | LineComment.SetHeaderComments(LineCommentContent)\r | |
85 | \r | |
86 | #\r | |
87 | # Find Tail comment.\r | |
88 | #\r | |
89 | if PkgLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
90 | TailComments = PkgLineContent[PkgLineContent.find(DT.TAB_COMMENT_SPLIT):]\r | |
91 | PkgLineContent = PkgLineContent[:PkgLineContent.find(DT.TAB_COMMENT_SPLIT)]\r | |
4231a819 | 92 | if LineComment is None:\r |
4234283c LG |
93 | LineComment = InfLineCommentObject()\r |
94 | LineComment.SetTailComments(TailComments) \r | |
95 | #\r | |
96 | # Find Macro\r | |
97 | #\r | |
98 | Name, Value = MacroParser((PkgLineContent, PkgLineNo),\r | |
99 | FileName,\r | |
100 | DT.MODEL_META_DATA_PACKAGE,\r | |
101 | self.FileLocalMacros)\r | |
4231a819 | 102 | if Name is not None:\r |
4234283c LG |
103 | SectionMacros[Name] = Value\r |
104 | LineComment = None\r | |
105 | HeaderComments = [] \r | |
106 | continue\r | |
107 | \r | |
108 | TokenList = GetSplitValueList(PkgLineContent, DT.TAB_VALUE_SPLIT, 1)\r | |
109 | ValueList[0:len(TokenList)] = TokenList\r | |
110 | \r | |
111 | #\r | |
112 | # Replace with Local section Macro and [Defines] section Macro.\r | |
113 | # \r | |
114 | ValueList = [InfExpandMacro(Value, (FileName, PkgLineContent, PkgLineNo), \r | |
115 | self.FileLocalMacros, SectionMacros, True)\r | |
116 | for Value in ValueList]\r | |
117 | \r | |
118 | PackageList.append((ValueList, LineComment, \r | |
119 | (PkgLineContent, PkgLineNo, FileName)))\r | |
120 | ValueList = []\r | |
121 | LineComment = None\r | |
122 | TailComments = ''\r | |
123 | HeaderComments = [] \r | |
124 | continue\r | |
125 | \r | |
126 | #\r | |
127 | # Current section archs\r | |
128 | # \r | |
129 | ArchList = []\r | |
130 | for Item in self.LastSectionHeaderContent:\r | |
131 | if Item[1] not in ArchList:\r | |
132 | ArchList.append(Item[1]) \r | |
133 | \r | |
134 | if not InfSectionObject.SetPackages(PackageList, Arch = ArchList):\r | |
135 | Logger.Error('InfParser', \r | |
136 | FORMAT_INVALID, \r | |
137 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\\r | |
138 | %("[Packages]"),\r | |
139 | File=FileName,\r | |
140 | Line=Item[3]) |