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