1 ## @file GenMetaFileMisc.py
3 # This file contained the miscellaneous routines for GenMetaFile usage.
5 # Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
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
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.
20 from Library
import DataType
as DT
21 from Library
import GlobalData
22 from Parser
.DecParser
import Dec
24 # AddExternToDefineSec
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
30 def AddExternToDefineSec(SectionDict
, Arch
, ExternList
):
32 for ArchList
, EntryPoint
, UnloadImage
, Constructor
, Destructor
, FFE
, HelpStringList
in ExternList
:
35 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_ENTRY_POINT
).ljust(LeftOffset
) + u
'= %s' % EntryPoint
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
]
45 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_UNLOAD_IMAGE
).ljust(LeftOffset
) + u
'= %s' % UnloadImage
47 Statement
+= ' | %s' % FFE
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
]
56 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_CONSTRUCTOR
).ljust(LeftOffset
) + u
'= %s' % Constructor
58 Statement
+= ' | %s' % FFE
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
]
67 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_DESTRUCTOR
).ljust(LeftOffset
) + u
'= %s' % Destructor
69 Statement
+= ' | %s' % FFE
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
]
79 # Using TokenSpaceGuidValue and Token to obtain PcdName from DEC file
81 def ObtainPcdName(Packages
, TokenSpaceGuidValue
, Token
):
82 TokenSpaceGuidName
= ''
84 TokenSpaceGuidNameFound
= False
86 for PackageDependency
in Packages
:
88 # Generate generic comment
90 Guid
= PackageDependency
.GetGuid()
91 Version
= PackageDependency
.GetVersion()
95 # find package path/name
97 for PkgInfo
in GlobalData
.gWSPKG_LIST
:
98 if Guid
== PkgInfo
[1]:
99 if (not Version
) or (Version
== PkgInfo
[2]):
103 # The dependency package in workspace
106 if Path
not in GlobalData
.gPackageDict
:
108 GlobalData
.gPackageDict
[Path
] = DecFile
110 DecFile
= GlobalData
.gPackageDict
[Path
]
112 DecGuidsDict
= DecFile
.GetGuidSectionObject().ValueDict
113 DecPcdsDict
= DecFile
.GetPcdSectionObject().ValueDict
115 TokenSpaceGuidName
= ''
117 TokenSpaceGuidNameFound
= False
120 # Get TokenSpaceGuidCName from Guids section
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
129 if TokenSpaceGuidNameFound
:
132 # Retrieve PcdCName from Pcds Section
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
141 # The dependency package in ToBeInstalledDist
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
151 for PcdItem
in Package
.PcdList
:
152 if TokenSpaceGuidName
== PcdItem
.TokenSpaceGuidCName
and Token
== PcdItem
.Token
:
153 PcdCName
= PcdItem
.CName
154 return TokenSpaceGuidName
, PcdCName
156 return TokenSpaceGuidName
, PcdCName
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
163 def TransferDict(OrigDict
, Type
=None):
166 if Type
in ['INF_GUID', 'INF_PPI_PROTOCOL']:
168 if Type
in ['INF_PCD']:
171 for Statement
, SortedArch
in OrigDict
:
172 if len(Statement
) > LeftOffset
:
173 LeftOffset
= len(Statement
)
175 for Statement
, SortedArch
in OrigDict
:
176 Comment
= OrigDict
[Statement
, SortedArch
]
178 # apply the NComment/1Comment rule
180 if Comment
.find('\n') != len(Comment
) - 1:
181 NewStateMent
= Comment
+ Statement
184 NewStateMent
= Statement
.ljust(LeftOffset
) + ' ' + Comment
.rstrip('\n')
186 NewStateMent
= Statement
+ ' ' + Comment
.rstrip('\n')
188 if SortedArch
in NewDict
:
189 NewDict
[SortedArch
] = NewDict
[SortedArch
] + [NewStateMent
]
191 NewDict
[SortedArch
] = [NewStateMent
]