]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/GenMetaFile/GenMetaFileMisc.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[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, 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 for ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList in ExternList:
32 if Arch or ArchList:
33 if EntryPoint:
34 Statement = '%s = %s' % (DT.TAB_INF_DEFINES_ENTRY_POINT, EntryPoint)
35 if FFE:
36 Statement += ' | %s' % FFE
37 if len(HelpStringList) > 0:
38 Statement = HelpStringList[0].GetString() + '\n' + Statement
39 if len(HelpStringList) > 1:
40 Statement = Statement + HelpStringList[1].GetString()
41 SectionDict[Arch] = SectionDict[Arch] + [Statement]
42 if UnloadImage:
43 Statement = '%s = %s' % (DT.TAB_INF_DEFINES_UNLOAD_IMAGE, UnloadImage)
44 if FFE:
45 Statement += ' | %s' % FFE
46
47 if len(HelpStringList) > 0:
48 Statement = HelpStringList[0].GetString() + '\n' + Statement
49 if len(HelpStringList) > 1:
50 Statement = Statement + HelpStringList[1].GetString()
51 SectionDict[Arch] = SectionDict[Arch] + [Statement]
52 if Constructor:
53 Statement = '%s = %s' % (DT.TAB_INF_DEFINES_CONSTRUCTOR, Constructor)
54 if FFE:
55 Statement += ' | %s' % FFE
56
57 if len(HelpStringList) > 0:
58 Statement = HelpStringList[0].GetString() + '\n' + Statement
59 if len(HelpStringList) > 1:
60 Statement = Statement + HelpStringList[1].GetString()
61 SectionDict[Arch] = SectionDict[Arch] + [Statement]
62 if Destructor:
63 Statement = '%s = %s' % (DT.TAB_INF_DEFINES_DESTRUCTOR, Destructor)
64 if FFE:
65 Statement += ' | %s' % FFE
66
67 if len(HelpStringList) > 0:
68 Statement = HelpStringList[0].GetString() + '\n' + Statement
69 if len(HelpStringList) > 1:
70 Statement = Statement + HelpStringList[1].GetString()
71 SectionDict[Arch] = SectionDict[Arch] + [Statement]
72
73 ## ObtainPcdName
74 #
75 # Using TokenSpaceGuidValue and Token to obtain PcdName from DEC file
76 #
77 def ObtainPcdName(Packages, TokenSpaceGuidValue, Token):
78 for PackageDependency in Packages:
79 #
80 # Generate generic comment
81 #
82 Guid = PackageDependency.GetGuid()
83 Version = PackageDependency.GetVersion()
84
85 #
86 # find package path/name
87 #
88 for PkgInfo in GlobalData.gWSPKG_LIST:
89 if Guid == PkgInfo[1]:
90 if (not Version) or (Version == PkgInfo[2]):
91 Path = PkgInfo[3]
92 break
93
94 DecFile = Dec(Path)
95 DecGuidsDict = DecFile.GetGuidSectionObject().ValueDict
96 DecPcdsDict = DecFile.GetPcdSectionObject().ValueDict
97
98 TokenSpaceGuidName = ''
99 PcdCName = ''
100 TokenSpaceGuidNameFound = False
101 PcdCNameFound = False
102
103 #
104 # Get TokenSpaceGuidCName from Guids section
105 #
106 for GuidKey in DecGuidsDict:
107 GuidList = DecGuidsDict[GuidKey]
108 if TokenSpaceGuidNameFound:
109 break
110 for GuidItem in GuidList:
111 if TokenSpaceGuidValue == GuidItem.GuidString:
112 TokenSpaceGuidName = GuidItem.GuidCName
113 TokenSpaceGuidNameFound = True
114 break
115
116 #
117 # Retrieve PcdCName from Pcds Section
118 #
119 for PcdKey in DecPcdsDict:
120 PcdList = DecPcdsDict[PcdKey]
121 if PcdCNameFound:
122 break
123 for PcdItem in PcdList:
124 if TokenSpaceGuidName == PcdItem.TokenSpaceGuidCName and Token == PcdItem.TokenValue:
125 PcdCName = PcdItem.TokenCName
126 PcdCNameFound = True
127 break
128
129 return TokenSpaceGuidName, PcdCName
130
131 ## _TransferDict
132 # transfer dict that using (Statement, SortedArch) as key,
133 # (GenericComment, UsageComment) as value into a dict that using SortedArch as
134 # key and NewStatement as value
135 #
136 def TransferDict(OrigDict):
137 NewDict = {}
138
139 for Statement, SortedArch in OrigDict:
140 Comment = OrigDict[Statement, SortedArch]
141 #
142 # apply the NComment/1Comment rule
143 #
144 if Comment.find('\n') != len(Comment) - 1:
145 NewStateMent = Comment + Statement
146 else:
147 NewStateMent = Statement + ' ' + Comment.rstrip('\n')
148
149 if SortedArch in NewDict:
150 NewDict[SortedArch] = NewDict[SortedArch] + [NewStateMent]
151 else:
152 NewDict[SortedArch] = [NewStateMent]
153
154 return NewDict
155