]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/Section.py
BaseTools: refactor and remove out of date use of .keys()
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Section.py
CommitLineData
30fdf114
LG
1## @file\r
2# section base class\r
3#\r
37de70b7 4# Copyright (c) 2007-2017, Intel Corporation. All rights reserved.<BR>\r
30fdf114 5#\r
40d841f6 6# This program and the accompanying materials\r
30fdf114
LG
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
18from CommonDataClass.FdfClass import SectionClassObject\r
19from GenFdsGlobalVariable import GenFdsGlobalVariable\r
1be2ed90 20import Common.LongFilePathOs as os, glob\r
30fdf114
LG
21from Common import EdkLogger\r
22from Common.BuildToolError import *\r
23\r
24## section base class\r
25#\r
26#\r
27class Section (SectionClassObject):\r
28 SectionType = {\r
29 'RAW' : 'EFI_SECTION_RAW',\r
30 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID',\r
31 'PE32' : 'EFI_SECTION_PE32',\r
32 'PIC' : 'EFI_SECTION_PIC',\r
33 'TE' : 'EFI_SECTION_TE',\r
34 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',\r
35 'DXE_DEPEX' : 'EFI_SECTION_DXE_DEPEX',\r
36 'PEI_DEPEX' : 'EFI_SECTION_PEI_DEPEX',\r
37 'GUIDED' : 'EFI_SECTION_GUID_DEFINED',\r
38 'COMPRESS' : 'EFI_SECTION_COMPRESSION',\r
39 'UI' : 'EFI_SECTION_USER_INTERFACE',\r
40 'SMM_DEPEX' : 'EFI_SECTION_SMM_DEPEX'\r
41 }\r
42\r
43 BinFileType = {\r
44 'GUID' : '.guid',\r
45 'ACPI' : '.acpi',\r
46 'ASL' : '.asl' ,\r
47 'UEFI_APP' : '.app',\r
48 'LIB' : '.lib',\r
49 'PE32' : '.pe32',\r
50 'PIC' : '.pic',\r
51 'PEI_DEPEX' : '.depex',\r
52 'SEC_PEI_DEPEX' : '.depex',\r
53 'TE' : '.te',\r
54 'UNI_VER' : '.ver',\r
55 'VER' : '.ver',\r
56 'UNI_UI' : '.ui',\r
57 'UI' : '.ui',\r
58 'BIN' : '.bin',\r
59 'RAW' : '.raw',\r
60 'COMPAT16' : '.comp16',\r
61 'FV' : '.fv'\r
62 }\r
63\r
64 SectFileType = {\r
65 'SEC_GUID' : '.sec' ,\r
66 'SEC_PE32' : '.sec' ,\r
67 'SEC_PIC' : '.sec',\r
68 'SEC_TE' : '.sec',\r
69 'SEC_VER' : '.sec',\r
70 'SEC_UI' : '.sec',\r
71 'SEC_COMPAT16' : '.sec',\r
72 'SEC_BIN' : '.sec'\r
73 }\r
74\r
75 ToolGuid = {\r
76 '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompress',\r
77 '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompress'\r
78 }\r
79\r
80 ## The constructor\r
81 #\r
82 # @param self The object pointer\r
83 #\r
84 def __init__(self):\r
85 SectionClassObject.__init__(self)\r
86\r
87 ## GenSection() method\r
88 #\r
89 # virtual function\r
90 #\r
91 # @param self The object pointer\r
92 # @param OutputPath Where to place output file\r
93 # @param ModuleName Which module this section belongs to\r
94 # @param SecNum Index of section\r
95 # @param KeyStringList Filter for inputs of section generation\r
96 # @param FfsInf FfsInfStatement object that contains this section data\r
97 # @param Dict dictionary contains macro and its value\r
98 #\r
99 def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}):\r
100 pass\r
101\r
102 ## GetFileList() method\r
103 #\r
104 # Generate compressed section\r
105 #\r
106 # @param self The object pointer\r
107 # @param FfsInf FfsInfStatement object that contains file list\r
108 # @param FileType File type to get\r
109 # @param FileExtension File extension to get\r
110 # @param Dict dictionary contains macro and its value\r
111 # @retval tuple (File list, boolean)\r
112 #\r
cf245466 113 def GetFileList(FfsInf, FileType, FileExtension, Dict = {}, IsMakefile=False):\r
98120f5f 114 IsSect = FileType in Section.SectFileType\r
30fdf114 115\r
4231a819 116 if FileExtension is not None:\r
30fdf114
LG
117 Suffix = FileExtension\r
118 elif IsSect :\r
119 Suffix = Section.SectionType.get(FileType)\r
120 else:\r
121 Suffix = Section.BinFileType.get(FileType)\r
4231a819 122 if FfsInf is None:\r
30fdf114
LG
123 EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!')\r
124\r
125 FileList = []\r
4231a819 126 if FileType is not None:\r
30fdf114
LG
127 for File in FfsInf.BinFileList:\r
128 if File.Arch == "COMMON" or FfsInf.CurrentArch == File.Arch:\r
97fa0ee9
YL
129 if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \\r
130 and FileType == 'DXE_DPEX'and File.Type == 'SMM_DEPEX') \\r
131 or (FileType == 'TE'and File.Type == 'PE32'):\r
30fdf114 132 if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []:\r
97fa0ee9 133 FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type))\r
30fdf114
LG
134 else:\r
135 GenFdsGlobalVariable.InfLogger ("\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" %(File.Target, File.File, FfsInf.TargetOverrideList, FfsInf.InfFileName))\r
136 else:\r
137 GenFdsGlobalVariable.VerboseLogger ("\nFile Type \'%s\' of File %s in %s is not same with file type \'%s\' from Rule in FDF" %(File.Type, File.File, FfsInf.InfFileName, FileType))\r
138 else:\r
139 GenFdsGlobalVariable.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf.CurrentArch, File.File, File.Arch, FfsInf.InfFileName))\r
140\r
4231a819 141 if (not IsMakefile and Suffix is not None and os.path.exists(FfsInf.EfiOutputPath)) or (IsMakefile and Suffix is not None):\r
b74d65ed
LG
142 #\r
143 # Get Makefile path and time stamp\r
144 #\r
145 MakefileDir = FfsInf.EfiOutputPath[:-len('OUTPUT')]\r
146 Makefile = os.path.join(MakefileDir, 'Makefile')\r
147 if not os.path.exists(Makefile):\r
148 Makefile = os.path.join(MakefileDir, 'GNUmakefile')\r
23cc8adb 149 if os.path.exists(Makefile):\r
b74d65ed
LG
150 # Update to search files with suffix in all sub-dirs.\r
151 Tuple = os.walk(FfsInf.EfiOutputPath)\r
152 for Dirpath, Dirnames, Filenames in Tuple:\r
153 for F in Filenames:\r
483b01d2 154 if os.path.splitext(F)[1] == Suffix:\r
b74d65ed
LG
155 FullName = os.path.join(Dirpath, F)\r
156 if os.path.getmtime(FullName) > os.path.getmtime(Makefile):\r
157 FileList.append(FullName)\r
23cc8adb
LG
158 if not FileList:\r
159 SuffixMap = FfsInf.GetFinalTargetSuffixMap()\r
160 if Suffix in SuffixMap:\r
161 FileList.extend(SuffixMap[Suffix])\r
162 \r
52302d4d
LG
163 #Process the file lists is alphabetical for a same section type\r
164 if len (FileList) > 1:\r
165 FileList.sort()\r
166\r
30fdf114
LG
167 return FileList, IsSect\r
168 GetFileList = staticmethod(GetFileList)\r