1 ## @file GenMetaFileMisc.py
3 # This file contained the miscellaneous routines for GenMetaFile usage.
5 # Copyright (c) 2011, 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
):
31 for ArchList
, EntryPoint
, UnloadImage
, Constructor
, Destructor
, FFE
, HelpStringList
in ExternList
:
34 Statement
= '%s = %s' % (DT
.TAB_INF_DEFINES_ENTRY_POINT
, EntryPoint
)
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
]
43 Statement
= '%s = %s' % (DT
.TAB_INF_DEFINES_UNLOAD_IMAGE
, UnloadImage
)
45 Statement
+= ' | %s' % FFE
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
]
53 Statement
= '%s = %s' % (DT
.TAB_INF_DEFINES_CONSTRUCTOR
, Constructor
)
55 Statement
+= ' | %s' % FFE
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
]
63 Statement
= '%s = %s' % (DT
.TAB_INF_DEFINES_DESTRUCTOR
, Destructor
)
65 Statement
+= ' | %s' % FFE
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
]
75 # Using TokenSpaceGuidValue and Token to obtain PcdName from DEC file
77 def ObtainPcdName(Packages
, TokenSpaceGuidValue
, Token
):
78 for PackageDependency
in Packages
:
80 # Generate generic comment
82 Guid
= PackageDependency
.GetGuid()
83 Version
= PackageDependency
.GetVersion()
86 # find package path/name
88 for PkgInfo
in GlobalData
.gWSPKG_LIST
:
89 if Guid
== PkgInfo
[1]:
90 if (not Version
) or (Version
== PkgInfo
[2]):
95 DecGuidsDict
= DecFile
.GetGuidSectionObject().ValueDict
96 DecPcdsDict
= DecFile
.GetPcdSectionObject().ValueDict
98 TokenSpaceGuidName
= ''
100 TokenSpaceGuidNameFound
= False
101 PcdCNameFound
= False
104 # Get TokenSpaceGuidCName from Guids section
106 for GuidKey
in DecGuidsDict
:
107 GuidList
= DecGuidsDict
[GuidKey
]
108 if TokenSpaceGuidNameFound
:
110 for GuidItem
in GuidList
:
111 if TokenSpaceGuidValue
== GuidItem
.GuidString
:
112 TokenSpaceGuidName
= GuidItem
.GuidCName
113 TokenSpaceGuidNameFound
= True
117 # Retrieve PcdCName from Pcds Section
119 for PcdKey
in DecPcdsDict
:
120 PcdList
= DecPcdsDict
[PcdKey
]
123 for PcdItem
in PcdList
:
124 if TokenSpaceGuidName
== PcdItem
.TokenSpaceGuidCName
and Token
== PcdItem
.TokenValue
:
125 PcdCName
= PcdItem
.TokenCName
129 return TokenSpaceGuidName
, PcdCName
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
136 def TransferDict(OrigDict
):
139 for Statement
, SortedArch
in OrigDict
:
140 Comment
= OrigDict
[Statement
, SortedArch
]
142 # apply the NComment/1Comment rule
144 if Comment
.find('\n') != len(Comment
) - 1:
145 NewStateMent
= Comment
+ Statement
147 NewStateMent
= Statement
+ ' ' + Comment
.rstrip('\n')
149 if SortedArch
in NewDict
:
150 NewDict
[SortedArch
] = NewDict
[SortedArch
] + [NewStateMent
]
152 NewDict
[SortedArch
] = [NewStateMent
]