]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Library/CommentGenerating.py
2 # This file is used to define comment generating interface
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 from Library
.String
import GetSplitValueList
23 from Library
.DataType
import TAB_SPACE_SPLIT
24 from Library
.DataType
import TAB_INF_GUIDTYPE_VAR
25 from Library
.DataType
import USAGE_ITEM_NOTIFY
26 from Library
.DataType
import ITEM_UNDEFINED
27 from Library
.DataType
import LANGUAGE_EN_US
29 ## GenTailCommentLines
31 # @param TailCommentLines: the tail comment lines that need to be generated
32 # @param LeadingSpaceNum: the number of leading space needed for non-first
35 def GenTailCommentLines (TailCommentLines
, LeadingSpaceNum
= 0):
37 TailCommentLines
= TailCommentLines
.rstrip(EndOfLine
)
38 CommentStr
= " ## " + (EndOfLine
+ LeadingSpaceNum
* TAB_SPACE_SPLIT
+ \
39 " ## ").join(GetSplitValueList(TailCommentLines
, \
45 # @param CommentLines: Generic comment Text, maybe Multiple Lines
47 def GenGenericComment (CommentLines
):
51 CommentLines
= CommentLines
.rstrip(EndOfLine
)
52 CommentStr
= '## ' + (EndOfLine
+ '# ').join\
53 (GetSplitValueList(CommentLines
, EndOfLine
)) + EndOfLine
58 # similar to GenGenericComment but will remove <EOL> at end of comment once,
59 # and for line with only <EOL>, '#\n' will be generated instead of '# \n'
61 # @param CommentLines: Generic comment Text, maybe Multiple Lines
62 # @return CommentStr: Generated comment line
64 def GenGenericCommentF (CommentLines
, NumOfPound
=1):
69 # if comment end with '\n', then remove it to prevent one extra line
72 if CommentLines
.endswith(EndOfLine
):
73 CommentLines
= CommentLines
[:-1]
74 CommentLineList
= GetSplitValueList(CommentLines
, EndOfLine
)
76 for Line
in CommentLineList
:
78 CommentStr
+= '#' * NumOfPound
+ '\n'
80 CommentStr
+= '#' * NumOfPound
+ ' ' + Line
+ '\n'
85 ## GenHeaderCommentSection
87 # Generate Header comment sections
89 # @param Abstract One line of abstract
90 # @param Description multiple lines of Description
91 # @param Copyright possible multiple copyright lines
92 # @param License possible multiple license lines
94 def GenHeaderCommentSection(Abstract
, Description
, Copyright
, License
):
98 Content
+= '## @file' + EndOfLine
100 Abstract
= Abstract
.rstrip(EndOfLine
)
101 Content
+= '# ' + Abstract
+ EndOfLine
102 Content
+= '#' + EndOfLine
104 Content
+= '#' + EndOfLine
107 Description
= Description
.rstrip(EndOfLine
)
108 Content
+= '# ' + (EndOfLine
+ '# ').join(GetSplitValueList\
110 Content
+= EndOfLine
+ '#' + EndOfLine
113 # There is no '#\n' line to separate multiple copyright lines in code base
116 Copyright
= Copyright
.rstrip(EndOfLine
)
117 Content
+= '# ' + (EndOfLine
+ '# ').join\
118 (GetSplitValueList(Copyright
, '\n'))
119 Content
+= EndOfLine
+ '#' + EndOfLine
122 License
= License
.rstrip(EndOfLine
)
123 Content
+= '# ' + (EndOfLine
+ '# ').join(GetSplitValueList\
125 Content
+= EndOfLine
+ '#' + EndOfLine
127 Content
+= '##' + EndOfLine
132 ## GenInfPcdTailComment
133 # Generate Pcd tail comment for Inf, this would be one line comment
135 # @param Usage: Usage type
136 # @param TailCommentText: Comment text for tail comment
138 def GenInfPcdTailComment (Usage
, TailCommentText
):
139 if (Usage
== ITEM_UNDEFINED
) and (not TailCommentText
):
142 CommentLine
= TAB_SPACE_SPLIT
.join([Usage
, TailCommentText
])
143 return GenTailCommentLines(CommentLine
)
145 ## GenInfProtocolPPITailComment
146 # Generate Protocol/PPI tail comment for Inf
148 # @param Usage: Usage type
149 # @param TailCommentText: Comment text for tail comment
151 def GenInfProtocolPPITailComment (Usage
, Notify
, TailCommentText
):
152 if (not Notify
) and (Usage
== ITEM_UNDEFINED
) and (not TailCommentText
):
156 CommentLine
= USAGE_ITEM_NOTIFY
+ " ## "
160 CommentLine
+= TAB_SPACE_SPLIT
.join([Usage
, TailCommentText
])
161 return GenTailCommentLines(CommentLine
)
163 ## GenInfGuidTailComment
164 # Generate Guid tail comment for Inf
166 # @param Usage: Usage type
167 # @param TailCommentText: Comment text for tail comment
169 def GenInfGuidTailComment (Usage
, GuidTypeList
, VariableName
, TailCommentText
):
170 GuidType
= GuidTypeList
[0]
171 if (Usage
== ITEM_UNDEFINED
) and (GuidType
== ITEM_UNDEFINED
) and \
172 (not TailCommentText
):
175 FirstLine
= Usage
+ " ## " + GuidType
176 if GuidType
== TAB_INF_GUIDTYPE_VAR
:
177 FirstLine
+= ":" + VariableName
179 CommentLine
= TAB_SPACE_SPLIT
.join([FirstLine
, TailCommentText
])
180 return GenTailCommentLines(CommentLine
)
182 ## GenDecGuidTailComment
184 # @param SupModuleList: Supported module type list
186 def GenDecTailComment (SupModuleList
):
187 CommentLine
= TAB_SPACE_SPLIT
.join(SupModuleList
)
188 return GenTailCommentLines(CommentLine
)
192 # get HelpString from a list of HelpTextObject, the priority refer to
195 # @param HelpTextObjList: List of HelpTextObject
197 # @return HelpStr: the help text string found, '' means no help text found
199 def _GetHelpStr(HelpTextObjList
):
202 for HelpObj
in HelpTextObjList
:
203 if HelpObj
and HelpObj
.GetLang() == LANGUAGE_EN_US
:
204 HelpStr
= HelpObj
.GetString()
207 for HelpObj
in HelpTextObjList
:
208 if HelpObj
and HelpObj
.GetLang().startswith('en'):
209 HelpStr
= HelpObj
.GetString()
212 for HelpObj
in HelpTextObjList
:
213 if HelpObj
and not HelpObj
.GetLang():
214 HelpStr
= HelpObj
.GetString()