]>
Commit | Line | Data |
---|---|---|
1 | ## @file\r | |
2 | # This file contained the parser for [Sources] sections in INF file\r | |
3 | #\r | |
4 | # Copyright (c) 2011 - 2018, 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 | 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 | |
34 | #\r | |
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 | |
46 | \r | |
47 | if SrcLineContent.strip() == '':\r | |
48 | continue\r | |
49 | \r | |
50 | #\r | |
51 | # Found Header Comments\r | |
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 | |
62 | # First time encounter comment\r | |
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 | |
71 | SectionContent += SrcLineContent + DT.END_OF_LINE\r | |
72 | continue\r | |
73 | else:\r | |
74 | StillCommentFalg = False\r | |
75 | \r | |
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 | |
82 | \r | |
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 | |
89 | if LineComment is None:\r | |
90 | LineComment = InfLineCommentObject()\r | |
91 | LineComment.SetTailComments(TailComments)\r | |
92 | \r | |
93 | #\r | |
94 | # Find Macro\r | |
95 | #\r | |
96 | Name, Value = MacroParser((SrcLineContent, SrcLineNo),\r | |
97 | FileName,\r | |
98 | DT.MODEL_EFI_SOURCE_FILE,\r | |
99 | self.FileLocalMacros)\r | |
100 | if Name is not None:\r | |
101 | SectionMacros[Name] = Value\r | |
102 | LineComment = None\r | |
103 | HeaderComments = []\r | |
104 | continue\r | |
105 | \r | |
106 | #\r | |
107 | # Replace with Local section Macro and [Defines] section Macro.\r | |
108 | #\r | |
109 | SrcLineContent = InfExpandMacro(SrcLineContent,\r | |
110 | (FileName, SrcLineContent, SrcLineNo),\r | |
111 | self.FileLocalMacros,\r | |
112 | SectionMacros)\r | |
113 | \r | |
114 | TokenList = GetSplitValueList(SrcLineContent, DT.TAB_VALUE_SPLIT, 4)\r | |
115 | ValueList[0:len(TokenList)] = TokenList\r | |
116 | \r | |
117 | #\r | |
118 | # Store section content string after MACRO replaced.\r | |
119 | #\r | |
120 | SectionContent += SrcLineContent + DT.END_OF_LINE\r | |
121 | \r | |
122 | SourceList.append((ValueList, LineComment,\r | |
123 | (SrcLineContent, SrcLineNo, FileName)))\r | |
124 | ValueList = []\r | |
125 | LineComment = None\r | |
126 | TailComments = ''\r | |
127 | HeaderComments = []\r | |
128 | continue\r | |
129 | \r | |
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 | |
136 | ArchList.append(Item[1])\r | |
137 | InfSectionObject.SetSupArchList(Item[1])\r | |
138 | \r | |
139 | InfSectionObject.SetAllContent(SectionContent)\r | |
140 | if not InfSectionObject.SetSources(SourceList, Arch = ArchList):\r | |
141 | Logger.Error('InfParser',\r | |
142 | FORMAT_INVALID,\r | |
143 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Sources]"),\r | |
144 | File=FileName,\r | |
145 | Line=Item[3])\r |