]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file\r |
2 | # This file contained the parser for BuildOption 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 | '''\r | |
16 | InfBuildOptionSectionParser\r | |
17 | '''\r | |
18 | ##\r | |
19 | # Import Modules\r | |
20 | #\r | |
21 | from Library import DataType as DT\r | |
22 | from Library import GlobalData\r | |
23 | import Logger.Log as Logger\r | |
24 | from Logger import StringTable as ST\r | |
25 | from Logger.ToolError import FORMAT_INVALID\r | |
26 | from Parser.InfParserMisc import InfExpandMacro\r | |
27 | from Library.Misc import GetSplitValueList\r | |
28 | from Parser.InfParserMisc import IsAsBuildOptionInfo\r | |
29 | from Library.Misc import GetHelpStringByRemoveHashKey\r | |
30 | from Library.ParserValidate import IsValidFamily\r | |
31 | from Library.ParserValidate import IsValidBuildOptionName\r | |
32 | from Parser.InfParserMisc import InfParserSectionRoot\r | |
33 | \r | |
34 | class InfBuildOptionSectionParser(InfParserSectionRoot):\r | |
35 | ## InfBuildOptionParser\r | |
36 | #\r | |
37 | #\r | |
38 | def InfBuildOptionParser(self, SectionString, InfSectionObject, FileName):\r | |
39 | \r | |
40 | BuildOptionList = []\r | |
41 | SectionContent = ''\r | |
42 | \r | |
43 | if not GlobalData.gIS_BINARY_INF:\r | |
44 | ValueList = []\r | |
45 | LineNo = 0\r | |
46 | \r | |
47 | for Line in SectionString:\r | |
48 | LineContent = Line[0]\r | |
49 | LineNo = Line[1]\r | |
50 | TailComments = ''\r | |
51 | ReplaceFlag = False\r | |
52 | \r | |
53 | if LineContent.strip() == '':\r | |
54 | SectionContent += LineContent + DT.END_OF_LINE \r | |
55 | continue \r | |
56 | #\r | |
57 | # Found Comment\r | |
58 | #\r | |
59 | if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
60 | SectionContent += LineContent + DT.END_OF_LINE \r | |
61 | continue\r | |
62 | \r | |
63 | #\r | |
64 | # Find Tail comment.\r | |
65 | #\r | |
66 | if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
67 | TailComments = LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):]\r | |
68 | LineContent = LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)] \r | |
69 | \r | |
70 | TokenList = GetSplitValueList(LineContent, DT.TAB_DEQUAL_SPLIT, 1)\r | |
71 | if len(TokenList) == 2:\r | |
72 | #\r | |
73 | # "Replace" type build option\r | |
74 | #\r | |
75 | TokenList.append('True')\r | |
76 | ReplaceFlag = True\r | |
77 | else:\r | |
78 | TokenList = GetSplitValueList(LineContent, DT.TAB_EQUAL_SPLIT, 1)\r | |
79 | #\r | |
80 | # "Append" type build option\r | |
81 | #\r | |
82 | if len(TokenList) == 2:\r | |
83 | TokenList.append('False')\r | |
84 | else:\r | |
85 | Logger.Error('InfParser', \r | |
86 | FORMAT_INVALID,\r | |
87 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
88 | ExtraData=LineContent, \r | |
89 | File=FileName,\r | |
90 | Line=LineNo) \r | |
91 | \r | |
92 | ValueList[0:len(TokenList)] = TokenList\r | |
93 | \r | |
94 | #\r | |
95 | # Replace with [Defines] section Macro\r | |
96 | #\r | |
97 | ValueList[0] = InfExpandMacro(ValueList[0], (FileName, LineContent, LineNo), \r | |
98 | self.FileLocalMacros, None)\r | |
99 | ValueList[1] = InfExpandMacro(ValueList[1], (FileName, LineContent, LineNo), \r | |
100 | self.FileLocalMacros, None, True)\r | |
101 | EqualString = ''\r | |
102 | if not ReplaceFlag:\r | |
103 | EqualString = ' = '\r | |
104 | else:\r | |
105 | EqualString = ' == '\r | |
106 | \r | |
107 | SectionContent += ValueList[0] + EqualString + ValueList[1] + TailComments + DT.END_OF_LINE\r | |
108 | \r | |
109 | Family = GetSplitValueList(ValueList[0], DT.TAB_COLON_SPLIT, 1)\r | |
110 | if len(Family) == 2:\r | |
111 | if not IsValidFamily(Family[0]): \r | |
112 | Logger.Error('InfParser', \r | |
113 | FORMAT_INVALID,\r | |
114 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
115 | ExtraData=LineContent, \r | |
116 | File=FileName,\r | |
117 | Line=LineNo)\r | |
118 | if not IsValidBuildOptionName(Family[1]):\r | |
119 | Logger.Error('InfParser', \r | |
120 | FORMAT_INVALID,\r | |
121 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
122 | ExtraData=LineContent, \r | |
123 | File=FileName,\r | |
124 | Line=LineNo)\r | |
125 | if len(Family) == 1:\r | |
126 | if not IsValidBuildOptionName(Family[0]):\r | |
127 | Logger.Error('InfParser', \r | |
128 | FORMAT_INVALID,\r | |
129 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
130 | ExtraData=LineContent, \r | |
131 | File=FileName,\r | |
132 | Line=LineNo)\r | |
133 | \r | |
134 | BuildOptionList.append(ValueList) \r | |
135 | ValueList = []\r | |
136 | continue\r | |
137 | else:\r | |
138 | BuildOptionList = InfAsBuiltBuildOptionParser(SectionString, FileName)\r | |
139 | \r | |
140 | #\r | |
141 | # Current section archs\r | |
142 | #\r | |
143 | ArchList = []\r | |
144 | LastItem = ''\r | |
145 | for Item in self.LastSectionHeaderContent:\r | |
146 | LastItem = Item\r | |
147 | if not (Item[1] == '' or Item[1] == '') and Item[1] not in ArchList:\r | |
148 | ArchList.append(Item[1])\r | |
149 | InfSectionObject.SetSupArchList(Item[1])\r | |
150 | \r | |
151 | InfSectionObject.SetAllContent(SectionContent)\r | |
152 | if not InfSectionObject.SetBuildOptions(BuildOptionList, ArchList, SectionContent):\r | |
153 | Logger.Error('InfParser', \r | |
154 | FORMAT_INVALID,\r | |
155 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[BuilOptions]"),\r | |
156 | File=FileName,\r | |
157 | Line=LastItem[3]) \r | |
158 | \r | |
159 | ## InfBuildOptionParser\r | |
160 | #\r | |
161 | #\r | |
162 | def InfAsBuiltBuildOptionParser(SectionString, FileName):\r | |
163 | BuildOptionList = [] \r | |
164 | #\r | |
165 | # AsBuild Binary INF file.\r | |
166 | #\r | |
167 | AsBuildOptionFlag = False\r | |
168 | BuildOptionItem = []\r | |
169 | Count = 0\r | |
170 | for Line in SectionString:\r | |
171 | Count += 1\r | |
172 | LineContent = Line[0]\r | |
173 | LineNo = Line[1]\r | |
174 | \r | |
175 | #\r | |
176 | # The last line\r | |
177 | #\r | |
178 | if len(SectionString) == Count:\r | |
179 | if LineContent.strip().startswith("##") and AsBuildOptionFlag:\r | |
180 | BuildOptionList.append(BuildOptionItem)\r | |
181 | BuildOptionList.append([GetHelpStringByRemoveHashKey(LineContent)])\r | |
182 | elif LineContent.strip().startswith("#") and AsBuildOptionFlag:\r | |
183 | BuildOptionInfo = GetHelpStringByRemoveHashKey(LineContent)\r | |
184 | BuildOptionItem.append(BuildOptionInfo)\r | |
185 | BuildOptionList.append(BuildOptionItem)\r | |
186 | else:\r | |
187 | if len(BuildOptionItem) > 0:\r | |
188 | BuildOptionList.append(BuildOptionItem)\r | |
189 | \r | |
190 | break \r | |
191 | \r | |
192 | if LineContent.strip() == '':\r | |
193 | AsBuildOptionFlag = False\r | |
194 | continue\r | |
195 | \r | |
196 | if LineContent.strip().startswith("##") and AsBuildOptionFlag:\r | |
197 | if len(BuildOptionItem) > 0:\r | |
198 | BuildOptionList.append(BuildOptionItem) \r | |
199 | \r | |
200 | BuildOptionItem = []\r | |
201 | \r | |
202 | if not LineContent.strip().startswith("#"):\r | |
203 | Logger.Error('InfParser', \r | |
204 | FORMAT_INVALID,\r | |
205 | ST.ERR_BO_CONTATIN_ASBUILD_AND_COMMON, \r | |
206 | File=FileName, \r | |
207 | Line=LineNo, \r | |
208 | ExtraData=LineContent)\r | |
209 | \r | |
210 | if IsAsBuildOptionInfo(LineContent):\r | |
211 | AsBuildOptionFlag = True\r | |
212 | continue\r | |
213 | \r | |
214 | if AsBuildOptionFlag:\r | |
215 | BuildOptionInfo = GetHelpStringByRemoveHashKey(LineContent)\r | |
216 | BuildOptionItem.append(BuildOptionInfo)\r | |
217 | \r | |
218 | return BuildOptionList |