]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/GenMetaFile/GenMetaFileMisc.py
3c6c9ee2907e7dc0cd7244fc2595daf146b0b78c
[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 for PackageDependency in Packages:
83 #
84 # Generate generic comment
85 #
86 Guid = PackageDependency.GetGuid()
87 Version = PackageDependency.GetVersion()
88
89 #
90 # find package path/name
91 #
92 for PkgInfo in GlobalData.gWSPKG_LIST:
93 if Guid == PkgInfo[1]:
94 if (not Version) or (Version == PkgInfo[2]):
95 Path = PkgInfo[3]
96 break
97
98 DecFile = None
99 if Path not in GlobalData.gPackageDict:
100 DecFile = Dec(Path)
101 GlobalData.gPackageDict[Path] = DecFile
102 else:
103 DecFile = GlobalData.gPackageDict[Path]
104
105 DecGuidsDict = DecFile.GetGuidSectionObject().ValueDict
106 DecPcdsDict = DecFile.GetPcdSectionObject().ValueDict
107
108 TokenSpaceGuidName = ''
109 PcdCName = ''
110 TokenSpaceGuidNameFound = False
111
112 #
113 # Get TokenSpaceGuidCName from Guids section
114 #
115 for GuidKey in DecGuidsDict:
116 GuidList = DecGuidsDict[GuidKey]
117 for GuidItem in GuidList:
118 if TokenSpaceGuidValue.upper() == GuidItem.GuidString.upper():
119 TokenSpaceGuidName = GuidItem.GuidCName
120 TokenSpaceGuidNameFound = True
121 break
122 if TokenSpaceGuidNameFound:
123 break
124 #
125 # Retrieve PcdCName from Pcds Section
126 #
127 for PcdKey in DecPcdsDict:
128 PcdList = DecPcdsDict[PcdKey]
129 for PcdItem in PcdList:
130 if TokenSpaceGuidName == PcdItem.TokenSpaceGuidCName and Token == PcdItem.TokenValue:
131 PcdCName = PcdItem.TokenCName
132 return TokenSpaceGuidName, PcdCName
133
134 return TokenSpaceGuidName, PcdCName
135
136 ## _TransferDict
137 # transfer dict that using (Statement, SortedArch) as key,
138 # (GenericComment, UsageComment) as value into a dict that using SortedArch as
139 # key and NewStatement as value
140 #
141 def TransferDict(OrigDict, Type=None):
142 NewDict = {}
143 LeftOffset = 0
144 if Type in ['INF_GUID', 'INF_PPI_PROTOCOL']:
145 LeftOffset = 45
146 if Type in ['INF_PCD']:
147 LeftOffset = 75
148 if LeftOffset > 0:
149 for Statement, SortedArch in OrigDict:
150 if len(Statement) > LeftOffset:
151 LeftOffset = len(Statement)
152
153 for Statement, SortedArch in OrigDict:
154 Comment = OrigDict[Statement, SortedArch]
155 #
156 # apply the NComment/1Comment rule
157 #
158 if Comment.find('\n') != len(Comment) - 1:
159 NewStateMent = Comment + Statement
160 else:
161 if LeftOffset:
162 NewStateMent = Statement.ljust(LeftOffset) + ' ' + Comment.rstrip('\n')
163 else:
164 NewStateMent = Statement + ' ' + Comment.rstrip('\n')
165
166 if SortedArch in NewDict:
167 NewDict[SortedArch] = NewDict[SortedArch] + [NewStateMent]
168 else:
169 NewDict[SortedArch] = [NewStateMent]
170
171 return NewDict
172