History

bpf/scripts: Make description and returns section for helpers/syscalls mandatory

This enforce a minimal formatting consistency for the documentation. The description and returns missing for a few helpers have also been added.

Usama Arif committed 4 years ago

Commit f1f3f671 parent e40fbbf1 file · +18 −12Browse files

Unified · Split

scripts/bpf_doc.py+18−12
@@ -92,14 +92,14 @@ class HeaderParser(object): · 91 unmodified lines
92 92
93 def parse_element(self):93 def parse_element(self):
94 proto = self.parse_symbol()94 proto = self.parse_symbol()
95 desc = self.parse_desc()95 desc = self.parse_desc(proto)
96 ret = self.parse_ret()96 ret = self.parse_ret(proto)
97 return APIElement(proto=proto, desc=desc, ret=ret)97 return APIElement(proto=proto, desc=desc, ret=ret)
98 98
99 def parse_helper(self):99 def parse_helper(self):
100 proto = self.parse_proto()100 proto = self.parse_proto()
101 desc = self.parse_desc()101 desc = self.parse_desc(proto)
102 ret = self.parse_ret()102 ret = self.parse_ret(proto)
103 return Helper(proto=proto, desc=desc, ret=ret)103 return Helper(proto=proto, desc=desc, ret=ret)
104 104
105 def parse_symbol(self):105 def parse_symbol(self):
@@ -129,16 +129,15 @@ class HeaderParser(object): · 23 unmodified lines
129 self.line = self.reader.readline()129 self.line = self.reader.readline()
130 return capture.group(1)130 return capture.group(1)
131 131
132 def parse_desc(self):132 def parse_desc(self, proto):
133 p = re.compile(' \* ?(?:\t| {5,8})Description$')133 p = re.compile(' \* ?(?:\t| {5,8})Description$')
134 capture = p.match(self.line)134 capture = p.match(self.line)
135 if not capture:135 if not capture:
136 # Helper can have empty description and we might be parsing another136 raise Exception("No description section found for " + proto)
137 # attribute: return but do not consume.
138 return ''
139 # Description can be several lines, some of them possibly empty, and it137 # Description can be several lines, some of them possibly empty, and it
140 # stops when another subsection title is met.138 # stops when another subsection title is met.
141 desc = ''139 desc = ''
140 desc_present = False
142 while True:141 while True:
143 self.line = self.reader.readline()142 self.line = self.reader.readline()
144 if self.line == ' *\n':143 if self.line == ' *\n':
@@ -147,21 +146,24 @@ class HeaderParser(object): · 2 unmodified lines
147 p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')146 p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')
148 capture = p.match(self.line)147 capture = p.match(self.line)
149 if capture:148 if capture:
149 desc_present = True
150 desc += capture.group(1) + '\n'150 desc += capture.group(1) + '\n'
151 else:151 else:
152 break152 break
153
154 if not desc_present:
155 raise Exception("No description found for " + proto)
153 return desc156 return desc
154 157
155 def parse_ret(self):158 def parse_ret(self, proto):
156 p = re.compile(' \* ?(?:\t| {5,8})Return$')159 p = re.compile(' \* ?(?:\t| {5,8})Return$')
157 capture = p.match(self.line)160 capture = p.match(self.line)
158 if not capture:161 if not capture:
159 # Helper can have empty retval and we might be parsing another162 raise Exception("No return section found for " + proto)
160 # attribute: return but do not consume.
161 return ''
162 # Return value description can be several lines, some of them possibly163 # Return value description can be several lines, some of them possibly
163 # empty, and it stops when another subsection title is met.164 # empty, and it stops when another subsection title is met.
164 ret = ''165 ret = ''
166 ret_present = False
165 while True:167 while True:
166 self.line = self.reader.readline()168 self.line = self.reader.readline()
167 if self.line == ' *\n':169 if self.line == ' *\n':
@@ -170,9 +172,13 @@ class HeaderParser(object): · 2 unmodified lines
170 p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')172 p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')
171 capture = p.match(self.line)173 capture = p.match(self.line)
172 if capture:174 if capture:
175 ret_present = True
173 ret += capture.group(1) + '\n'176 ret += capture.group(1) + '\n'
174 else:177 else:
175 break178 break
179
180 if not ret_present:
181 raise Exception("No return found for " + proto)
176 return ret182 return ret
177 183
178 def seek_to(self, target, help_message):184 def seek_to(self, target, help_message):