]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file GenMetaFileMisc.py\r |
2 | #\r | |
3 | # This file contained the miscellaneous routines for GenMetaFile usage.\r | |
4 | #\r | |
5 | # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
6 | #\r | |
7 | # This program and the accompanying materials are licensed and made available \r | |
8 | # under the terms and conditions of the BSD License which accompanies this \r | |
9 | # distribution. The full text of the license may be found at \r | |
10 | # http://opensource.org/licenses/bsd-license.php\r | |
11 | #\r | |
12 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | #\r | |
15 | \r | |
16 | '''\r | |
17 | GenMetaFileMisc\r | |
18 | '''\r | |
19 | \r | |
20 | from Library import DataType as DT\r | |
21 | from Library import GlobalData\r | |
22 | from Parser.DecParser import Dec\r | |
23 | \r | |
24 | # AddExternToDefineSec\r | |
25 | #\r | |
26 | # @param SectionDict: string of source file path/name\r | |
27 | # @param Arch: string of source file family field\r | |
28 | # @param ExternList: string of source file FeatureFlag field\r | |
29 | # \r | |
30 | def AddExternToDefineSec(SectionDict, Arch, ExternList):\r | |
31 | for ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList in ExternList:\r | |
32 | if Arch or ArchList:\r | |
33 | if EntryPoint:\r | |
34 | Statement = '%s = %s' % (DT.TAB_INF_DEFINES_ENTRY_POINT, EntryPoint)\r | |
35 | if FFE:\r | |
36 | Statement += ' | %s' % FFE\r | |
37 | if len(HelpStringList) > 0:\r | |
38 | Statement = HelpStringList[0].GetString() + '\n' + Statement\r | |
39 | if len(HelpStringList) > 1:\r | |
40 | Statement = Statement + HelpStringList[1].GetString()\r | |
41 | SectionDict[Arch] = SectionDict[Arch] + [Statement]\r | |
42 | if UnloadImage:\r | |
43 | Statement = '%s = %s' % (DT.TAB_INF_DEFINES_UNLOAD_IMAGE, UnloadImage)\r | |
44 | if FFE:\r | |
45 | Statement += ' | %s' % FFE\r | |
46 | \r | |
47 | if len(HelpStringList) > 0:\r | |
48 | Statement = HelpStringList[0].GetString() + '\n' + Statement\r | |
49 | if len(HelpStringList) > 1:\r | |
50 | Statement = Statement + HelpStringList[1].GetString()\r | |
51 | SectionDict[Arch] = SectionDict[Arch] + [Statement]\r | |
52 | if Constructor:\r | |
53 | Statement = '%s = %s' % (DT.TAB_INF_DEFINES_CONSTRUCTOR, Constructor)\r | |
54 | if FFE:\r | |
55 | Statement += ' | %s' % FFE\r | |
56 | \r | |
57 | if len(HelpStringList) > 0:\r | |
58 | Statement = HelpStringList[0].GetString() + '\n' + Statement\r | |
59 | if len(HelpStringList) > 1:\r | |
60 | Statement = Statement + HelpStringList[1].GetString() \r | |
61 | SectionDict[Arch] = SectionDict[Arch] + [Statement] \r | |
62 | if Destructor:\r | |
63 | Statement = '%s = %s' % (DT.TAB_INF_DEFINES_DESTRUCTOR, Destructor)\r | |
64 | if FFE:\r | |
65 | Statement += ' | %s' % FFE\r | |
66 | \r | |
67 | if len(HelpStringList) > 0:\r | |
68 | Statement = HelpStringList[0].GetString() + '\n' + Statement\r | |
69 | if len(HelpStringList) > 1:\r | |
70 | Statement = Statement + HelpStringList[1].GetString()\r | |
71 | SectionDict[Arch] = SectionDict[Arch] + [Statement]\r | |
72 | \r | |
73 | ## ObtainPcdName\r | |
74 | #\r | |
75 | # Using TokenSpaceGuidValue and Token to obtain PcdName from DEC file\r | |
76 | #\r | |
77 | def ObtainPcdName(Packages, TokenSpaceGuidValue, Token):\r | |
78 | for PackageDependency in Packages:\r | |
79 | #\r | |
80 | # Generate generic comment\r | |
81 | #\r | |
82 | Guid = PackageDependency.GetGuid()\r | |
83 | Version = PackageDependency.GetVersion()\r | |
84 | \r | |
85 | #\r | |
86 | # find package path/name\r | |
87 | # \r | |
88 | for PkgInfo in GlobalData.gWSPKG_LIST:\r | |
89 | if Guid == PkgInfo[1]:\r | |
90 | if (not Version) or (Version == PkgInfo[2]):\r | |
91 | Path = PkgInfo[3]\r | |
92 | break\r | |
93 | \r | |
94 | DecFile = Dec(Path)\r | |
95 | DecGuidsDict = DecFile.GetGuidSectionObject().ValueDict\r | |
96 | DecPcdsDict = DecFile.GetPcdSectionObject().ValueDict\r | |
97 | \r | |
98 | TokenSpaceGuidName = ''\r | |
99 | PcdCName = ''\r | |
100 | TokenSpaceGuidNameFound = False\r | |
101 | PcdCNameFound = False\r | |
102 | \r | |
103 | #\r | |
104 | # Get TokenSpaceGuidCName from Guids section \r | |
105 | #\r | |
106 | for GuidKey in DecGuidsDict:\r | |
107 | GuidList = DecGuidsDict[GuidKey]\r | |
108 | if TokenSpaceGuidNameFound:\r | |
109 | break\r | |
110 | for GuidItem in GuidList:\r | |
111 | if TokenSpaceGuidValue == GuidItem.GuidString:\r | |
112 | TokenSpaceGuidName = GuidItem.GuidCName\r | |
113 | TokenSpaceGuidNameFound = True\r | |
114 | break\r | |
115 | \r | |
116 | #\r | |
117 | # Retrieve PcdCName from Pcds Section\r | |
118 | #\r | |
119 | for PcdKey in DecPcdsDict:\r | |
120 | PcdList = DecPcdsDict[PcdKey]\r | |
121 | if PcdCNameFound:\r | |
122 | break\r | |
123 | for PcdItem in PcdList:\r | |
124 | if TokenSpaceGuidName == PcdItem.TokenSpaceGuidCName and Token == PcdItem.TokenValue:\r | |
125 | PcdCName = PcdItem.TokenCName\r | |
126 | PcdCNameFound = True\r | |
127 | break \r | |
128 | \r | |
129 | return TokenSpaceGuidName, PcdCName\r | |
130 | \r | |
131 | ## _TransferDict\r | |
132 | # transfer dict that using (Statement, SortedArch) as key, \r | |
133 | # (GenericComment, UsageComment) as value into a dict that using SortedArch as\r | |
134 | # key and NewStatement as value \r | |
135 | #\r | |
136 | def TransferDict(OrigDict):\r | |
137 | NewDict = {}\r | |
138 | \r | |
139 | for Statement, SortedArch in OrigDict:\r | |
140 | Comment = OrigDict[Statement, SortedArch]\r | |
141 | #\r | |
142 | # apply the NComment/1Comment rule\r | |
143 | #\r | |
144 | if Comment.find('\n') != len(Comment) - 1: \r | |
145 | NewStateMent = Comment + Statement\r | |
146 | else:\r | |
147 | NewStateMent = Statement + ' ' + Comment.rstrip('\n')\r | |
148 | \r | |
149 | if SortedArch in NewDict:\r | |
150 | NewDict[SortedArch] = NewDict[SortedArch] + [NewStateMent]\r | |
151 | else:\r | |
152 | NewDict[SortedArch] = [NewStateMent]\r | |
153 | \r | |
154 | return NewDict \r | |
155 |