]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/AutoGen/IdfClassObject.py
BaseTools: Replace StringIO.StringIO with io.BytesIO
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / IdfClassObject.py
... / ...
CommitLineData
1## @file\r
2# This file is used to collect all defined strings in Image Definition files\r
3#\r
4# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13##\r
14# Import Modules\r
15#\r
16import Common.EdkLogger as EdkLogger\r
17from Common.BuildToolError import *\r
18from Common.StringUtils import GetLineNo\r
19from Common.Misc import PathClass\r
20from Common.LongFilePathSupport import LongFilePath\r
21import re\r
22import os\r
23from Common.GlobalData import gIdentifierPattern\r
24from UniClassObject import StripComments\r
25\r
26IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)\r
27\r
28#\r
29# Value of different image information block types\r
30#\r
31EFI_HII_IIBT_END = 0x00\r
32EFI_HII_IIBT_IMAGE_1BIT = 0x10\r
33EFI_HII_IIBT_IMAGE_1BIT_TRANS = 0x11\r
34EFI_HII_IIBT_IMAGE_4BIT = 0x12\r
35EFI_HII_IIBT_IMAGE_4BIT_TRANS = 0x13\r
36EFI_HII_IIBT_IMAGE_8BIT = 0x14\r
37EFI_HII_IIBT_IMAGE_8BIT_TRANS = 0x15\r
38EFI_HII_IIBT_IMAGE_24BIT = 0x16\r
39EFI_HII_IIBT_IMAGE_24BIT_TRANS = 0x17\r
40EFI_HII_IIBT_IMAGE_JPEG = 0x18\r
41EFI_HII_IIBT_IMAGE_PNG = 0x19\r
42EFI_HII_IIBT_DUPLICATE = 0x20\r
43EFI_HII_IIBT_SKIP2 = 0x21\r
44EFI_HII_IIBT_SKIP1 = 0x22\r
45EFI_HII_IIBT_EXT1 = 0x30\r
46EFI_HII_IIBT_EXT2 = 0x31\r
47EFI_HII_IIBT_EXT4 = 0x32\r
48\r
49#\r
50# Value of HII package type\r
51#\r
52EFI_HII_PACKAGE_TYPE_ALL = 0x00\r
53EFI_HII_PACKAGE_TYPE_GUID = 0x01\r
54EFI_HII_PACKAGE_FORMS = 0x02\r
55EFI_HII_PACKAGE_STRINGS = 0x04\r
56EFI_HII_PACKAGE_FONTS = 0x05\r
57EFI_HII_PACKAGE_IMAGES = 0x06\r
58EFI_HII_PACKAGE_SIMPLE_FONTS = 0x07\r
59EFI_HII_PACKAGE_DEVICE_PATH = 0x08\r
60EFI_HII_PACKAGE_KEYBOARD_LAYOUT = 0x09\r
61EFI_HII_PACKAGE_ANIMATIONS = 0x0A\r
62EFI_HII_PACKAGE_END = 0xDF\r
63EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN = 0xE0\r
64EFI_HII_PACKAGE_TYPE_SYSTEM_END = 0xFF\r
65\r
66class IdfFileClassObject(object):\r
67 def __init__(self, FileList = []):\r
68 self.ImageFilesDict = {}\r
69 self.ImageIDList = []\r
70 for File in FileList:\r
71 if File is None:\r
72 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.')\r
73\r
74 try:\r
75 IdfFile = open(LongFilePath(File.Path), mode='r')\r
76 FileIn = IdfFile.read()\r
77 IdfFile.close()\r
78 except:\r
79 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)\r
80\r
81 ImageFileList = []\r
82 for Line in FileIn.splitlines():\r
83 Line = Line.strip()\r
84 Line = StripComments(Line)\r
85 if len(Line) == 0:\r
86 continue\r
87\r
88 LineNo = GetLineNo(FileIn, Line, False)\r
89 if not Line.startswith('#image '):\r
90 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is invalid.' % (Line, LineNo, File.Path))\r
91\r
92 if Line.find('#image ') >= 0:\r
93 LineDetails = Line.split()\r
94 Len = len(LineDetails)\r
95 if Len != 3 and Len != 4:\r
96 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The format is not match #image IMAGE_ID [TRANSPARENT] ImageFileName in Line %s of File %s.' % (LineNo, File.Path))\r
97 if Len == 4 and LineDetails[2] != 'TRANSPARENT':\r
98 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'Please use the keyword "TRANSPARENT" to describe the transparency setting in Line %s of File %s.' % (LineNo, File.Path))\r
99 MatchString = gIdentifierPattern.match(LineDetails[1])\r
100 if MatchString is None:\r
101 EdkLogger.error('Image Definition File Parser', FORMAT_INVALID, 'The Image token name %s defined in Idf file %s contains the invalid character.' % (LineDetails[1], File.Path))\r
102 if LineDetails[1] not in self.ImageIDList:\r
103 self.ImageIDList.append(LineDetails[1])\r
104 else:\r
105 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is already defined.' % (LineDetails[1], LineNo, File.Path))\r
106 if Len == 4:\r
107 ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], True)\r
108 else:\r
109 ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], False)\r
110 ImageFileList.append(ImageFile)\r
111 if ImageFileList:\r
112 self.ImageFilesDict[File] = ImageFileList\r
113\r
114def SearchImageID(ImageFileObject, FileList):\r
115 if FileList == []:\r
116 return ImageFileObject\r
117\r
118 for File in FileList:\r
119 if os.path.isfile(File):\r
120 Lines = open(File, 'r')\r
121 for Line in Lines:\r
122 ImageIdList = IMAGE_TOKEN.findall(Line)\r
123 for ID in ImageIdList:\r
124 EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID)\r
125 ImageFileObject.SetImageIDReferenced(ID)\r
126\r
127class ImageFileObject(object):\r
128 def __init__(self, FileName, ImageID, TransParent = False):\r
129 self.FileName = FileName\r
130 self.File = ''\r
131 self.ImageID = ImageID\r
132 self.TransParent = TransParent\r
133 self.Referenced = False\r
134\r
135 def SetImageIDReferenced(self, ImageID):\r
136 if ImageID == self.ImageID:\r
137 self.Referenced = True\r