diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-10-17 14:40:38 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-10-18 10:59:27 +0100 |
commit | 7e9212712817a7c10b9aae7a26de3de3a4f18611 (patch) | |
tree | 3751a50e1dde2576bd4b9ec3c6fb1f2da50d548e | |
parent | f7f5e30667e1ad8e1ca76ee331be2843f2976bfa (diff) | |
download | poky-7e9212712817a7c10b9aae7a26de3de3a4f18611.tar.gz |
bitbake: data/siggen: Extract task hash generation code into a function
By creating a standalone function, we can add better functional testing
of this code.
(Bitbake rev: 796a20d24dc18479de1975a37b9e52a5ac75c73f)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/data.py | 38 | ||||
-rw-r--r-- | bitbake/lib/bb/siggen.py | 37 |
2 files changed, 42 insertions, 33 deletions
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index fde4cba6bb..d66d98cc8b 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py | |||
@@ -38,6 +38,7 @@ the speed is more critical here. | |||
38 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig | 38 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig |
39 | 39 | ||
40 | import sys, os, re | 40 | import sys, os, re |
41 | import hashlib | ||
41 | if sys.argv[0][-5:] == "pydoc": | 42 | if sys.argv[0][-5:] == "pydoc": |
42 | path = os.path.dirname(os.path.dirname(sys.argv[1])) | 43 | path = os.path.dirname(os.path.dirname(sys.argv[1])) |
43 | else: | 44 | else: |
@@ -405,6 +406,43 @@ def generate_dependencies(d): | |||
405 | #print "For %s: %s" % (task, str(deps[task])) | 406 | #print "For %s: %s" % (task, str(deps[task])) |
406 | return tasklist, deps, values | 407 | return tasklist, deps, values |
407 | 408 | ||
409 | def generate_dependency_hash(tasklist, gendeps, lookupcache, whitelist, fn): | ||
410 | taskdeps = {} | ||
411 | basehash = {} | ||
412 | |||
413 | for task in tasklist: | ||
414 | data = lookupcache[task] | ||
415 | |||
416 | if data is None: | ||
417 | bb.error("Task %s from %s seems to be empty?!" % (task, fn)) | ||
418 | data = '' | ||
419 | |||
420 | gendeps[task] -= whitelist | ||
421 | newdeps = gendeps[task] | ||
422 | seen = set() | ||
423 | while newdeps: | ||
424 | nextdeps = newdeps | ||
425 | seen |= nextdeps | ||
426 | newdeps = set() | ||
427 | for dep in nextdeps: | ||
428 | if dep in whitelist: | ||
429 | continue | ||
430 | gendeps[dep] -= whitelist | ||
431 | newdeps |= gendeps[dep] | ||
432 | newdeps -= seen | ||
433 | |||
434 | alldeps = sorted(seen) | ||
435 | for dep in alldeps: | ||
436 | data = data + dep | ||
437 | var = lookupcache[dep] | ||
438 | if var is not None: | ||
439 | data = data + str(var) | ||
440 | k = fn + "." + task | ||
441 | basehash[k] = hashlib.md5(data.encode("utf-8")).hexdigest() | ||
442 | taskdeps[task] = alldeps | ||
443 | |||
444 | return taskdeps, basehash | ||
445 | |||
408 | def inherits_class(klass, d): | 446 | def inherits_class(klass, d): |
409 | val = d.getVar('__inherit_cache', False) or [] | 447 | val = d.getVar('__inherit_cache', False) or [] |
410 | needle = os.path.join('classes', '%s.bbclass' % klass) | 448 | needle = os.path.join('classes', '%s.bbclass' % klass) |
diff --git a/bitbake/lib/bb/siggen.py b/bitbake/lib/bb/siggen.py index e9bb51d736..03c824ec38 100644 --- a/bitbake/lib/bb/siggen.py +++ b/bitbake/lib/bb/siggen.py | |||
@@ -110,42 +110,13 @@ class SignatureGeneratorBasic(SignatureGenerator): | |||
110 | ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') == '1') | 110 | ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') == '1') |
111 | tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d) | 111 | tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d) |
112 | 112 | ||
113 | taskdeps = {} | 113 | taskdeps, basehash = bb.data.generate_dependency_hash(tasklist, gendeps, lookupcache, self.basewhitelist, fn) |
114 | basehash = {} | ||
115 | 114 | ||
116 | for task in tasklist: | 115 | for task in tasklist: |
117 | data = lookupcache[task] | ||
118 | |||
119 | if data is None: | ||
120 | bb.error("Task %s from %s seems to be empty?!" % (task, fn)) | ||
121 | data = '' | ||
122 | |||
123 | gendeps[task] -= self.basewhitelist | ||
124 | newdeps = gendeps[task] | ||
125 | seen = set() | ||
126 | while newdeps: | ||
127 | nextdeps = newdeps | ||
128 | seen |= nextdeps | ||
129 | newdeps = set() | ||
130 | for dep in nextdeps: | ||
131 | if dep in self.basewhitelist: | ||
132 | continue | ||
133 | gendeps[dep] -= self.basewhitelist | ||
134 | newdeps |= gendeps[dep] | ||
135 | newdeps -= seen | ||
136 | |||
137 | alldeps = sorted(seen) | ||
138 | for dep in alldeps: | ||
139 | data = data + dep | ||
140 | var = lookupcache[dep] | ||
141 | if var is not None: | ||
142 | data = data + str(var) | ||
143 | datahash = hashlib.md5(data.encode("utf-8")).hexdigest() | ||
144 | k = fn + "." + task | 116 | k = fn + "." + task |
145 | if not ignore_mismatch and k in self.basehash and self.basehash[k] != datahash: | 117 | if not ignore_mismatch and k in self.basehash and self.basehash[k] != basehash[k]: |
146 | bb.error("When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed." % (k, self.basehash[k], datahash)) | 118 | bb.error("When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed." % (k, self.basehash[k], basehash[k])) |
147 | self.basehash[k] = datahash | 119 | self.basehash[k] = basehash[k] |
148 | taskdeps[task] = alldeps | ||
149 | 120 | ||
150 | self.taskdeps[fn] = taskdeps | 121 | self.taskdeps[fn] = taskdeps |
151 | self.gendeps[fn] = gendeps | 122 | self.gendeps[fn] = gendeps |