]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 | 2 | # This file contained the parser for [Sources] sections in INF file\r |
4234283c | 3 | #\r |
f7496d71 | 4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 5 | #\r |
f7496d71 LG |
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 | |
4234283c LG |
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 | InfSourceSectionParser\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 InfSourceSectionParser(InfParserSectionRoot):\r | |
32 | ## InfSourceParser\r | |
33 | #\r | |
f7496d71 | 34 | #\r |
4234283c LG |
35 | def InfSourceParser(self, SectionString, InfSectionObject, FileName):\r |
36 | SectionMacros = {}\r | |
37 | ValueList = []\r | |
38 | SourceList = []\r | |
39 | StillCommentFalg = False\r | |
40 | HeaderComments = []\r | |
41 | LineComment = None\r | |
42 | SectionContent = ''\r | |
43 | for Line in SectionString:\r | |
44 | SrcLineContent = Line[0]\r | |
45 | SrcLineNo = Line[1]\r | |
f7496d71 | 46 | \r |
4234283c LG |
47 | if SrcLineContent.strip() == '':\r |
48 | continue\r | |
f7496d71 | 49 | \r |
4234283c | 50 | #\r |
f7496d71 | 51 | # Found Header Comments\r |
4234283c LG |
52 | #\r |
53 | if SrcLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
54 | #\r | |
55 | # Last line is comments, and this line go on.\r | |
56 | #\r | |
57 | if StillCommentFalg:\r | |
58 | HeaderComments.append(Line)\r | |
59 | SectionContent += SrcLineContent + DT.END_OF_LINE\r | |
60 | continue\r | |
61 | #\r | |
f7496d71 | 62 | # First time encounter comment\r |
4234283c LG |
63 | #\r |
64 | else:\r | |
65 | #\r | |
66 | # Clear original data\r | |
67 | #\r | |
68 | HeaderComments = []\r | |
69 | HeaderComments.append(Line)\r | |
70 | StillCommentFalg = True\r | |
f7496d71 | 71 | SectionContent += SrcLineContent + DT.END_OF_LINE\r |
4234283c LG |
72 | continue\r |
73 | else:\r | |
74 | StillCommentFalg = False\r | |
f7496d71 | 75 | \r |
4234283c LG |
76 | if len(HeaderComments) >= 1:\r |
77 | LineComment = InfLineCommentObject()\r | |
78 | LineCommentContent = ''\r | |
79 | for Item in HeaderComments:\r | |
80 | LineCommentContent += Item[0] + DT.END_OF_LINE\r | |
81 | LineComment.SetHeaderComments(LineCommentContent)\r | |
f7496d71 | 82 | \r |
4234283c LG |
83 | #\r |
84 | # Find Tail comment.\r | |
85 | #\r | |
86 | if SrcLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
87 | TailComments = SrcLineContent[SrcLineContent.find(DT.TAB_COMMENT_SPLIT):]\r | |
88 | SrcLineContent = SrcLineContent[:SrcLineContent.find(DT.TAB_COMMENT_SPLIT)]\r | |
4231a819 | 89 | if LineComment is None:\r |
4234283c LG |
90 | LineComment = InfLineCommentObject()\r |
91 | LineComment.SetTailComments(TailComments)\r | |
f7496d71 | 92 | \r |
4234283c LG |
93 | #\r |
94 | # Find Macro\r | |
95 | #\r | |
f7496d71 | 96 | Name, Value = MacroParser((SrcLineContent, SrcLineNo),\r |
4234283c LG |
97 | FileName,\r |
98 | DT.MODEL_EFI_SOURCE_FILE,\r | |
99 | self.FileLocalMacros)\r | |
4231a819 | 100 | if Name is not None:\r |
4234283c LG |
101 | SectionMacros[Name] = Value\r |
102 | LineComment = None\r | |
103 | HeaderComments = []\r | |
104 | continue\r | |
f7496d71 | 105 | \r |
4234283c LG |
106 | #\r |
107 | # Replace with Local section Macro and [Defines] section Macro.\r | |
f7496d71 LG |
108 | #\r |
109 | SrcLineContent = InfExpandMacro(SrcLineContent,\r | |
110 | (FileName, SrcLineContent, SrcLineNo),\r | |
111 | self.FileLocalMacros,\r | |
4234283c LG |
112 | SectionMacros)\r |
113 | \r | |
114 | TokenList = GetSplitValueList(SrcLineContent, DT.TAB_VALUE_SPLIT, 4)\r | |
115 | ValueList[0:len(TokenList)] = TokenList\r | |
f7496d71 | 116 | \r |
4234283c LG |
117 | #\r |
118 | # Store section content string after MACRO replaced.\r | |
119 | #\r | |
f7496d71 LG |
120 | SectionContent += SrcLineContent + DT.END_OF_LINE\r |
121 | \r | |
122 | SourceList.append((ValueList, LineComment,\r | |
4234283c LG |
123 | (SrcLineContent, SrcLineNo, FileName)))\r |
124 | ValueList = []\r | |
125 | LineComment = None\r | |
126 | TailComments = ''\r | |
127 | HeaderComments = []\r | |
128 | continue\r | |
f7496d71 | 129 | \r |
4234283c LG |
130 | #\r |
131 | # Current section archs\r | |
132 | #\r | |
133 | ArchList = []\r | |
134 | for Item in self.LastSectionHeaderContent:\r | |
135 | if Item[1] not in ArchList:\r | |
f7496d71 | 136 | ArchList.append(Item[1])\r |
4234283c | 137 | InfSectionObject.SetSupArchList(Item[1])\r |
f7496d71 LG |
138 | \r |
139 | InfSectionObject.SetAllContent(SectionContent)\r | |
4234283c | 140 | if not InfSectionObject.SetSources(SourceList, Arch = ArchList):\r |
f7496d71 | 141 | Logger.Error('InfParser',\r |
4234283c LG |
142 | FORMAT_INVALID,\r |
143 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Sources]"),\r | |
f7496d71 LG |
144 | File=FileName,\r |
145 | Line=Item[3])\r |