]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Library/CommentGenerating.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Library / CommentGenerating.py
CommitLineData
4234283c
LG
1## @file\r
2# This file is used to define comment generating interface\r
3#\r
4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# This program and the accompanying materials are licensed and made available \r
7# under the terms and conditions of the BSD License which accompanies this \r
8# distribution. The full text of the license may be found at \r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15'''\r
16CommentGenerating\r
17'''\r
18\r
19##\r
20# Import Modules\r
21#\r
22from Library.String import GetSplitValueList\r
23from Library.DataType import TAB_SPACE_SPLIT\r
24from Library.DataType import TAB_INF_GUIDTYPE_VAR\r
25from Library.DataType import USAGE_ITEM_NOTIFY\r
26from Library.DataType import ITEM_UNDEFINED\r
27from Library.DataType import LANGUAGE_EN_US\r
28\r
29## GenTailCommentLines\r
30#\r
31# @param TailCommentLines: the tail comment lines that need to be generated\r
32# @param LeadingSpaceNum: the number of leading space needed for non-first \r
33# line tail comment\r
34# \r
35def GenTailCommentLines (TailCommentLines, LeadingSpaceNum = 0):\r
36 EndOfLine = "\n"\r
37 TailCommentLines = TailCommentLines.rstrip(EndOfLine)\r
38 CommentStr = " ## " + (EndOfLine + LeadingSpaceNum * TAB_SPACE_SPLIT + \\r
39 " ## ").join(GetSplitValueList(TailCommentLines, \\r
40 EndOfLine))\r
41 return CommentStr\r
42\r
43## GenGenericComment\r
44#\r
45# @param CommentLines: Generic comment Text, maybe Multiple Lines\r
46# \r
47def GenGenericComment (CommentLines):\r
48 if not CommentLines:\r
49 return ''\r
50 EndOfLine = "\n"\r
51 CommentLines = CommentLines.rstrip(EndOfLine)\r
52 CommentStr = '## ' + (EndOfLine + '# ').join\\r
53 (GetSplitValueList(CommentLines, EndOfLine)) + EndOfLine\r
54 return CommentStr\r
55\r
56## GenGenericCommentF\r
57#\r
58# similar to GenGenericComment but will remove <EOL> at end of comment once,\r
59# and for line with only <EOL>, '#\n' will be generated instead of '# \n'\r
60#\r
61# @param CommentLines: Generic comment Text, maybe Multiple Lines\r
62# @return CommentStr: Generated comment line \r
63# \r
64def GenGenericCommentF (CommentLines, NumOfPound=1):\r
65 if not CommentLines:\r
66 return ''\r
67 EndOfLine = "\n"\r
68 #\r
69 # if comment end with '\n', then remove it to prevent one extra line\r
70 # generate later on\r
71 #\r
72 if CommentLines.endswith(EndOfLine):\r
73 CommentLines = CommentLines[:-1]\r
74 CommentLineList = GetSplitValueList(CommentLines, EndOfLine)\r
75 CommentStr = ''\r
76 for Line in CommentLineList:\r
77 if Line == '':\r
78 CommentStr += '#' * NumOfPound + '\n'\r
79 else:\r
80 CommentStr += '#' * NumOfPound + ' ' + Line + '\n'\r
81 \r
82 return CommentStr\r
83\r
84\r
85## GenHeaderCommentSection\r
86#\r
87# Generate Header comment sections\r
88#\r
89# @param Abstract One line of abstract \r
90# @param Description multiple lines of Description\r
91# @param Copyright possible multiple copyright lines\r
92# @param License possible multiple license lines\r
93#\r
94def GenHeaderCommentSection(Abstract, Description, Copyright, License):\r
95 EndOfLine = '\n'\r
96 Content = ''\r
97 \r
98 Content += '## @file' + EndOfLine\r
99 if Abstract:\r
100 Abstract = Abstract.rstrip(EndOfLine)\r
101 Content += '# ' + Abstract + EndOfLine\r
102 Content += '#' + EndOfLine\r
103 else:\r
104 Content += '#' + EndOfLine\r
105\r
106 if Description:\r
107 Description = Description.rstrip(EndOfLine)\r
108 Content += '# ' + (EndOfLine + '# ').join(GetSplitValueList\\r
109 (Description, '\n'))\r
110 Content += EndOfLine + '#' + EndOfLine \r
111 \r
112 #\r
113 # There is no '#\n' line to separate multiple copyright lines in code base \r
114 #\r
115 if Copyright:\r
116 Copyright = Copyright.rstrip(EndOfLine)\r
117 Content += '# ' + (EndOfLine + '# ').join\\r
118 (GetSplitValueList(Copyright, '\n'))\r
119 Content += EndOfLine + '#' + EndOfLine\r
120\r
121 if License:\r
122 License = License.rstrip(EndOfLine)\r
123 Content += '# ' + (EndOfLine + '# ').join(GetSplitValueList\\r
124 (License, '\n'))\r
125 Content += EndOfLine + '#' + EndOfLine\r
126\r
127 Content += '##' + EndOfLine\r
128 \r
129 return Content\r
130\r
131\r
132## GenInfPcdTailComment\r
133# Generate Pcd tail comment for Inf, this would be one line comment\r
134#\r
135# @param Usage: Usage type\r
136# @param TailCommentText: Comment text for tail comment\r
137# \r
138def GenInfPcdTailComment (Usage, TailCommentText):\r
139 if (Usage == ITEM_UNDEFINED) and (not TailCommentText):\r
140 return ''\r
141 \r
142 CommentLine = TAB_SPACE_SPLIT.join([Usage, TailCommentText])\r
143 return GenTailCommentLines(CommentLine)\r
144\r
145## GenInfProtocolPPITailComment\r
146# Generate Protocol/PPI tail comment for Inf\r
147#\r
148# @param Usage: Usage type\r
149# @param TailCommentText: Comment text for tail comment\r
150# \r
151def GenInfProtocolPPITailComment (Usage, Notify, TailCommentText):\r
152 if (not Notify) and (Usage == ITEM_UNDEFINED) and (not TailCommentText):\r
153 return ''\r
154 \r
155 if Notify:\r
156 CommentLine = USAGE_ITEM_NOTIFY + " ## "\r
157 else:\r
158 CommentLine = ''\r
159 \r
160 CommentLine += TAB_SPACE_SPLIT.join([Usage, TailCommentText])\r
161 return GenTailCommentLines(CommentLine)\r
162\r
163## GenInfGuidTailComment\r
164# Generate Guid tail comment for Inf\r
165#\r
166# @param Usage: Usage type\r
167# @param TailCommentText: Comment text for tail comment\r
168# \r
169def GenInfGuidTailComment (Usage, GuidTypeList, VariableName, TailCommentText):\r
170 GuidType = GuidTypeList[0]\r
171 if (Usage == ITEM_UNDEFINED) and (GuidType == ITEM_UNDEFINED) and \\r
172 (not TailCommentText):\r
173 return ''\r
174 \r
175 FirstLine = Usage + " ## " + GuidType \r
176 if GuidType == TAB_INF_GUIDTYPE_VAR:\r
177 FirstLine += ":" + VariableName\r
178 \r
179 CommentLine = TAB_SPACE_SPLIT.join([FirstLine, TailCommentText])\r
180 return GenTailCommentLines(CommentLine)\r
181\r
182## GenDecGuidTailComment\r
183#\r
184# @param SupModuleList: Supported module type list\r
185# \r
186def GenDecTailComment (SupModuleList): \r
187 CommentLine = TAB_SPACE_SPLIT.join(SupModuleList)\r
188 return GenTailCommentLines(CommentLine)\r
189\r
190\r
191## _GetHelpStr\r
192# get HelpString from a list of HelpTextObject, the priority refer to \r
193# related HLD\r
194#\r
195# @param HelpTextObjList: List of HelpTextObject\r
196# \r
197# @return HelpStr: the help text string found, '' means no help text found\r
198#\r
199def _GetHelpStr(HelpTextObjList):\r
200 HelpStr = ''\r
201\r
202 for HelpObj in HelpTextObjList:\r
203 if HelpObj and HelpObj.GetLang() == LANGUAGE_EN_US:\r
204 HelpStr = HelpObj.GetString()\r
205 return HelpStr\r
206 \r
207 for HelpObj in HelpTextObjList:\r
208 if HelpObj and HelpObj.GetLang().startswith('en'):\r
209 HelpStr = HelpObj.GetString()\r
210 return HelpStr\r
211\r
212 for HelpObj in HelpTextObjList:\r
213 if HelpObj and not HelpObj.GetLang():\r
214 HelpStr = HelpObj.GetString()\r
215 return HelpStr\r
216 \r
217 return HelpStr