]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfSourceSectionParser.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfSourceSectionParser.py
CommitLineData
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
2e351cbe 6# SPDX-License-Identifier: BSD-2-Clause-Patent\r
4234283c
LG
7#\r
8'''\r
9InfSourceSectionParser\r
10'''\r
11##\r
12# Import Modules\r
13#\r
14\r
15import Logger.Log as Logger\r
16from Logger import StringTable as ST\r
17from Logger.ToolError import FORMAT_INVALID\r
18from Parser.InfParserMisc import InfExpandMacro\r
19from Library import DataType as DT\r
20from Library.Parsing import MacroParser\r
21from Library.Misc import GetSplitValueList\r
22from Object.Parser.InfCommonObject import InfLineCommentObject\r
23from Parser.InfParserMisc import InfParserSectionRoot\r
24\r
25class InfSourceSectionParser(InfParserSectionRoot):\r
26 ## InfSourceParser\r
27 #\r
f7496d71 28 #\r
4234283c
LG
29 def InfSourceParser(self, SectionString, InfSectionObject, FileName):\r
30 SectionMacros = {}\r
31 ValueList = []\r
32 SourceList = []\r
33 StillCommentFalg = False\r
34 HeaderComments = []\r
35 LineComment = None\r
36 SectionContent = ''\r
37 for Line in SectionString:\r
38 SrcLineContent = Line[0]\r
39 SrcLineNo = Line[1]\r
f7496d71 40\r
4234283c
LG
41 if SrcLineContent.strip() == '':\r
42 continue\r
f7496d71 43\r
4234283c 44 #\r
f7496d71 45 # Found Header Comments\r
4234283c
LG
46 #\r
47 if SrcLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
48 #\r
49 # Last line is comments, and this line go on.\r
50 #\r
51 if StillCommentFalg:\r
52 HeaderComments.append(Line)\r
53 SectionContent += SrcLineContent + DT.END_OF_LINE\r
54 continue\r
55 #\r
f7496d71 56 # First time encounter comment\r
4234283c
LG
57 #\r
58 else:\r
59 #\r
60 # Clear original data\r
61 #\r
62 HeaderComments = []\r
63 HeaderComments.append(Line)\r
64 StillCommentFalg = True\r
f7496d71 65 SectionContent += SrcLineContent + DT.END_OF_LINE\r
4234283c
LG
66 continue\r
67 else:\r
68 StillCommentFalg = False\r
f7496d71 69\r
4234283c
LG
70 if len(HeaderComments) >= 1:\r
71 LineComment = InfLineCommentObject()\r
72 LineCommentContent = ''\r
73 for Item in HeaderComments:\r
74 LineCommentContent += Item[0] + DT.END_OF_LINE\r
75 LineComment.SetHeaderComments(LineCommentContent)\r
f7496d71 76\r
4234283c
LG
77 #\r
78 # Find Tail comment.\r
79 #\r
80 if SrcLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
81 TailComments = SrcLineContent[SrcLineContent.find(DT.TAB_COMMENT_SPLIT):]\r
82 SrcLineContent = SrcLineContent[:SrcLineContent.find(DT.TAB_COMMENT_SPLIT)]\r
4231a819 83 if LineComment is None:\r
4234283c
LG
84 LineComment = InfLineCommentObject()\r
85 LineComment.SetTailComments(TailComments)\r
f7496d71 86\r
4234283c
LG
87 #\r
88 # Find Macro\r
89 #\r
f7496d71 90 Name, Value = MacroParser((SrcLineContent, SrcLineNo),\r
4234283c
LG
91 FileName,\r
92 DT.MODEL_EFI_SOURCE_FILE,\r
93 self.FileLocalMacros)\r
4231a819 94 if Name is not None:\r
4234283c
LG
95 SectionMacros[Name] = Value\r
96 LineComment = None\r
97 HeaderComments = []\r
98 continue\r
f7496d71 99\r
4234283c
LG
100 #\r
101 # Replace with Local section Macro and [Defines] section Macro.\r
f7496d71
LG
102 #\r
103 SrcLineContent = InfExpandMacro(SrcLineContent,\r
104 (FileName, SrcLineContent, SrcLineNo),\r
105 self.FileLocalMacros,\r
4234283c
LG
106 SectionMacros)\r
107\r
108 TokenList = GetSplitValueList(SrcLineContent, DT.TAB_VALUE_SPLIT, 4)\r
109 ValueList[0:len(TokenList)] = TokenList\r
f7496d71 110\r
4234283c
LG
111 #\r
112 # Store section content string after MACRO replaced.\r
113 #\r
f7496d71
LG
114 SectionContent += SrcLineContent + DT.END_OF_LINE\r
115\r
116 SourceList.append((ValueList, LineComment,\r
4234283c
LG
117 (SrcLineContent, SrcLineNo, FileName)))\r
118 ValueList = []\r
119 LineComment = None\r
120 TailComments = ''\r
121 HeaderComments = []\r
122 continue\r
f7496d71 123\r
4234283c
LG
124 #\r
125 # Current section archs\r
126 #\r
127 ArchList = []\r
128 for Item in self.LastSectionHeaderContent:\r
129 if Item[1] not in ArchList:\r
f7496d71 130 ArchList.append(Item[1])\r
4234283c 131 InfSectionObject.SetSupArchList(Item[1])\r
f7496d71
LG
132\r
133 InfSectionObject.SetAllContent(SectionContent)\r
4234283c 134 if not InfSectionObject.SetSources(SourceList, Arch = ArchList):\r
f7496d71 135 Logger.Error('InfParser',\r
4234283c
LG
136 FORMAT_INVALID,\r
137 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Sources]"),\r
f7496d71
LG
138 File=FileName,\r
139 Line=Item[3])\r