]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Object/Parser/InfUserExtensionObject.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Object / Parser / InfUserExtensionObject.py
1 ## @file
2 # This file is used to define class objects of INF file [UserExtension] section.
3 # It will consumed by InfParser.
4 #
5 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 #
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 '''
10 InfUserExtensionsObject
11 '''
12
13 from Logger import StringTable as ST
14 from Logger import ToolError
15 import Logger.Log as Logger
16 from Library import GlobalData
17
18 from Library.Misc import Sdict
19
20 class InfUserExtensionItem():
21 def __init__(self,
22 Content = '',
23 UserId = '',
24 IdString = ''):
25 self.Content = Content
26 self.UserId = UserId
27 self.IdString = IdString
28 self.SupArchList = []
29
30 def SetContent(self, Content):
31 self.Content = Content
32 def GetContent(self):
33 return self.Content
34
35 def SetUserId(self, UserId):
36 self.UserId = UserId
37 def GetUserId(self):
38 return self.UserId
39
40 def SetIdString(self, IdString):
41 self.IdString = IdString
42 def GetIdString(self):
43 return self.IdString
44
45 def SetSupArchList(self, SupArchList):
46 self.SupArchList = SupArchList
47 def GetSupArchList(self):
48 return self.SupArchList
49
50 ##
51 #
52 #
53 #
54 class InfUserExtensionObject():
55 def __init__(self):
56 self.UserExtension = Sdict()
57
58 def SetUserExtension(self, UserExtensionCont, IdContent=None, LineNo=None):
59 if not UserExtensionCont or UserExtensionCont == '':
60 return True
61 #
62 # IdContent is a list contain UserId and IdString
63 # For this call the general section header parser, if no definition of
64 # IdString/UserId, it will return 'COMMON'
65 #
66 for IdContentItem in IdContent:
67 InfUserExtensionItemObj = InfUserExtensionItem()
68 if IdContentItem[0] == 'COMMON':
69 UserId = ''
70 else:
71 UserId = IdContentItem[0]
72
73 if IdContentItem[1] == 'COMMON':
74 IdString = ''
75 else:
76 IdString = IdContentItem[1]
77
78 #
79 # Fill UserExtensionObj members.
80 #
81 InfUserExtensionItemObj.SetUserId(UserId)
82 InfUserExtensionItemObj.SetIdString(IdString)
83 InfUserExtensionItemObj.SetContent(UserExtensionCont)
84 InfUserExtensionItemObj.SetSupArchList(IdContentItem[2])
85
86 # for CheckItem in self.UserExtension:
87 # if IdContentItem[0] == CheckItem[0] and IdContentItem[1] == CheckItem[1]:
88 # if IdContentItem[2].upper() == 'COMMON' or CheckItem[2].upper() == 'COMMON':
89 # #
90 # # For COMMON ARCH type, do special check.
91 # #
92 # Logger.Error('InfParser',
93 # ToolError.FORMAT_INVALID,
94 # ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\
95 # (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]),
96 # File=GlobalData.gINF_MODULE_NAME,
97 # Line=LineNo,
98 # ExtraData=None)
99
100 if IdContentItem in self.UserExtension:
101 #
102 # Each UserExtensions section header must have a unique set
103 # of UserId, IdString and Arch values.
104 # This means that the same UserId can be used in more than one
105 # section header, provided the IdString or Arch values are
106 # different. The same IdString values can be used in more than
107 # one section header if the UserId or Arch values are
108 # different. The same UserId and the same IdString can be used
109 # in a section header if the Arch values are different in each
110 # of the section headers.
111 #
112 Logger.Error('InfParser',
113 ToolError.FORMAT_INVALID,
114 ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\
115 (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]),
116 File=GlobalData.gINF_MODULE_NAME,
117 Line=LineNo,
118 ExtraData=None)
119 else:
120 UserExtensionList = []
121 UserExtensionList.append(InfUserExtensionItemObj)
122 self.UserExtension[IdContentItem] = UserExtensionList
123
124 return True
125
126 def GetUserExtension(self):
127 return self.UserExtension