]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/GenMetaFile/GenMetaFileMisc.py
BaseTools/UPT: Support Multiple Installation
[mirror_edk2.git] / BaseTools / Source / Python / UPT / GenMetaFile / GenMetaFileMisc.py
1 ## @file GenMetaFileMisc.py
2 #
3 # This file contained the miscellaneous routines for GenMetaFile usage.
4 #
5 # Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
6 #
7 # This program and the accompanying materials are licensed and made available
8 # under the terms and conditions of the BSD License which accompanies this
9 # distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
11 #
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #
15
16 '''
17 GenMetaFileMisc
18 '''
19
20 from Library import DataType as DT
21 from Library import GlobalData
22 from Parser.DecParser import Dec
23
24 # AddExternToDefineSec
25 #
26 # @param SectionDict: string of source file path/name
27 # @param Arch: string of source file family field
28 # @param ExternList: string of source file FeatureFlag field
29 #
30 def AddExternToDefineSec(SectionDict, Arch, ExternList):
31 LeftOffset = 31
32 for ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList in ExternList:
33 if Arch or ArchList:
34 if EntryPoint:
35 Statement = (u'%s ' % DT.TAB_INF_DEFINES_ENTRY_POINT).ljust(LeftOffset) + u'= %s' % EntryPoint
36 if FFE:
37 Statement += ' | %s' % FFE
38 if len(HelpStringList) > 0:
39 Statement = HelpStringList[0].GetString() + '\n' + Statement
40 if len(HelpStringList) > 1:
41 Statement = Statement + HelpStringList[1].GetString()
42 SectionDict[Arch] = SectionDict[Arch] + [Statement]
43
44 if UnloadImage:
45 Statement = (u'%s ' % DT.TAB_INF_DEFINES_UNLOAD_IMAGE).ljust(LeftOffset) + u'= %s' % UnloadImage
46 if FFE:
47 Statement += ' | %s' % FFE
48
49 if len(HelpStringList) > 0:
50 Statement = HelpStringList[0].GetString() + '\n' + Statement
51 if len(HelpStringList) > 1:
52 Statement = Statement + HelpStringList[1].GetString()
53 SectionDict[Arch] = SectionDict[Arch] + [Statement]
54
55 if Constructor:
56 Statement = (u'%s ' % DT.TAB_INF_DEFINES_CONSTRUCTOR).ljust(LeftOffset) + u'= %s' % Constructor
57 if FFE:
58 Statement += ' | %s' % FFE
59
60 if len(HelpStringList) > 0:
61 Statement = HelpStringList[0].GetString() + '\n' + Statement
62 if len(HelpStringList) > 1:
63 Statement = Statement + HelpStringList[1].GetString()
64 SectionDict[Arch] = SectionDict[Arch] + [Statement]
65
66 if Destructor:
67 Statement = (u'%s ' % DT.TAB_INF_DEFINES_DESTRUCTOR).ljust(LeftOffset) + u'= %s' % Destructor
68 if FFE:
69 Statement += ' | %s' % FFE
70
71 if len(HelpStringList) > 0:
72 Statement = HelpStringList[0].GetString() + '\n' + Statement
73 if len(HelpStringList) > 1:
74 Statement = Statement + HelpStringList[1].GetString()
75 SectionDict[Arch] = SectionDict[Arch] + [Statement]
76
77 ## ObtainPcdName
78 #
79 # Using TokenSpaceGuidValue and Token to obtain PcdName from DEC file
80 #
81 def ObtainPcdName(Packages, TokenSpaceGuidValue, Token):
82 TokenSpaceGuidName = ''
83 PcdCName = ''
84 TokenSpaceGuidNameFound = False
85
86 for PackageDependency in Packages:
87 #
88 # Generate generic comment
89 #
90 Guid = PackageDependency.GetGuid()
91 Version = PackageDependency.GetVersion()
92
93 Path = None
94 #
95 # find package path/name
96 #
97 for PkgInfo in GlobalData.gWSPKG_LIST:
98 if Guid == PkgInfo[1]:
99 if (not Version) or (Version == PkgInfo[2]):
100 Path = PkgInfo[3]
101 break
102
103 # The dependency package in workspace
104 if Path:
105 DecFile = None
106 if Path not in GlobalData.gPackageDict:
107 DecFile = Dec(Path)
108 GlobalData.gPackageDict[Path] = DecFile
109 else:
110 DecFile = GlobalData.gPackageDict[Path]
111
112 DecGuidsDict = DecFile.GetGuidSectionObject().ValueDict
113 DecPcdsDict = DecFile.GetPcdSectionObject().ValueDict
114
115 TokenSpaceGuidName = ''
116 PcdCName = ''
117 TokenSpaceGuidNameFound = False
118
119 #
120 # Get TokenSpaceGuidCName from Guids section
121 #
122 for GuidKey in DecGuidsDict:
123 GuidList = DecGuidsDict[GuidKey]
124 for GuidItem in GuidList:
125 if TokenSpaceGuidValue.upper() == GuidItem.GuidString.upper():
126 TokenSpaceGuidName = GuidItem.GuidCName
127 TokenSpaceGuidNameFound = True
128 break
129 if TokenSpaceGuidNameFound:
130 break
131 #
132 # Retrieve PcdCName from Pcds Section
133 #
134 for PcdKey in DecPcdsDict:
135 PcdList = DecPcdsDict[PcdKey]
136 for PcdItem in PcdList:
137 if TokenSpaceGuidName == PcdItem.TokenSpaceGuidCName and Token == PcdItem.TokenValue:
138 PcdCName = PcdItem.TokenCName
139 return TokenSpaceGuidName, PcdCName
140
141 # The dependency package in ToBeInstalledDist
142 else:
143 for Dist in GlobalData.gTO_BE_INSTALLED_DIST_LIST:
144 for Package in Dist.PackageSurfaceArea.values():
145 if Guid == Package.Guid:
146 for GuidItem in Package.GuidList:
147 if TokenSpaceGuidValue.upper() == GuidItem.Guid.upper():
148 TokenSpaceGuidName = GuidItem.CName
149 TokenSpaceGuidNameFound = True
150 break
151 for PcdItem in Package.PcdList:
152 if TokenSpaceGuidName == PcdItem.TokenSpaceGuidCName and Token == PcdItem.Token:
153 PcdCName = PcdItem.CName
154 return TokenSpaceGuidName, PcdCName
155
156 return TokenSpaceGuidName, PcdCName
157
158 ## _TransferDict
159 # transfer dict that using (Statement, SortedArch) as key,
160 # (GenericComment, UsageComment) as value into a dict that using SortedArch as
161 # key and NewStatement as value
162 #
163 def TransferDict(OrigDict, Type=None):
164 NewDict = {}
165 LeftOffset = 0
166 if Type in ['INF_GUID', 'INF_PPI_PROTOCOL']:
167 LeftOffset = 45
168 if Type in ['INF_PCD']:
169 LeftOffset = 75
170 if LeftOffset > 0:
171 for Statement, SortedArch in OrigDict:
172 if len(Statement) > LeftOffset:
173 LeftOffset = len(Statement)
174
175 for Statement, SortedArch in OrigDict:
176 Comment = OrigDict[Statement, SortedArch]
177 #
178 # apply the NComment/1Comment rule
179 #
180 if Comment.find('\n') != len(Comment) - 1:
181 NewStateMent = Comment + Statement
182 else:
183 if LeftOffset:
184 NewStateMent = Statement.ljust(LeftOffset) + ' ' + Comment.rstrip('\n')
185 else:
186 NewStateMent = Statement + ' ' + Comment.rstrip('\n')
187
188 if SortedArch in NewDict:
189 NewDict[SortedArch] = NewDict[SortedArch] + [NewStateMent]
190 else:
191 NewDict[SortedArch] = [NewStateMent]
192
193 return NewDict
194