]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/IdfClassObject.py
BaseTools: Enable structure pcd in FDF file
[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 from Common.BuildToolError import *
18 from Common.StringUtils import GetLineNo
19 from Common.Misc import PathClass
20 from Common.LongFilePathSupport import LongFilePath
21 import re
22 import os
23 from Common.GlobalData import gIdentifierPattern
24 from UniClassObject import StripComments
25
26 IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
27
28 #
29 # Value of different image information block types
30 #
31 EFI_HII_IIBT_END = 0x00
32 EFI_HII_IIBT_IMAGE_1BIT = 0x10
33 EFI_HII_IIBT_IMAGE_1BIT_TRANS = 0x11
34 EFI_HII_IIBT_IMAGE_4BIT = 0x12
35 EFI_HII_IIBT_IMAGE_4BIT_TRANS = 0x13
36 EFI_HII_IIBT_IMAGE_8BIT = 0x14
37 EFI_HII_IIBT_IMAGE_8BIT_TRANS = 0x15
38 EFI_HII_IIBT_IMAGE_24BIT = 0x16
39 EFI_HII_IIBT_IMAGE_24BIT_TRANS = 0x17
40 EFI_HII_IIBT_IMAGE_JPEG = 0x18
41 EFI_HII_IIBT_IMAGE_PNG = 0x19
42 EFI_HII_IIBT_DUPLICATE = 0x20
43 EFI_HII_IIBT_SKIP2 = 0x21
44 EFI_HII_IIBT_SKIP1 = 0x22
45 EFI_HII_IIBT_EXT1 = 0x30
46 EFI_HII_IIBT_EXT2 = 0x31
47 EFI_HII_IIBT_EXT4 = 0x32
48
49 #
50 # Value of HII package type
51 #
52 EFI_HII_PACKAGE_TYPE_ALL = 0x00
53 EFI_HII_PACKAGE_TYPE_GUID = 0x01
54 EFI_HII_PACKAGE_FORMS = 0x02
55 EFI_HII_PACKAGE_STRINGS = 0x04
56 EFI_HII_PACKAGE_FONTS = 0x05
57 EFI_HII_PACKAGE_IMAGES = 0x06
58 EFI_HII_PACKAGE_SIMPLE_FONTS = 0x07
59 EFI_HII_PACKAGE_DEVICE_PATH = 0x08
60 EFI_HII_PACKAGE_KEYBOARD_LAYOUT = 0x09
61 EFI_HII_PACKAGE_ANIMATIONS = 0x0A
62 EFI_HII_PACKAGE_END = 0xDF
63 EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN = 0xE0
64 EFI_HII_PACKAGE_TYPE_SYSTEM_END = 0xFF
65
66 class IdfFileClassObject(object):
67 def __init__(self, FileList = []):
68 self.ImageFilesDict = {}
69 self.ImageIDList = []
70 for File in FileList:
71 if File is None:
72 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.')
73
74 try:
75 IdfFile = open(LongFilePath(File.Path), mode='r')
76 FileIn = IdfFile.read()
77 IdfFile.close()
78 except:
79 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)
80
81 ImageFileList = []
82 for Line in FileIn.splitlines():
83 Line = Line.strip()
84 Line = StripComments(Line)
85 if len(Line) == 0:
86 continue
87
88 LineNo = GetLineNo(FileIn, Line, False)
89 if not Line.startswith('#image '):
90 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is invalid.' % (Line, LineNo, File.Path))
91
92 if Line.find('#image ') >= 0:
93 LineDetails = Line.split()
94 Len = len(LineDetails)
95 if Len != 3 and Len != 4:
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))
97 if Len == 4 and LineDetails[2] != 'TRANSPARENT':
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))
99 MatchString = gIdentifierPattern.match(LineDetails[1])
100 if MatchString is None:
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))
102 if LineDetails[1] not in self.ImageIDList:
103 self.ImageIDList.append(LineDetails[1])
104 else:
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))
106 if Len == 4:
107 ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], True)
108 else:
109 ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], False)
110 ImageFileList.append(ImageFile)
111 if ImageFileList:
112 self.ImageFilesDict[File] = ImageFileList
113
114 def SearchImageID(ImageFileObject, FileList):
115 if FileList == []:
116 return ImageFileObject
117
118 for File in FileList:
119 if os.path.isfile(File):
120 Lines = open(File, 'r')
121 for Line in Lines:
122 ImageIdList = IMAGE_TOKEN.findall(Line)
123 for ID in ImageIdList:
124 EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID)
125 ImageFileObject.SetImageIDReferenced(ID)
126
127 class ImageFileObject(object):
128 def __init__(self, FileName, ImageID, TransParent = False):
129 self.FileName = FileName
130 self.File = ''
131 self.ImageID = ImageID
132 self.TransParent = TransParent
133 self.Referenced = False
134
135 def SetImageIDReferenced(self, ImageID):
136 if ImageID == self.ImageID:
137 self.Referenced = True