1 ## @file GenMetaFileMisc.py
3 # This file contained the miscellaneous routines for GenMetaFile usage.
5 # Copyright (c) 2011 - 2014, 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 for PackageDependency
in Packages
:
84 # Generate generic comment
86 Guid
= PackageDependency
.GetGuid()
87 Version
= PackageDependency
.GetVersion()
90 # find package path/name
92 for PkgInfo
in GlobalData
.gWSPKG_LIST
:
93 if Guid
== PkgInfo
[1]:
94 if (not Version
) or (Version
== PkgInfo
[2]):
99 if Path
not in GlobalData
.gPackageDict
:
101 GlobalData
.gPackageDict
[Path
] = DecFile
103 DecFile
= GlobalData
.gPackageDict
[Path
]
105 DecGuidsDict
= DecFile
.GetGuidSectionObject().ValueDict
106 DecPcdsDict
= DecFile
.GetPcdSectionObject().ValueDict
108 TokenSpaceGuidName
= ''
110 TokenSpaceGuidNameFound
= False
111 PcdCNameFound
= False
114 # Get TokenSpaceGuidCName from Guids section
116 for GuidKey
in DecGuidsDict
:
117 GuidList
= DecGuidsDict
[GuidKey
]
118 if TokenSpaceGuidNameFound
:
120 for GuidItem
in GuidList
:
121 if TokenSpaceGuidValue
.upper() == GuidItem
.GuidString
.upper():
122 TokenSpaceGuidName
= GuidItem
.GuidCName
123 TokenSpaceGuidNameFound
= True
127 # Retrieve PcdCName from Pcds Section
129 for PcdKey
in DecPcdsDict
:
130 PcdList
= DecPcdsDict
[PcdKey
]
132 return TokenSpaceGuidName
, PcdCName
133 for PcdItem
in PcdList
:
134 if TokenSpaceGuidName
== PcdItem
.TokenSpaceGuidCName
and Token
== PcdItem
.TokenValue
:
135 PcdCName
= PcdItem
.TokenCName
139 return TokenSpaceGuidName
, PcdCName
142 # transfer dict that using (Statement, SortedArch) as key,
143 # (GenericComment, UsageComment) as value into a dict that using SortedArch as
144 # key and NewStatement as value
146 def TransferDict(OrigDict
, Type
=None):
149 if Type
in ['INF_GUID', 'INF_PPI_PROTOCOL']:
151 if Type
in ['INF_PCD']:
154 for Statement
, SortedArch
in OrigDict
:
155 if len(Statement
) > LeftOffset
:
156 LeftOffset
= len(Statement
)
158 for Statement
, SortedArch
in OrigDict
:
159 Comment
= OrigDict
[Statement
, SortedArch
]
161 # apply the NComment/1Comment rule
163 if Comment
.find('\n') != len(Comment
) - 1:
164 NewStateMent
= Comment
+ Statement
167 NewStateMent
= Statement
.ljust(LeftOffset
) + ' ' + Comment
.rstrip('\n')
169 NewStateMent
= Statement
+ ' ' + Comment
.rstrip('\n')
171 if SortedArch
in NewDict
:
172 NewDict
[SortedArch
] = NewDict
[SortedArch
] + [NewStateMent
]
174 NewDict
[SortedArch
] = [NewStateMent
]