Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: sphinx/kernel_abi: reduce buffer usage for ABI messages

Instead of producing a big message with all ABI contents and then
parse as a whole, simplify the code by handling each ABI symbol
in separate. As an additional benefit, there's no need to place
file/line nubers inlined at the data and use a regex to convert
them.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/15be22955e3c6df49d7256c8fd24f62b397ad0ff.1739182025.git.mchehab+huawei@kernel.org

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
aea5e52d ee34f830

+48 -45
+39 -37
Documentation/sphinx/kernel_abi.py
··· 68 68 has_content = False 69 69 final_argument_whitespace = True 70 70 logger = logging.getLogger('kernel_abi') 71 + parser = None 71 72 72 73 option_spec = { 73 74 "debug": directives.flag, ··· 80 79 raise self.warning("docutils: file insertion disabled") 81 80 82 81 path = os.path.join(srctree, "Documentation", self.arguments[0]) 83 - parser = AbiParser(path, logger=self.logger) 84 - parser.parse_abi() 85 - parser.check_issues() 82 + self.parser = AbiParser(path, logger=self.logger) 83 + self.parser.parse_abi() 84 + self.parser.check_issues() 86 85 87 - msg = "" 88 - for m in parser.doc(enable_lineno=True, show_file=True): 89 - msg += m 90 - 91 - node = self.nested_parse(msg, self.arguments[0]) 86 + node = self.nested_parse(None, self.arguments[0]) 92 87 return node 93 88 94 - def nested_parse(self, lines, fname): 89 + def nested_parse(self, data, fname): 95 90 env = self.state.document.settings.env 96 91 content = ViewList() 97 92 node = nodes.section() 98 93 99 - if "debug" in self.options: 100 - code_block = "\n\n.. code-block:: rst\n :linenos:\n" 101 - for line in lines.split("\n"): 102 - code_block += "\n " + line 103 - lines = code_block + "\n\n" 94 + if data is not None: 95 + # Handles the .rst file 96 + for line in data.split("\n"): 97 + content.append(line, fname, 0) 104 98 105 - line_regex = re.compile(r"^\.\. LINENO (\S+)\#([0-9]+)$") 106 - ln = 0 107 - n = 0 108 - f = fname 99 + self.do_parse(content, node) 109 100 110 - for line in lines.split("\n"): 111 - n = n + 1 112 - match = line_regex.search(line) 113 - if match: 114 - new_f = match.group(1) 101 + else: 102 + # Handles the ABI parser content, symbol by symbol 115 103 116 - # Sphinx parser is lazy: it stops parsing contents in the 117 - # middle, if it is too big. So, handle it per input file 118 - if new_f != f and content: 119 - self.do_parse(content, node) 120 - content = ViewList() 104 + old_f = fname 105 + n = 0 106 + for msg, f, ln in self.parser.doc(): 107 + msg_list = msg.split("\n") 108 + if "debug" in self.options: 109 + lines = [ 110 + "", "", ".. code-block:: rst", 111 + " :linenos:", "" 112 + ] 113 + for m in msg_list: 114 + lines.append(" " + m) 115 + else: 116 + lines = msg_list 121 117 118 + for line in lines: 119 + # sphinx counts lines from 0 120 + content.append(line, f, ln - 1) 121 + n += 1 122 + 123 + if f != old_f: 122 124 # Add the file to Sphinx build dependencies 123 125 env.note_dependency(os.path.abspath(f)) 124 126 125 - f = new_f 127 + old_f = f 126 128 127 - # sphinx counts lines from 0 128 - ln = int(match.group(2)) - 1 129 - else: 130 - content.append(line, f, ln) 129 + # Sphinx doesn't like to parse big messages. So, let's 130 + # add content symbol by symbol 131 + if content: 132 + self.do_parse(content, node) 133 + content = ViewList() 131 134 132 - self.logger.info("%s: parsed %i lines" % (fname, n)) 133 - 134 - if content: 135 - self.do_parse(content, node) 135 + self.logger.info("%s: parsed %i lines" % (fname, n)) 136 136 137 137 return node.children 138 138
+5 -2
scripts/get_abi.py
··· 63 63 parser.parse_abi() 64 64 parser.check_issues() 65 65 66 - for msg in parser.doc(args.enable_lineno, args.raw, not args.no_file): 67 - print(msg) 66 + for t in parser.doc(args.raw, not args.no_file): 67 + if args.enable_lineno: 68 + print (f".. LINENO {t[1]}#{t[2]}\n\n") 69 + 70 + print(t[0]) 68 71 69 72 class AbiValidate: 70 73 """Initialize an argparse subparser for ABI validation"""
+4 -6
scripts/lib/abi/abi_parser.py
··· 427 427 428 428 return new_desc + "\n\n" 429 429 430 - def doc(self, enable_lineno, output_in_txt=False, show_file=False): 430 + def doc(self, output_in_txt=False, show_file=True): 431 431 """Print ABI at stdout""" 432 432 433 433 part = None ··· 443 443 continue 444 444 445 445 msg = "" 446 - 447 - if enable_lineno: 448 - ln = v.get("line_no", 1) 449 - msg += f".. LINENO {file_ref[0][0]}#{ln}\n\n" 450 446 451 447 if wtype != "File": 452 448 cur_part = names[0] ··· 504 508 if users and users.strip(" \t\n"): 505 509 msg += f"Users:\n\t{users.strip("\n").replace('\n', '\n\t')}\n\n" 506 510 507 - yield msg 511 + ln = v.get("line_no", 1) 512 + 513 + yield (msg, file_ref[0][0], ln) 508 514 509 515 def check_issues(self): 510 516 """Warn about duplicated ABI entries"""