From 1451571157b9cdcc0f36c83ab2c74546a72d75a5 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 19 Dec 2019 07:36:11 +0100 Subject: [PATCH] doc: extract_content.py: Detect included files in a more robust way Allow '..
:: ' to appear anywhere within a line, and find multiple directives on a single line. This is needed to find files included e.g. within tables. Implemented by making the part of the regex more specific and searching for matches anywhere within the contents of the file. Should be a bit faster too. Maybe there's some tiny potential for false positives, but this generates the same file list as the old version for the current docs at least. Fixes: #21466 Signed-off-by: Ulf Magnusson --- doc/scripts/extract_content.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/doc/scripts/extract_content.py b/doc/scripts/extract_content.py index 3a74821dbcc4..fdf3b5c327eb 100755 --- a/doc/scripts/extract_content.py +++ b/doc/scripts/extract_content.py @@ -59,7 +59,7 @@ def src_deps(zephyr_base, src_file, dest, src_root): # Load the file's contents, bailing on decode errors. try: with open(src_file, encoding="utf-8") as f: - content = [x.strip() for x in f.readlines()] + content = f.read() except UnicodeDecodeError as e: # pylint: disable=unsubscriptable-object sys.stderr.write( @@ -83,14 +83,10 @@ def src_deps(zephyr_base, src_file, dest, src_root): # argument, which is a (relative) path to the additional # dependency file. directives = "|".join(DIRECTIVES) - pattern = re.compile(r"\.\.\s+(?P%s)::\s+(?P.*)" % + pattern = re.compile(r"\.\.\s+(?P%s)::\s+(?P[^\s]+)" % directives) deps = [] - for l in content: - m = pattern.match(l) - if not m: - continue - + for m in pattern.finditer(content): dep_rel = m.group('dep_rel') # relative to src_dir or absolute dep_src = path.abspath(path.join(src_dir, dep_rel)) if path.isabs(dep_rel):