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