summaryrefslogtreecommitdiffstats
path: root/documentation
diff options
context:
space:
mode:
authorQuentin Schulz <foss@0leil.net>2020-10-04 15:12:41 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-01-04 10:55:01 +0000
commit47cb48f36e2c92cb8b2862bcb2901b338f964ef4 (patch)
treecdf86eecaba4a6409d0ef67869a2f05181c7d471 /documentation
parent4030fd0f3c3439695949f09b6378278bdd9569bf (diff)
downloadpoky-47cb48f36e2c92cb8b2862bcb2901b338f964ef4.tar.gz
docs: sphinx: yocto-vars: rebuild files when poky.yaml has changed
poky.yaml changes aren't detected by Sphinx by default. In order to detect changes in poky.yaml, its md5sum is stored in the app.outdir (BUILDDIR/html when building html) and checked against the md5sum of the poky.yaml under use. If the md5sum has changed, find all rst files in app.srcdir that have at least an occurence of `&.*;` and mark them as requiring a rebuild. (From yocto-docs rev: 3816a23462ad9eafbf49d455d06e64638de8ea26) Signed-off-by: Quentin Schulz <foss@0leil.net> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 59537c7fa49e3ea6918f45b3201ad16d56988b9b) Signed-off-by: Nicolas Dechesne <nicolas.dechesne@linaro.org> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'documentation')
-rw-r--r--documentation/sphinx/yocto-vars.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/documentation/sphinx/yocto-vars.py b/documentation/sphinx/yocto-vars.py
index 8083d7da19..8795eee0a0 100644
--- a/documentation/sphinx/yocto-vars.py
+++ b/documentation/sphinx/yocto-vars.py
@@ -1,4 +1,6 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2from hashlib import md5
3from pathlib import Path
2import re 4import re
3import sys 5import sys
4 6
@@ -20,25 +22,62 @@ __version__ = '1.0'
20# Each .rst file is processed after source-read event (subst_vars_replace runs once per file) 22# Each .rst file is processed after source-read event (subst_vars_replace runs once per file)
21subst_vars = {} 23subst_vars = {}
22 24
25poky_hash = ""
26
23def subst_vars_replace(app: Sphinx, docname, source): 27def subst_vars_replace(app: Sphinx, docname, source):
24 result = source[0] 28 result = source[0]
25 for k in subst_vars: 29 for k in subst_vars:
26 result = result.replace("&"+k+";", subst_vars[k]) 30 result = result.replace("&"+k+";", subst_vars[k])
27 source[0] = result 31 source[0] = result
28 32
33def yocto_vars_env_get_outdated(app: Sphinx, env, added, changed, removed):
34 '''
35 If poky.yaml changed (BUILDDIR/.poky.yaml.cache does not exist or contains
36 an md5sum different from poky.yaml's current md5sum), force rebuild of all
37 *.rst files in SOURCEDIR whose content has at least one occurence of `&.*;`
38 (see PATTERN global variable).
39 '''
40 try:
41 poky_cache = Path(app.outdir) / ".poky.yaml.cache"
42 cache_hash = poky_cache.read_text()
43 except FileNotFoundError:
44 cache_hash = None
45
46 if poky_hash == cache_hash:
47 return []
48
49 docs = []
50 for p in Path(app.srcdir).rglob("*.rst"):
51 if PATTERN.search(p.read_text()):
52 p_rel_no_ext = p.relative_to(app.srcdir).parent / p.stem
53 docs.append(str(p_rel_no_ext))
54 return docs
55
56def yocto_vars_build_finished(app: Sphinx, exception):
57 poky_cache = Path(app.outdir) / ".poky.yaml.cache"
58 poky_cache.write_text(poky_hash)
59 return []
60
29PATTERN = re.compile(r'&(.*?);') 61PATTERN = re.compile(r'&(.*?);')
30def expand(val, src): 62def expand(val, src):
31 return PATTERN.sub(lambda m: expand(src.get(m.group(1), ''), src), val) 63 return PATTERN.sub(lambda m: expand(src.get(m.group(1), ''), src), val)
32 64
33def setup(app: Sphinx): 65def setup(app: Sphinx):
34 #FIXME: if poky.yaml changes, files are not reprocessed. 66 global poky_hash
67
35 with open("poky.yaml") as file: 68 with open("poky.yaml") as file:
36 subst_vars.update(yaml.load(file, Loader=yaml.FullLoader)) 69 hasher = md5()
70 buff = file.read()
71 hasher.update(buff.encode('utf-8'))
72 poky_hash = hasher.hexdigest()
73 subst_vars.update(yaml.safe_load(buff))
37 74
38 for k in subst_vars: 75 for k in subst_vars:
39 subst_vars[k] = expand(subst_vars[k], subst_vars) 76 subst_vars[k] = expand(subst_vars[k], subst_vars)
40 77
41 app.connect('source-read', subst_vars_replace) 78 app.connect('source-read', subst_vars_replace)
79 app.connect('env-get-outdated', yocto_vars_env_get_outdated)
80 app.connect('build-finished', yocto_vars_build_finished)
42 81
43 return dict( 82 return dict(
44 version = __version__, 83 version = __version__,