siggen: Import unihash code from OE-Core
PATCH 1/16 siggen: Import unihash code from OE-Core
This code is closely tied with the hash server in bitbake and also means we can't relibably test the hashserv runqueue functionality without OE metadata. Moving this to bitbake as a MixIn class makes most sense and encourages code collaboration and reuse as well as enabling easier and more accurate testing of the APIs.
--- lib/bb/siggen.py | 163 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+)
lib/bb/siggen.py +163 -0
@@ -354,6 +354,169 @@ class SignatureGeneratorBasicHash(SignatureGeneratorBasic): bb.note("Tainting hash to force rebuild of task %s, %s" % (fn, task)) bb.build.write_taint(task, d, fn) +class SignatureGeneratorUniHashMixIn(object): + def get_taskdata(self): + return (self.server, self.method) + super().get_taskdata() + + def set_taskdata(self, data): + self.server, self.method = data[:2] + super().set_taskdata(data[2:]) + + def __get_task_unihash_key(self, task): + # TODO: The key only *needs* to be the taskhash, the task is just + # convenient + return '%s:%s' % (task, self.taskhash[task]) + + def get_stampfile_hash(self, task): + if task in self.taskhash: + # If a unique hash is reported, use it as the stampfile hash. This + # ensures that if a task won't be re-run if the taskhash changes, + # but it would result in the same output hash + unihash = self.unihashes.get(self.__get_task_unihash_key(task)) + if unihash is not None: + return unihash + + return super().get_stampfile_hash(task) + + def get_unihash(self, task): + import urllib + import json + + taskhash = self.taskhash[task] + + key = self.__get_task_unihash_key(task) + + # TODO: This cache can grow unbounded. It probably only needs to keep + # for each task + unihash = self.unihashes.get(key) + if unihash is not None: + return unihash + + # In the absence of being able to discover a unique hash from the + # server, make it be equivalent to the taskhash. The unique "hash" only + # really needs to be a unique string (not even necessarily a hash), but + # making it match the taskhash has a few advantages: + # + # 1) All of the sstate code that assumes hashes can be the same + # 2) It provides maximal compatibility with builders that don't use + # an equivalency server + # 3) The value is easy for multiple independent builders to derive the + # same unique hash from the same input. This means that if the + # independent builders find the same taskhash, but it isn't reported + # to the server, there is a better chance that they will agree on + # the unique hash. + unihash = taskhash + + try: + url = '%s/v1/equivalent?%s' % (self.server, + urllib.parse.urlencode({'method': self.method, 'taskhash': self.taskhash[task]})) + + request = urllib.request.Request(url) + response = urllib.request.urlopen(request) + data = response.read().decode('utf-8') + + json_data = json.loads(data) + + if json_data: + unihash = json_data['unihash'] + # A unique hash equal to the taskhash is not very interesting, + # so it is reported it at debug level 2. If they differ, that + # is much more interesting, so it is reported at debug level 1 + bb.debug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, task, self.server)) + else: + bb.debug(2, 'No reported unihash for %s:%s from %s' % (task, taskhash, self.server)) + except urllib.error.URLError as e: + bb.warn('Failure contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) + except (KeyError, json.JSONDecodeError) as e: + bb.warn('Poorly formatted response from %s: %s' % (self.server, str(e))) + + self.unihashes[key] = unihash + return unihash + + def report_unihash(self, path, task, d): + import urllib + import json + import tempfile + import base64 + import importlib + + taskhash = d.getVar('BB_TASKHASH') + unihash = d.getVar('BB_UNIHASH') + report_taskdata = d.getVar('SSTATE_HASHEQUIV_REPORT_TASKDATA') == '1' + tempdir = d.getVar('T') + fn = d.getVar('BB_FILENAME') + key = fn + '.do_' + task + ':' + taskhash + + # Sanity checks + cache_unihash = self.unihashes.get(key) + if cache_unihash is None: + bb.fatal('%s not in unihash cache. Please report this error' % key) + + if cache_unihash != unihash: + bb.fatal("Cache unihash %s doesn't match BB_UNIHASH %s" % (cache_unihash, unihash)) + + sigfile = None + sigfile_name = "depsig.do_%s.%d" % (task, os.getpid()) + sigfile_link = "depsig.do_%s" % task + + try: + sigfile = open(os.path.join(tempdir, sigfile_name), 'w+b') + + locs = {'path': path, 'sigfile': sigfile, 'task': task, 'd': d} + + (module, method) = self.method.rsplit('.', 1) + locs['method'] = getattr(importlib.import_module(module), method) + + outhash = bb.utils.better_eval('method(path, sigfile, task, d)', locs) + + try: + url = '%s/v1/equivalent' % self.server + task_data = { + 'taskhash': taskhash, + 'method': self.method, + 'outhash': outhash, + 'unihash': unihash, + 'owner': d.getVar('SSTATE_HASHEQUIV_OWNER') + } + + if report_taskdata: + sigfile.seek(0) + + task_data['PN'] = d.getVar('PN') + task_data['PV'] = d.getVar('PV') + task_data['PR'] = d.getVar('PR') + task_data['task'] = task + task_data['outhash_siginfo'] = sigfile.read().decode('utf-8') + + headers = {'content-type': 'application/json'} + + request = urllib.request.Request(url, json.dumps(task_data).encode('utf-8'), headers) + response = urllib.request.urlopen(request) + data = response.read().decode('utf-8') + + json_data = json.loads(data) + new_unihash = json_data['unihash'] + + if new_unihash != unihash: + bb.debug(1, 'Task %s unihash changed %s -> %s by server %s' % (taskhash, unihash, new_unihash, self.server)) + else: + bb.debug(1, 'Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server)) + except urllib.error.URLError as e: + bb.warn('Failure contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) + except (KeyError, json.JSONDecodeError) as e: + bb.warn('Poorly formatted response from %s: %s' % (self.server, str(e))) + finally: + if sigfile: + sigfile.close() + + sigfile_link_path = os.path.join(tempdir, sigfile_link) + bb.utils.remove(sigfile_link_path) + + try: + os.symlink(sigfile_name, sigfile_link_path) + except OSError: + pass + def dump_this_task(outfile, d): import bb.parse fn = d.getVar("BB_FILENAME")
Signature · 1 line
2.20.1
PATCH 2/16 cache: Add SimpleCache class
This adds a simple version of the MultiProcessCache which can be used to save and load cache data, useful for a new usecase we have in sigdata/runqueue.
--- lib/bb/cache.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
lib/bb/cache.py +53 -0
@@ -883,3 +883,56 @@ class MultiProcessCache(object): p.dump([data, self.__class__.CACHE_VERSION]) bb.utils.unlockfile(glf) + + +class SimpleCache(object): + """ + BitBake multi-process cache implementation + + Used by the codeparser & file checksum caches + """ + + def __init__(self, version): + self.cachefile = None + self.cachedata = None + self.cacheversion = version + + def init_cache(self, d, cache_file_name=None, defaultdata=None): + cachedir = (d.getVar("PERSISTENT_DIR") or + d.getVar("CACHE")) + if not cachedir: + return defaultdata + + bb.utils.mkdirhier(cachedir) + self.cachefile = os.path.join(cachedir, + cache_file_name or self.__class__.cache_file_name) + logger.debug(1, "Using cache in '%s'", self.cachefile) + + glf = bb.utils.lockfile(self.cachefile + ".lock") + + try: + with open(self.cachefile, "rb") as f: + p = pickle.Unpickler(f) + data, version = p.load() + except: + bb.utils.unlockfile(glf) + return defaultdata + + bb.utils.unlockfile(glf) + + if version != self.cacheversion: + return defaultdata + + return data + + def save(self, data): + if not self.cachefile: + return + + glf = bb.utils.lockfile(self.cachefile + ".lock") + + with open(self.cachefile, "wb") as f: + p = pickle.Pickler(f, -1) + p.dump([data, self.cacheversion]) + + bb.utils.unlockfile(glf)
Signature · 1 line
2.20.1
PATCH 3/16 runqueue: Improve scenequeue processing logic
In reply to Richard PurdieRather than a special copy of the data structure which we change, compute the logic using set operations from other data we have. This means we can add tasks back into the scenequeue without having to worry about reversing operations on this variable with all the potential bugs that might involve.
--- lib/bb/runqueue.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
lib/bb/runqueue.py +3 -9
@@ -2206,12 +2206,9 @@ class RunQueueExecute: logger.debug(2, "%s was unavailable and is a hard dependency of %s so skipping" % (task, dep)) self.sq_task_failoutright(dep) continue - if task not in self.sqdata.sq_revdeps2[dep]: - # May already have been removed by the fail case above - continue - self.sqdata.sq_revdeps2[dep].remove(task) - if len(self.sqdata.sq_revdeps2[dep]) == 0: - self.sq_buildable.add(dep) + if self.sqdata.sq_revdeps[dep].issubset(self.scenequeue_covered | self.scenequeue_notcovered): + if dep not in self.sq_buildable: + self.sq_buildable.add(dep) next = set([task]) while next:
@@ -2377,8 +2374,6 @@ class SQData(object): self.sq_deps = {} # SceneQueue reverse dependencies self.sq_revdeps = {} - # Copy of reverse dependencies used by sq processing code - self.sq_revdeps2 = {} # Injected inter-setscene task dependencies self.sq_harddeps = {} # Cache of stamp files so duplicates can't run in parallel
@@ -2537,7 +2532,6 @@ def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): # bb.warn("Task %s_setscene: is %s " % (tid, data)) sqdata.sq_revdeps = sq_revdeps_squash - sqdata.sq_revdeps2 = copy.deepcopy(sqdata.sq_revdeps) sqdata.sq_covered_tasks = sq_collated_deps # Build reverse version of revdeps to populate deps structure
Signature · 1 line
2.20.1
PATCH 4/16 siggen: Add new unitaskhashes data variable which is cached
In reply to Richard PurdieWe need to preserve unihash task hashes between runs. Use the new SimpleCache class to create such a class within the signature generator which is loaded at init time and saved when builds complete. The default is unpopulated but metadata sig handlers can populate this cache.
--- lib/bb/runqueue.py | 1 + lib/bb/siggen.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-)
lib/bb/runqueue.py +1 -0
@@ -1516,6 +1516,7 @@ class RunQueue: self.dm_event_handler_registered = False if build_done and self.rqexe: + bb.parse.siggen.save_unitaskhashes() self.teardown_workers() if self.rqexe: if self.rqexe.stats.failed:
lib/bb/siggen.py +18 -2
@@ -41,6 +41,7 @@ class SignatureGenerator(object): self.runtaskdeps = {} self.file_checksum_values = {} self.taints = {} + self.unitaskhashes = {} def finalise(self, fn, d, varient): return
@@ -73,14 +74,23 @@ class SignatureGenerator(object): return def get_taskdata(self): - return (self.runtaskdeps, self.taskhash, self.file_checksum_values, self.taints, self.basehash) + return (self.runtaskdeps, self.taskhash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes) def set_taskdata(self, data): - self.runtaskdeps, self.taskhash, self.file_checksum_values, self.taints, self.basehash = data + self.runtaskdeps, self.taskhash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes = data def reset(self, data): self.__init__(data) + def get_taskhashes(self): + return self.taskhash, self.unitaskhashes + + def set_taskhashes(self, hashes): + self.taskhash, self.unitaskhashes = hashes + + def save_unitaskhashes(self): + return + class SignatureGeneratorBasic(SignatureGenerator): """
@@ -107,6 +117,9 @@ class SignatureGeneratorBasic(SignatureGenerator): else: self.checksum_cache = None + self.unihash_cache = bb.cache.SimpleCache("1") + self.unitaskhashes = self.unihash_cache.init_cache(data, "bb_unihashes.dat", {}) + def init_rundepcheck(self, data): self.taskwhitelist = data.getVar("BB_HASHTASK_WHITELIST") or None if self.taskwhitelist:
@@ -244,6 +257,9 @@ class SignatureGeneratorBasic(SignatureGenerator): bb.fetch2.fetcher_parse_save() bb.fetch2.fetcher_parse_done() + def save_unitaskhashes(self): + self.unihash_cache.save(self.unitaskhashes) + def dump_sigtask(self, fn, task, stampbase, runtime): k = fn + "." + task
Signature · 1 line
2.20.1
PATCH 5/16 siggen: Convert to use self.unitaskhashes
In reply to Richard PurdieRather than metadata driven sqlite databases for communication, use bitbake's unitaskhashes variable instead.
--- lib/bb/siggen.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
lib/bb/siggen.py +8 -4
@@ -388,12 +388,15 @@ class SignatureGeneratorUniHashMixIn(object): # If a unique hash is reported, use it as the stampfile hash. This # ensures that if a task won't be re-run if the taskhash changes, # but it would result in the same output hash - unihash = self.unihashes.get(self.__get_task_unihash_key(task)) + unihash = self.unitaskhashes.get(self.__get_task_unihash_key(task), None) if unihash is not None: return unihash return super().get_stampfile_hash(task) + def set_unihash(self, task, unihash): + self.unitaskhashes[self.__get_task_unihash_key(task)] = unihash + def get_unihash(self, task): import urllib import json
@@ -404,7 +407,7 @@ class SignatureGeneratorUniHashMixIn(object): # TODO: This cache can grow unbounded. It probably only needs to keep # for each task - unihash = self.unihashes.get(key) + unihash = self.unitaskhashes.get(key, None) if unihash is not None: return unihash
@@ -446,7 +449,7 @@ class SignatureGeneratorUniHashMixIn(object): except (KeyError, json.JSONDecodeError) as e: bb.warn('Poorly formatted response from %s: %s' % (self.server, str(e))) - self.unihashes[key] = unihash + self.unitaskhashes[key] = unihash return unihash def report_unihash(self, path, task, d):
@@ -464,7 +467,7 @@ class SignatureGeneratorUniHashMixIn(object): key = fn + '.do_' + task + ':' + taskhash # Sanity checks - cache_unihash = self.unihashes.get(key) + cache_unihash = self.unitaskhashes.get(key, None) if cache_unihash is None: bb.fatal('%s not in unihash cache. Please report this error' % key)
@@ -515,6 +518,7 @@ class SignatureGeneratorUniHashMixIn(object): if new_unihash != unihash: bb.debug(1, 'Task %s unihash changed %s -> %s by server %s' % (taskhash, unihash, new_unihash, self.server)) + bb.event.fire(bb.runqueue.taskUniHashUpdate(fn + ':do_' + task, new_unihash), d) else: bb.debug(1, 'Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server)) except urllib.error.URLError as e:
Signature · 1 line
2.20.1
PATCH 6/16 runqueue: Enable dynamic task adjustment to hash equivalency
In reply to Richard PurdieThere is a compelling usecase for tasks being able to notify runqueue that their "unihash" has changed. When this is recieved, the hashes of all subsequent tasks should be recomputed and their new hashes checked against existing setscene validity. Any newly available setscene tasks should then be executed.
Making this work effectively needs several pieces. An event is added which the cooker listen for. If a new hash becomes available it can send an event to notify of this.
When such an event is seen, hash recomputations are made. A setscene task can't be run until all the tasks it "covers" are stopped. The notion of "holdoff" tasks is therefore added, these are removed from the buildable list with the assumption that some setscene task will run and cover them.
The workers need to be notified when taskhashes change to update their own internal siggen data stores. A new worker command is added to do this which will affect all newly spawned worker processes from that worker.
An example workflow which tests this code is:
Configuration:BB_SIGNATURE_HANDLER = "OEEquivHash"SSTATE_HASHEQUIV_SERVER = "http://localhost:8686"
$ bitbake-hashserv & $ bitbake automake-native $ bitbake autoconf-native automake-native -c clean $ bitbake m4-native -c install -f $ bitbake automake-native
with the test being whether automake-native is installed from sstate.
--- bin/bitbake-worker | 6 ++ lib/bb/runqueue.py | 163 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 160 insertions(+), 9 deletions(-)
bin/bitbake-worker +6 -0
@@ -234,6 +234,8 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha the_data.setVar(varname, value) bb.parse.siggen.set_taskdata(workerdata["sigdata"]) + if "newhashes" in workerdata: + bb.parse.siggen.set_taskhashes(workerdata["newhashes"]) ret = 0 the_data = bb_cache.loadDataFull(fn, appends)
@@ -377,6 +379,7 @@ class BitbakeWorker(object): self.handle_item(b"cookerconfig", self.handle_cookercfg) self.handle_item(b"extraconfigdata", self.handle_extraconfigdata) self.handle_item(b"workerdata", self.handle_workerdata) + self.handle_item(b"newtaskhashes", self.handle_newtaskhashes) self.handle_item(b"runtask", self.handle_runtask) self.handle_item(b"finishnow", self.handle_finishnow) self.handle_item(b"ping", self.handle_ping)
@@ -416,6 +419,9 @@ class BitbakeWorker(object): for mc in self.databuilder.mcdata: self.databuilder.mcdata[mc].setVar("PRSERV_HOST", self.workerdata["prhost"]) + def handle_newtaskhashes(self, data): + self.workerdata["newhashes"] = pickle.loads(data) + def handle_ping(self, _): workerlog_write("Handling ping\n")
lib/bb/runqueue.py +154 -9
250 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 7/16 cooker/hashserv: Allow autostarting of a local hash server using BB_HASHSERVE
In reply to Richard PurdieIts useful, particularly in the local developer model of usage, for bitbake to start and stop a hash equivalence server on local port, rather than relying on one being started by the user before the build.
The new BB_HASHSERVE variable supports this.
The database handling is moved internally into the hashserv code so that different threads/processes can be used for the server without errors.
--- bin/bitbake-hashserv | 4 +--- bin/bitbake-worker | 1 + lib/bb/cooker.py | 15 ++++++++++++++- lib/bb/runqueue.py | 1 + lib/hashserv/__init__.py | 19 ++++++++++++++++--- lib/hashserv/tests.py | 7 ++++--- 6 files changed, 37 insertions(+), 10 deletions(-)
bin/bitbake-hashserv +1 -3
@@ -41,9 +41,7 @@ def main(): console.setLevel(level) logger.addHandler(console) - db = sqlite3.connect(args.database) - - server = hashserv.create_server((args.address, args.port), db, args.prefix) + server = hashserv.create_server((args.address, args.port), args.database, args.prefix) server.serve_forever() return 0
bin/bitbake-worker +1 -0
@@ -418,6 +418,7 @@ class BitbakeWorker(object): bb.msg.loggerDefaultDomains = self.workerdata["logdefaultdomain"] for mc in self.databuilder.mcdata: self.databuilder.mcdata[mc].setVar("PRSERV_HOST", self.workerdata["prhost"]) + self.databuilder.mcdata[mc].setVar("BB_HASHSERVE", self.workerdata["hashservport"]) def handle_newtaskhashes(self, data): self.workerdata["newhashes"] = pickle.loads(data)
lib/bb/cooker.py +14 -1
@@ -31,6 +31,7 @@ import pyinotify import json import pickle import codecs +import hashserv logger = logging.getLogger("BitBake") collectlog = logging.getLogger("BitBake.Collection")
@@ -230,6 +231,8 @@ class BBCooker: self.state = state.initial self.parser = None + self.hashserv = None + self.hashservport = None signal.signal(signal.SIGTERM, self.sigterm_exception) # Let SIGHUP exit as SIGTERM
@@ -368,6 +371,15 @@ class BBCooker: self.data.setVar('BB_CMDLINE', self.ui_cmdline) + if self.data.getVar("BB_HASHSERVE") == "localhost:0": + dbfile = (self.data.getVar("PERSISTENT_DIR") or self.data.getVar("CACHE")) + "/hashserv.db" + self.hashserv = hashserv.create_server(('localhost', 0), dbfile, '') + self.hashservport = "localhost:" + str(self.hashserv.server_port) + thread = threading.Thread(target=self.hashserv.serve_forever) + thread.daemon = True + thread.start() + self.data.setVar("BB_HASHSERVE", self.hashservport) + # # Copy of the data store which has been expanded. # Used for firing events and accessing variables where expansion needs to be accounted for
@@ -1645,9 +1657,10 @@ class BBCooker: def post_serve(self): prserv.serv.auto_shutdown() + if self.hashserv: + self.hashserv.shutdown() bb.event.fire(CookerExit(), self.data) - def shutdown(self, force = False): if force: self.state = state.forceshutdown
lib/bb/runqueue.py +1 -0
@@ -1254,6 +1254,7 @@ class RunQueue: "buildname" : self.cfgData.getVar("BUILDNAME"), "date" : self.cfgData.getVar("DATE"), "time" : self.cfgData.getVar("TIME"), + "hashservport" : self.cooker.hashservport, } worker.stdin.write(b"<cookerconfig>" + pickle.dumps(self.cooker.configuration) + b"</cookerconfig>")
lib/hashserv/__init__.py +16 -3
@@ -18,8 +18,15 @@ class HashEquivalenceServer(BaseHTTPRequestHandler): def log_message(self, f, *args): logger.debug(f, *args) + def opendb(self): + self.db = sqlite3.connect(self.dbname) + self.db.row_factory = sqlite3.Row + def do_GET(self): try: + if not self.db: + self.opendb() + p = urllib.parse.urlparse(self.path) if p.path != self.prefix + '/v1/equivalent':
@@ -52,6 +59,9 @@ class HashEquivalenceServer(BaseHTTPRequestHandler): def do_POST(self): try: + if not self.db: + self.opendb() + p = urllib.parse.urlparse(self.path) if p.path != self.prefix + '/v1/equivalent':
@@ -123,14 +133,17 @@ class HashEquivalenceServer(BaseHTTPRequestHandler): self.send_error(400, explain=traceback.format_exc()) return -def create_server(addr, db, prefix=''): +def create_server(addr, dbname, prefix=''): class Handler(HashEquivalenceServer): pass - Handler.prefix = prefix - Handler.db = db + db = sqlite3.connect(dbname) db.row_factory = sqlite3.Row + Handler.prefix = prefix + Handler.db = None + Handler.dbname = dbname + with contextlib.closing(db.cursor()) as cursor: cursor.execute(''' CREATE TABLE IF NOT EXISTS tasks_v2 (
lib/hashserv/tests.py +4 -3
@@ -11,14 +11,15 @@ import sqlite3 import hashlib import urllib.request import json +import tempfile from . import create_server class TestHashEquivalenceServer(unittest.TestCase): def setUp(self): - # Start an in memory hash equivalence server in the background bound to + # Start a hash equivalence server in the background bound to # an ephemeral port - db = sqlite3.connect(':memory:', check_same_thread=False) - self.server = create_server(('localhost', 0), db) + self.dbfile = tempfile.NamedTemporaryFile(prefix="bb-hashserv-db-") + self.server = create_server(('localhost', 0), self.dbfile.name) self.server_addr = 'http://localhost:%d' % self.server.socket.getsockname()[1] self.server_thread = threading.Thread(target=self.server.serve_forever) self.server_thread.start()
Signature · 1 line
2.20.1
PATCH 8/16 hashserv: Turn off sqlite synchronous mode
In reply to Richard PurdieWe're seeing performance problems with hashserv running on a normal build system. The cause seems to be the large amounts of file IO that builds involve blocking writes to the database. Since sqlite blocks on the sync calls, this causes a significant problem.
Since if we lose power we have bigger problems, run with synchronous=off to avoid locking and put the jounral into memory to avoid any write issues there too.
This took writes from 120s down to negligible in my tests, which means hashserv then responds promptly to requests.
--- lib/hashserv/__init__.py | 2 ++ 1 file changed, 2 insertions(+)
lib/hashserv/__init__.py +2 -0
@@ -21,6 +21,8 @@ class HashEquivalenceServer(BaseHTTPRequestHandler): def opendb(self): self.db = sqlite3.connect(self.dbname) self.db.row_factory = sqlite3.Row + self.db.execute("PRAGMA synchronous = OFF;") + self.db.execute("PRAGMA journal_mode = MEMORY;") def do_GET(self): try:
Signature · 1 line
2.20.1
PATCH 9/16 prserv: Use a memory journal
In reply to Richard PurdieWe've seen PR Server timeouts on the autobuilder, this is likely from the journal being blocked on disk IO generated by the build.
Since we're running with synchronous off, we may as well put the journal into memory and avoid any IO related stalls.
--- lib/prserv/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/prserv/db.py +1 -1
@@ -257,7 +257,7 @@ class PRData(object): self.connection=sqlite3.connect(self.filename, isolation_level="EXCLUSIVE", check_same_thread = False) self.connection.row_factory=sqlite3.Row self.connection.execute("pragma synchronous = off;") - self.connection.execute("PRAGMA journal_mode = WAL;") + self.connection.execute("PRAGMA journal_mode = MEMORY;") self._tables={} def disconnect(self):
Signature · 1 line
2.20.1
Re: [PATCH 09/16] prserv: Use a memory journal
Quoted 5 lines · Richard Purdie
We've seen PR Server timeouts on the autobuilder, this is likely from the journal being blocked on disk IO generated by the build.
Since we're running with synchronous off, we may as well put the journal into memory and avoid any IO related stalls.
When does it flush to disk? On exit?
--Mark
Quoted 19 lines
Signed-off-by Richard Purdie <[email protected]>--- lib/prserv/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/prserv/db.py +1
-1@@ -257,7 +257,7 @@ class PRData(object): self.connection=sqlite3.connect(self.filename, isolation_level="EXCLUSIVE", check_same_thread = False) self.connection.row_factory=sqlite3.Row self.connection.execute("pragma synchronous = off;") - self.connection.execute("PRAGMA journal_mode = WAL;") + self.connection.execute("PRAGMA journal_mode = MEMORY;") self._tables={} def disconnect(self):
Re: [PATCH 09/16] prserv: Use a memory journal
Quoted 10 lines · Mark Hatle
Quoted 7 lines · Richard Purdie
We've seen PR Server timeouts on the autobuilder, this is likely from the
journal being blocked on disk IO generated by the build.Since we're running with synchronous off, we may as well put the journal
into memory and avoid any IO related stalls.When does it flush to disk? On exit?
It will make the correct writes to preserve the database so program crashes won't corrupt, only a poweroff situation. Basically we're not trying to second guess the VFS in the kernel.
Cheers,
Richard
PATCH 10/16 hashserv: Use separate threads for answering requests and handling them
In reply to Richard PurdieExperience with the prserv shows that having two threads, one accepting and queueing connections and one handling the requests leads to much more reliable behaviour than having everything in a single thread.
--- lib/hashserv/__init__.py | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
lib/hashserv/__init__.py +40 -1
@@ -10,6 +10,9 @@ import sqlite3 import json import traceback import logging +import socketserver +import queue +import threading from datetime import datetime logger = logging.getLogger('hashserv')
@@ -135,6 +138,41 @@ class HashEquivalenceServer(BaseHTTPRequestHandler): self.send_error(400, explain=traceback.format_exc()) return +class ThreadedHTTPServer(HTTPServer): + quit = False + + def serve_forever(self): + self.requestqueue = queue.Queue() + self.handlerthread = threading.Thread(target=self.process_request_thread) + self.handlerthread.daemon = False + + self.handlerthread.start() + super().serve_forever() + + def process_request_thread(self): + while not self.quit: + try: + (request, client_address) = self.requestqueue.get(True) + except queue.Empty: + continue + if request is None: + continue + try: + self.finish_request(request, client_address) + except Exception: + self.handle_error(request, client_address) + finally: + self.shutdown_request(request) + + def process_request(self, request, client_address): + self.requestqueue.put((request, client_address)) + + def server_close(self): + super().server_close() + self.quit = True + self.requestqueue.put((None, None)) + self.handlerthread.join() + def create_server(addr, dbname, prefix=''): class Handler(HashEquivalenceServer): pass
@@ -171,4 +209,5 @@ def create_server(addr, dbname, prefix=''): cursor.execute('CREATE INDEX IF NOT EXISTS outhash_lookup ON tasks_v2 (method, outhash)') logger.info('Starting server on %s', addr) - return HTTPServer(addr, Handler) + + return ThreadedHTTPServer(addr, Handler)
Signature · 1 line
2.20.1
PATCH 11/16 hashserv: Switch from threads to multiprocessing
In reply to Richard PurdieThere were hard to debug lockups when trying to use threading to start hashserv as a thread. Switch to multiprocessing which doesn't show the same locking problems.
--- lib/bb/cooker.py | 20 +++++++++++--------- lib/hashserv/__init__.py | 14 ++++++++++++-- lib/hashserv/tests.py | 8 ++++---- 3 files changed, 27 insertions(+), 15 deletions(-)
lib/bb/cooker.py +11 -9
@@ -193,6 +193,8 @@ class BBCooker: bb.parse.BBHandler.cached_statements = {} self.ui_cmdline = None + self.hashserv = None + self.hashservport = None self.initConfigurationData()
@@ -231,8 +233,6 @@ class BBCooker: self.state = state.initial self.parser = None - self.hashserv = None - self.hashservport = None signal.signal(signal.SIGTERM, self.sigterm_exception) # Let SIGHUP exit as SIGTERM
@@ -372,12 +372,13 @@ class BBCooker: self.data.setVar('BB_CMDLINE', self.ui_cmdline) if self.data.getVar("BB_HASHSERVE") == "localhost:0": - dbfile = (self.data.getVar("PERSISTENT_DIR") or self.data.getVar("CACHE")) + "/hashserv.db" - self.hashserv = hashserv.create_server(('localhost', 0), dbfile, '') - self.hashservport = "localhost:" + str(self.hashserv.server_port) - thread = threading.Thread(target=self.hashserv.serve_forever) - thread.daemon = True - thread.start() + if not self.hashserv: + dbfile = (self.data.getVar("PERSISTENT_DIR") or self.data.getVar("CACHE")) + "/hashserv.db" + self.hashserv = hashserv.create_server(('localhost', 0), dbfile, '') + self.hashservport = "localhost:" + str(self.hashserv.server_port) + self.hashserv.process = multiprocessing.Process(target=self.hashserv.serve_forever) + self.hashserv.process.daemon = True + self.hashserv.process.start() self.data.setVar("BB_HASHSERVE", self.hashservport) #
@@ -1658,7 +1659,8 @@ class BBCooker: def post_serve(self): prserv.serv.auto_shutdown() if self.hashserv: - self.hashserv.shutdown() + self.hashserv.process.terminate() + self.hashserv.process.join() bb.event.fire(CookerExit(), self.data) def shutdown(self, force = False):
lib/hashserv/__init__.py +12 -2
@@ -13,6 +13,7 @@ import logging import socketserver import queue import threading +import signal from datetime import datetime logger = logging.getLogger('hashserv')
@@ -147,8 +148,14 @@ class ThreadedHTTPServer(HTTPServer): self.handlerthread.daemon = False self.handlerthread.start() + + signal.signal(signal.SIGTERM, self.sigterm_exception) super().serve_forever() + def sigterm_exception(self, signum, stackframe): + self.server_close() + os._exit(0) + def process_request_thread(self): while not self.quit: try:
@@ -163,6 +170,7 @@ class ThreadedHTTPServer(HTTPServer): self.handle_error(request, client_address) finally: self.shutdown_request(request) + os._exit(0) def process_request(self, request, client_address): self.requestqueue.put((request, client_address))
@@ -208,6 +216,8 @@ def create_server(addr, dbname, prefix=''): cursor.execute('CREATE INDEX IF NOT EXISTS taskhash_lookup ON tasks_v2 (method, taskhash)') cursor.execute('CREATE INDEX IF NOT EXISTS outhash_lookup ON tasks_v2 (method, outhash)') - logger.info('Starting server on %s', addr) + ret = ThreadedHTTPServer(addr, Handler) + + logger.info('Starting server on %s\n', ret.server_port) - return ThreadedHTTPServer(addr, Handler) + return ret
lib/hashserv/tests.py +4 -4
@@ -6,7 +6,7 @@ # import unittest -import threading +import multiprocessing import sqlite3 import hashlib import urllib.request
@@ -21,16 +21,16 @@ class TestHashEquivalenceServer(unittest.TestCase): self.dbfile = tempfile.NamedTemporaryFile(prefix="bb-hashserv-db-") self.server = create_server(('localhost', 0), self.dbfile.name) self.server_addr = 'http://localhost:%d' % self.server.socket.getsockname()[1] - self.server_thread = threading.Thread(target=self.server.serve_forever) + self.server_thread = multiprocessing.Process(target=self.server.serve_forever) + self.server_thread.daemon = True self.server_thread.start() def tearDown(self): # Shutdown server s = getattr(self, 'server', None) if s is not None: - self.server.shutdown() + self.server_thread.terminate() self.server_thread.join() - self.server.server_close() def send_get(self, path): url = '%s/%s' % (self.server_addr, path)
Signature · 1 line
2.20.1
PATCH 12/16 runqueue: Clean up BB_HASHCHECK_FUNCTION API
In reply to Richard PurdieThis function uses an old API which uses offsets into lists as a communication mechanism. Update the API to use "tid" which is used universally in runqueue now.
We can also add kwargs support to the funciton definition to drop some of the backwards compaiblility hoops we had to jump though with different function argument combinations.
--- lib/bb/runqueue.py | 54 +++++-------------- .../tests/runqueue-tests/classes/base.bbclass | 22 ++++---- 2 files changed, 23 insertions(+), 53 deletions(-)
lib/bb/runqueue.py +13 -41
@@ -1388,57 +1388,29 @@ class RunQueue: cache[tid] = iscurrent return iscurrent - def validate_hashes(self, tocheck, data, presentcount=None, siginfo=False): + def validate_hashes(self, tocheck, data, currentcount=None, siginfo=False): valid = set() if self.hashvalidate: - sq_hash = [] - sq_hashfn = [] - sq_unihash = [] - sq_fn = [] - sq_taskname = [] - sq_task = [] + sq_data = {} + sq_data['hash'] = {} + sq_data['hashfn'] = {} + sq_data['unihash'] = {} for tid in tocheck: (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) + sq_data['hash'][tid] = self.rqdata.runtaskentries[tid].hash + sq_data['hashfn'][tid] = self.rqdata.dataCaches[mc].hashfn[taskfn] + sq_data['unihash'][tid] = self.rqdata.runtaskentries[tid].unihash - sq_fn.append(fn) - sq_hashfn.append(self.rqdata.dataCaches[mc].hashfn[taskfn]) - sq_hash.append(self.rqdata.runtaskentries[tid].hash) - sq_unihash.append(self.rqdata.runtaskentries[tid].unihash) - sq_taskname.append(taskname) - sq_task.append(tid) - - if presentcount is not None: - data.setVar("BB_SETSCENE_STAMPCURRENT_COUNT", presentcount) - - valid_ids = self.validate_hash(sq_fn, sq_taskname, sq_hash, sq_hashfn, siginfo, sq_unihash, data, presentcount) - - if presentcount is not None: - data.delVar("BB_SETSCENE_STAMPCURRENT_COUNT") - - for v in valid_ids: - valid.add(sq_task[v]) + valid_ids = self.validate_hash(sq_data, data, siginfo, currentcount) return valid - def validate_hash(self, sq_fn, sq_task, sq_hash, sq_hashfn, siginfo, sq_unihash, d, presentcount): - locs = {"sq_fn" : sq_fn, "sq_task" : sq_task, "sq_hash" : sq_hash, "sq_hashfn" : sq_hashfn, - "sq_unihash" : sq_unihash, "siginfo" : siginfo, "d" : d} + def validate_hash(self, sq_data, d, siginfo, currentcount): + locs = {"sq_data" : sq_data, "d" : d, "siginfo" : siginfo, "currentcount" : currentcount} - # Backwards compatibility - hashvalidate_args = ("(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=siginfo, sq_unihash=sq_unihash)", - "(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=siginfo)", - "(sq_fn, sq_task, sq_hash, sq_hashfn, d)") - - for args in hashvalidate_args[:-1]: - try: - call = self.hashvalidate + args - return bb.utils.better_eval(call, locs) - except TypeError: - continue + # Metadata has **kwargs so args can be added, sq_data can also gain new fields + call = self.hashvalidate + "(sq_data, d, siginfo=siginfo, currentcount=currentcount)" - # Call the last entry without a try...catch to propagate any thrown - # TypeError - call = self.hashvalidate + hashvalidate_args[-1] return bb.utils.better_eval(call, locs) def _execute_runqueue(self):
lib/bb/tests/runqueue-tests/classes/base.bbclass +10 -12
@@ -216,27 +216,25 @@ def setscene_depvalid(task, taskdependees, notneeded, d, log=None): BB_HASHCHECK_FUNCTION = "sstate_checkhashes" -def sstate_checkhashes(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=False, *, sq_unihash=None): +def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, **kwargs): - ret = [] - missed = [] + found = set() + missed = set() valid = d.getVar("SSTATEVALID").split() - for task in range(len(sq_fn)): - n = os.path.basename(sq_fn[task]).rsplit(".", 1)[0] + ":" + sq_task[task] + for tid in sq_data['hash']: + n = os.path.basename(bb.runqueue.fn_from_tid(tid)).split(".")[0] + ":do_" + bb.runqueue.taskname_from_tid(tid)[3:] + print(n) if n in valid: bb.note("SState: Found valid sstate for %s" % n) - ret.append(task) + found.add(tid) elif os.path.exists(d.expand("${TOPDIR}/%s.run" % n.replace("do_", ""))): bb.note("SState: Found valid sstate for %s (already run)" % n) - ret.append(task) + found.add(tid) else: - missed.append(task) + missed.add(tid) bb.note("SState: Found no valid sstate for %s" % n) - if hasattr(bb.parse.siggen, "checkhashes"): - bb.parse.siggen.checkhashes(missed, ret, sq_fn, sq_task, sq_hash, sq_hashfn, d) - - return ret + return found
Signature · 1 line
2.20.1
PATCH 13/16 siggen: Clean up task reference formats
In reply to Richard PurdieCurrently siggen uses the format "<filename>.<taskname>" for referencing tasks whilst runqueue uses "<filename>:<taskname>". This converts to use ":" as the separator everywhere.
This is an API breaking change since the cache is affected, as are siginfo files and any custom signature handlers such as those in OE-Core.
Ultimately this will let us clean up and the accessor functions from runqueue, removing all the ".rsplit(".", 1)[0]" type code currently all over the place. Once a standard is used everwhere we can update the code over time to be more optimal.
--- lib/bb/cache.py | 2 +- lib/bb/data.py | 2 +- lib/bb/runqueue.py | 19 +++--- lib/bb/siggen.py | 152 ++++++++++++++++++++----------------------- lib/bb/tests/data.py | 2 +- 5 files changed, 82 insertions(+), 95 deletions(-)
lib/bb/cache.py +1 -1
@@ -220,7 +220,7 @@ class CoreRecipeInfo(RecipeInfoCommon): cachedata.hashfn[fn] = self.hashfilename for task, taskhash in self.basetaskhashes.items(): - identifier = '%s.%s' % (fn, task) + identifier = '%s:%s' % (fn, task) cachedata.basetaskhash[identifier] = taskhash cachedata.inherits[fn] = self.inherits
lib/bb/data.py +1 -1
@@ -422,7 +422,7 @@ def generate_dependency_hash(tasklist, gendeps, lookupcache, whitelist, fn): var = lookupcache[dep] if var is not None: data = data + str(var) - k = fn + "." + task + k = fn + ":" + task basehash[k] = hashlib.sha256(data.encode("utf-8")).hexdigest() taskdeps[task] = alldeps
lib/bb/runqueue.py +8 -11
@@ -1174,10 +1174,9 @@ class RunQueueData: def prepare_task_hash(self, tid): procdep = [] for dep in self.runtaskentries[tid].depends: - procdep.append(fn_from_tid(dep) + "." + taskname_from_tid(dep)) - (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) - self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(taskfn, taskname, procdep, self.dataCaches[mc]) - self.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(taskfn + "." + taskname) + procdep.append(dep) + self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(tid, procdep, self.dataCaches[mc_from_tid(tid)]) + self.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(tid) def dump_data(self): """
@@ -1401,7 +1400,7 @@ class RunQueue: sq_data['hashfn'][tid] = self.rqdata.dataCaches[mc].hashfn[taskfn] sq_data['unihash'][tid] = self.rqdata.runtaskentries[tid].unihash - valid_ids = self.validate_hash(sq_data, data, siginfo, currentcount) + valid = self.validate_hash(sq_data, data, siginfo, currentcount) return valid
@@ -2152,8 +2151,7 @@ class RunQueueExecute: if unihash != self.rqdata.runtaskentries[tid].unihash: logger.info("Task %s unihash changed to %s" % (tid, unihash)) self.rqdata.runtaskentries[tid].unihash = unihash - (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) - bb.parse.siggen.set_unihash(taskfn + "." + taskname, unihash) + bb.parse.siggen.set_unihash(tid, unihash) # Work out all tasks which depend on this one total = set()
@@ -2177,12 +2175,11 @@ class RunQueueExecute: continue procdep = [] for dep in self.rqdata.runtaskentries[tid].depends: - procdep.append(fn_from_tid(dep) + "." + taskname_from_tid(dep)) - (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) + procdep.append(dep) orighash = self.rqdata.runtaskentries[tid].hash - self.rqdata.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(taskfn, taskname, procdep, self.rqdata.dataCaches[mc]) + self.rqdata.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(tid, procdep, self.rqdata.dataCaches[mc_from_tid(tid)]) origuni = self.rqdata.runtaskentries[tid].unihash - self.rqdata.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(taskfn + "." + taskname) + self.rqdata.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(tid) logger.debug(1, "Task %s hash changes: %s->%s %s->%s" % (tid, orighash, self.rqdata.runtaskentries[tid].hash, origuni, self.rqdata.runtaskentries[tid].unihash)) next |= self.rqdata.runtaskentries[tid].revdeps changed.add(tid)
lib/bb/siggen.py +71 -81
311 lines not on this page · raw message
lib/bb/tests/data.py +1 -1
@@ -466,7 +466,7 @@ class TaskHash(unittest.TestCase): tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d) taskdeps, basehash = bb.data.generate_dependency_hash(tasklist, gendeps, lookupcache, set(), "somefile") bb.warn(str(lookupcache)) - return basehash["somefile." + taskname] + return basehash["somefile:" + taskname] d = bb.data.init() d.setVar("__BBTASKS", ["mytask"])
Signature · 1 line
2.20.1
Re: [PATCH 13/16] siggen: Clean up task reference formats
There are filesystems (MacOS primarily) where ':' is the separator. So it would be better to continue using '.'..
AFAIK the common separators are: /, \ and :
And some filesystems seem to have special syntax for '@' as well.
--Mark
Quoted 444 lines · Richard Purdie
Currently siggen uses the format "<filename>.<taskname>" for referencing tasks whilst runqueue uses "<filename>:<taskname>". This converts to use ":" as the separator everywhere.
This is an API breaking change since the cache is affected, as are siginfo files and any custom signature handlers such as those in OE-Core.
Ultimately this will let us clean up and the accessor functions from runqueue, removing all the ".rsplit(".", 1)[0]" type code currently all over the place. Once a standard is used everwhere we can update the code over time to be more optimal.
Signed-off-by Richard Purdie <[email protected]>--- lib/bb/cache.py | 2 +- lib/bb/data.py | 2 +- lib/bb/runqueue.py | 19 +++--- lib/bb/siggen.py | 152 ++++++++++++++++++++----------------------- lib/bb/tests/data.py | 2 +- 5 files changed, 82 insertions(+), 95 deletions(-)lib/bb/cache.py +1
-1@@ -220,7 +220,7 @@ class CoreRecipeInfo(RecipeInfoCommon): cachedata.hashfn[fn] = self.hashfilename for task, taskhash in self.basetaskhashes.items(): - identifier = '%s.%s' % (fn, task) + identifier = '%s:%s' % (fn, task) cachedata.basetaskhash[identifier] = taskhash cachedata.inherits[fn] = self.inheritslib/bb/data.py +1
-1@@ -422,7 +422,7 @@ def generate_dependency_hash(tasklist, gendeps, lookupcache, whitelist, fn): var = lookupcache[dep] if var is not None: data = data + str(var) - k = fn + "." + task + k = fn + ":" + task basehash[k] = hashlib.sha256(data.encode("utf-8")).hexdigest() taskdeps[task] = alldepslib/bb/runqueue.py +8
-11@@ -1174,10 +1174,9 @@ class RunQueueData: def prepare_task_hash(self, tid): procdep = [] for dep in self.runtaskentries[tid].depends: - procdep.append(fn_from_tid(dep) + "." + taskname_from_tid(dep)) - (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) - self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(taskfn, taskname, procdep, self.dataCaches[mc]) - self.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(taskfn + "." + taskname) + procdep.append(dep) + self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(tid, procdep, self.dataCaches[mc_from_tid(tid)]) + self.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(tid) def dump_data(self): """@@ -1401,7 +1400,7 @@ class RunQueue: sq_data['hashfn'][tid] = self.rqdata.dataCaches[mc].hashfn[taskfn] sq_data['unihash'][tid] = self.rqdata.runtaskentries[tid].unihash - valid_ids = self.validate_hash(sq_data, data, siginfo, currentcount) + valid = self.validate_hash(sq_data, data, siginfo, currentcount) return valid@@ -2152,8 +2151,7 @@ class RunQueueExecute: if unihash != self.rqdata.runtaskentries[tid].unihash: logger.info("Task %s unihash changed to %s" % (tid, unihash)) self.rqdata.runtaskentries[tid].unihash = unihash - (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) - bb.parse.siggen.set_unihash(taskfn + "." + taskname, unihash) + bb.parse.siggen.set_unihash(tid, unihash) # Work out all tasks which depend on this one total = set()@@ -2177,12 +2175,11 @@ class RunQueueExecute: continue procdep = [] for dep in self.rqdata.runtaskentries[tid].depends: - procdep.append(fn_from_tid(dep) + "." + taskname_from_tid(dep)) - (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) + procdep.append(dep) orighash = self.rqdata.runtaskentries[tid].hash - self.rqdata.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(taskfn, taskname, procdep, self.rqdata.dataCaches[mc]) + self.rqdata.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(tid, procdep, self.rqdata.dataCaches[mc_from_tid(tid)]) origuni = self.rqdata.runtaskentries[tid].unihash - self.rqdata.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(taskfn + "." + taskname) + self.rqdata.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(tid) logger.debug(1, "Task %s hash changes: %s->%s %s->%s" % (tid, orighash, self.rqdata.runtaskentries[tid].hash, origuni, self.rqdata.runtaskentries[tid].unihash)) next |= self.rqdata.runtaskentries[tid].revdeps changed.add(tid)lib/bb/siggen.py +71
-81@@ -46,13 +46,12 @@ class SignatureGenerator(object): def finalise(self, fn, d, varient): return - def get_unihash(self, task): - return self.taskhash[task] + def get_unihash(self, tid): + return self.taskhash[tid] - def get_taskhash(self, fn, task, deps, dataCache): - k = fn + "." + task - self.taskhash[k] = hashlib.sha256(k.encode("utf-8")).hexdigest() - return self.taskhash[k] + def get_taskhash(self, tid, deps, dataCache): + self.taskhash[tid] = hashlib.sha256(tid.encode("utf-8")).hexdigest() + return self.taskhash[tid] def writeout_file_checksum_cache(self): """Write/update the file checksum cache onto disk"""@@ -106,7 +105,6 @@ class SignatureGeneratorBasic(SignatureGenerator): self.taints = {} self.gendeps = {} self.lookupcache = {} - self.pkgnameextract = re.compile(r"(?P<fn>.*)\..*") self.basewhitelist = set((data.getVar("BB_HASHBASE_WHITELIST") or "").split()) self.taskwhitelist = None self.init_rundepcheck(data)@@ -135,16 +133,16 @@ class SignatureGeneratorBasic(SignatureGenerator): taskdeps, basehash = bb.data.generate_dependency_hash(tasklist, gendeps, lookupcache, self.basewhitelist, fn) for task in tasklist: - k = fn + "." + task - if not ignore_mismatch and k in self.basehash and self.basehash[k] != basehash[k]: - 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])) + tid = fn + ":" + task + if not ignore_mismatch and tid in self.basehash and self.basehash[tid] != basehash[tid]: + bb.error("When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed." % (tid, self.basehash[tid], basehash[tid])) bb.error("The following commands may help:") cmd = "$ bitbake %s -c%s" % (d.getVar('PN'), task) # Make sure sigdata is dumped before run printdiff bb.error("%s -Snone" % cmd) bb.error("Then:") bb.error("%s -Sprintdiff\n" % cmd) - self.basehash[k] = basehash[k] + self.basehash[tid] = basehash[tid] self.taskdeps[fn] = taskdeps self.gendeps[fn] = gendeps@@ -171,7 +169,7 @@ class SignatureGeneratorBasic(SignatureGenerator): # self.dump_sigtask(fn, task, d.getVar("STAMP"), False) for task in taskdeps: - d.setVar("BB_BASEHASH_task-%s" % task, self.basehash[fn + "." + task]) + d.setVar("BB_BASEHASH_task-%s" % task, self.basehash[fn + ":" + task]) def rundep_check(self, fn, recipename, task, dep, depname, dataCache): # Return True if we should keep the dependency, False to drop it@@ -191,33 +189,26 @@ class SignatureGeneratorBasic(SignatureGenerator): pass return taint - def get_taskhash(self, fn, task, deps, dataCache): + def get_taskhash(self, tid, deps, dataCache): - mc = '' - if fn.startswith('mc:'): - mc = fn.split(':')[1] - k = fn + "." + task + (mc, _, task, fn) = bb.runqueue.split_tid_mcfn(tid) - data = dataCache.basetaskhash[k] - self.basehash[k] = data - self.runtaskdeps[k] = [] - self.file_checksum_values[k] = [] + data = dataCache.basetaskhash[tid] + self.basehash[tid] = data + self.runtaskdeps[tid] = [] + self.file_checksum_values[tid] = [] recipename = dataCache.pkg_fn[fn] for dep in sorted(deps, key=clean_basepath): - pkgname = self.pkgnameextract.search(dep).group('fn') - if mc: - depmc = pkgname.split(':')[1] - if mc != depmc: - continue - if dep.startswith("mc:") and not mc: + (depmc, _, deptaskname, depfn) = bb.runqueue.split_tid_mcfn(dep) + if mc != depmc: continue - depname = dataCache.pkg_fn[pkgname] + depname = dataCache.pkg_fn[depfn] if not self.rundep_check(fn, recipename, task, dep, depname, dataCache): continue if dep not in self.taskhash: bb.fatal("%s is not in taskhash, caller isn't calling in dependency order?" % dep) data = data + self.get_unihash(dep) - self.runtaskdeps[k].append(dep) + self.runtaskdeps[tid].append(dep) if task in dataCache.file_checksums[fn]: if self.checksum_cache:@@ -225,7 +216,7 @@ class SignatureGeneratorBasic(SignatureGenerator): else: checksums = bb.fetch2.get_file_checksums(dataCache.file_checksums[fn][task], recipename) for (f,cs) in checksums: - self.file_checksum_values[k].append((f,cs)) + self.file_checksum_values[tid].append((f,cs)) if cs: data = data + cs@@ -235,16 +226,16 @@ class SignatureGeneratorBasic(SignatureGenerator): import uuid taint = str(uuid.uuid4()) data = data + taint - self.taints[k] = "nostamp:" + taint + self.taints[tid] = "nostamp:" + taint taint = self.read_taint(fn, task, dataCache.stamp[fn]) if taint: data = data + taint - self.taints[k] = taint - logger.warning("%s is tainted from a forced run" % k) + self.taints[tid] = taint + logger.warning("%s is tainted from a forced run" % tid) h = hashlib.sha256(data.encode("utf-8")).hexdigest() - self.taskhash[k] = h + self.taskhash[tid] = h #d.setVar("BB_TASKHASH_task-%s" % task, taskhash[task]) return h@@ -262,15 +253,15 @@ class SignatureGeneratorBasic(SignatureGenerator): def dump_sigtask(self, fn, task, stampbase, runtime): - k = fn + "." + task + tid = fn + ":" + task referencestamp = stampbase if isinstance(runtime, str) and runtime.startswith("customfile"): sigfile = stampbase referencestamp = runtime[11:] - elif runtime and k in self.taskhash: - sigfile = stampbase + "." + task + ".sigdata" + "." + self.taskhash[k] + elif runtime and tid in self.taskhash: + sigfile = stampbase + "." + task + ".sigdata" + "." + self.taskhash[tid] else: - sigfile = stampbase + "." + task + ".sigbasedata" + "." + self.basehash[k] + sigfile = stampbase + "." + task + ".sigbasedata" + "." + self.basehash[tid] bb.utils.mkdirhier(os.path.dirname(sigfile))@@ -279,7 +270,7 @@ class SignatureGeneratorBasic(SignatureGenerator): data['basewhitelist'] = self.basewhitelist data['taskwhitelist'] = self.taskwhitelist data['taskdeps'] = self.taskdeps[fn][task] - data['basehash'] = self.basehash[k] + data['basehash'] = self.basehash[tid] data['gendeps'] = {} data['varvals'] = {} data['varvals'][task] = self.lookupcache[fn][task]@@ -289,30 +280,30 @@ class SignatureGeneratorBasic(SignatureGenerator): data['gendeps'][dep] = self.gendeps[fn][dep] data['varvals'][dep] = self.lookupcache[fn][dep] - if runtime and k in self.taskhash: - data['runtaskdeps'] = self.runtaskdeps[k] - data['file_checksum_values'] = [(os.path.basename(f), cs) for f,cs in self.file_checksum_values[k]] + if runtime and tid in self.taskhash: + data['runtaskdeps'] = self.runtaskdeps[tid] + data['file_checksum_values'] = [(os.path.basename(f), cs) for f,cs in self.file_checksum_values[tid]] data['runtaskhashes'] = {} for dep in data['runtaskdeps']: data['runtaskhashes'][dep] = self.get_unihash(dep) - data['taskhash'] = self.taskhash[k] + data['taskhash'] = self.taskhash[tid] taint = self.read_taint(fn, task, referencestamp) if taint: data['taint'] = taint - if runtime and k in self.taints: - if 'nostamp:' in self.taints[k]: - data['taint'] = self.taints[k] + if runtime and tid in self.taints: + if 'nostamp:' in self.taints[tid]: + data['taint'] = self.taints[tid] computed_basehash = calc_basehash(data) - if computed_basehash != self.basehash[k]: - bb.error("Basehash mismatch %s versus %s for %s" % (computed_basehash, self.basehash[k], k)) - if runtime and k in self.taskhash: + if computed_basehash != self.basehash[tid]: + bb.error("Basehash mismatch %s versus %s for %s" % (computed_basehash, self.basehash[tid], tid)) + if runtime and tid in self.taskhash: computed_taskhash = calc_taskhash(data) - if computed_taskhash != self.taskhash[k]: - bb.error("Taskhash mismatch %s versus %s for %s" % (computed_taskhash, self.taskhash[k], k)) - sigfile = sigfile.replace(self.taskhash[k], computed_taskhash) + if computed_taskhash != self.taskhash[tid]: + bb.error("Taskhash mismatch %s versus %s for %s" % (computed_taskhash, self.taskhash[tid], tid)) + sigfile = sigfile.replace(self.taskhash[tid], computed_taskhash) fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.") try:@@ -332,34 +323,33 @@ class SignatureGeneratorBasic(SignatureGenerator): if fn in self.taskdeps: for task in self.taskdeps[fn]: tid = fn + ":" + task - (mc, _, _) = bb.runqueue.split_tid(tid) - k = fn + "." + task - if k not in self.taskhash: + mc = bb.runqueue.mc_from_tid(tid) + if tid not in self.taskhash: continue - if dataCaches[mc].basetaskhash[k] != self.basehash[k]: - bb.error("Bitbake's cached basehash does not match the one we just generated (%s)!" % k) - bb.error("The mismatched hashes were %s and %s" % (dataCaches[mc].basetaskhash[k], self.basehash[k])) + if dataCaches[mc].basetaskhash[tid] != self.basehash[tid]: + bb.error("Bitbake's cached basehash does not match the one we just generated (%s)!" % tid) + bb.error("The mismatched hashes were %s and %s" % (dataCaches[mc].basetaskhash[tid], self.basehash[tid])) self.dump_sigtask(fn, task, dataCaches[mc].stamp[fn], True) class SignatureGeneratorBasicHash(SignatureGeneratorBasic): name = "basichash" - def get_stampfile_hash(self, task): - if task in self.taskhash: - return self.taskhash[task] + def get_stampfile_hash(self, tid): + if tid in self.taskhash: + return self.taskhash[tid] # If task is not in basehash, then error - return self.basehash[task] + return self.basehash[tid] def stampfile(self, stampbase, fn, taskname, extrainfo, clean=False): if taskname != "do_setscene" and taskname.endswith("_setscene"): - k = fn + "." + taskname[:-9] + tid = fn + ":" + taskname[:-9] else: - k = fn + "." + taskname + tid = fn + ":" + taskname if clean: h = "*" else: - h = self.get_stampfile_hash(k) + h = self.get_stampfile_hash(tid) return ("%s.%s.%s.%s" % (stampbase, taskname, h, extrainfo)).rstrip('.')@@ -378,32 +368,32 @@ class SignatureGeneratorUniHashMixIn(object): self.server, self.method = data[:2] super().set_taskdata(data[2:]) - def __get_task_unihash_key(self, task): - # TODO: The key only *needs* to be the taskhash, the task is just + def __get_task_unihash_key(self, tid): + # TODO: The key only *needs* to be the taskhash, the tid is just # convenient - return '%s:%s' % (task, self.taskhash[task]) + return '%s:%s' % (tid, self.taskhash[tid]) - def get_stampfile_hash(self, task): - if task in self.taskhash: + def get_stampfile_hash(self, tid): + if tid in self.taskhash: # If a unique hash is reported, use it as the stampfile hash. This # ensures that if a task won't be re-run if the taskhash changes, # but it would result in the same output hash - unihash = self.unitaskhashes.get(self.__get_task_unihash_key(task), None) + unihash = self.unitaskhashes.get(self.__get_task_unihash_key(tid), None) if unihash is not None: return unihash - return super().get_stampfile_hash(task) + return super().get_stampfile_hash(tid) - def set_unihash(self, task, unihash): - self.unitaskhashes[self.__get_task_unihash_key(task)] = unihash + def set_unihash(self, tid, unihash): + self.unitaskhashes[self.__get_task_unihash_key(tid)] = unihash - def get_unihash(self, task): + def get_unihash(self, tid): import urllib import json - taskhash = self.taskhash[task] + taskhash = self.taskhash[tid] - key = self.__get_task_unihash_key(task) + key = self.__get_task_unihash_key(tid) # TODO: This cache can grow unbounded. It probably only needs to keep # for each task@@ -428,7 +418,7 @@ class SignatureGeneratorUniHashMixIn(object): try: url = '%s/v1/equivalent?%s' % (self.server, - urllib.parse.urlencode({'method': self.method, 'taskhash': self.taskhash[task]})) + urllib.parse.urlencode({'method': self.method, 'taskhash': self.taskhash[tid]})) request = urllib.request.Request(url) response = urllib.request.urlopen(request)@@ -441,9 +431,9 @@ class SignatureGeneratorUniHashMixIn(object): # A unique hash equal to the taskhash is not very interesting, # so it is reported it at debug level 2. If they differ, that # is much more interesting, so it is reported at debug level 1 - bb.debug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, task, self.server)) + bb.debug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server)) else: - bb.debug(2, 'No reported unihash for %s:%s from %s' % (task, taskhash, self.server)) + bb.debug(2, 'No reported unihash for %s:%s from %s' % (tid, taskhash, self.server)) except urllib.error.URLError as e: bb.warn('Failure contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) except (KeyError, json.JSONDecodeError) as e:@@ -464,7 +454,7 @@ class SignatureGeneratorUniHashMixIn(object): report_taskdata = d.getVar('SSTATE_HASHEQUIV_REPORT_TASKDATA') == '1' tempdir = d.getVar('T') fn = d.getVar('BB_FILENAME') - key = fn + '.do_' + task + ':' + taskhash + key = fn + ':do_' + task + ':' + taskhash # Sanity checks cache_unihash = self.unitaskhashes.get(key, None)lib/bb/tests/data.py +1
-1@@ -466,7 +466,7 @@ class TaskHash(unittest.TestCase): tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d) taskdeps, basehash = bb.data.generate_dependency_hash(tasklist, gendeps, lookupcache, set(), "somefile") bb.warn(str(lookupcache)) - return basehash["somefile." + taskname] + return basehash["somefile:" + taskname] d = bb.data.init() d.setVar("__BBTASKS", ["mytask"])
Re: [PATCH 13/16] siggen: Clean up task reference formats
Quoted 3 lines · Mark Hatle
There are filesystems (MacOS primarily) where ':' is the separator. So it would
be better to continue using '.'..
The ship has sailed on that, ":" is used throughout runqueue already. This patch just brings pieces of external API into line with that. Using "." is even worse as its in every filename.
Cheers,
Richard
PATCH 14/16 build/utils: Drop bb.build.FuncFailed
In reply to Richard PurdieIts hard to see what this exception adds in the current codebase. The logfile attribute is effectively ignored, the exception doesn't serve a defined purpose and mostly seems to be worked around.
Remove it entirely. If this does cause output problems, we'll figure out better ways to address those.
--- lib/bb/build.py | 57 +++++++++---------------------------------------- lib/bb/data.py | 2 +- lib/bb/utils.py | 2 +- 3 files changed, 12 insertions(+), 49 deletions(-)
lib/bb/build.py +10 -47
@@ -54,23 +54,6 @@ else: builtins['bb'] = bb builtins['os'] = os -class FuncFailed(Exception): - def __init__(self, name = None, logfile = None): - self.logfile = logfile - self.name = name - if name: - self.msg = 'Function failed: %s' % name - else: - self.msg = "Function failed" - - def __str__(self): - if self.logfile and os.path.exists(self.logfile): - msg = ("%s (log file is located at %s)" % - (self.msg, self.logfile)) - else: - msg = self.msg - return msg - class TaskBase(event.Event): """Base class for task events"""
@@ -189,12 +172,7 @@ class StdoutNoopContextManager: return sys.stdout.name -# -# pythonexception allows the python exceptions generated to be raised -# as the real exceptions (not FuncFailed) and without a backtrace at the -# origin of the failure. -# -def exec_func(func, d, dirs = None, pythonexception=False): +def exec_func(func, d, dirs = None): """Execute a BB 'function'""" try:
@@ -266,7 +244,7 @@ def exec_func(func, d, dirs = None, pythonexception=False): with bb.utils.fileslocked(lockfiles): if ispython: - exec_func_python(func, d, runfile, cwd=adir, pythonexception=pythonexception) + exec_func_python(func, d, runfile, cwd=adir) else: exec_func_shell(func, d, runfile, cwd=adir)
@@ -286,7 +264,7 @@ _functionfmt = """ {function}(d) """ logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s") -def exec_func_python(func, d, runfile, cwd=None, pythonexception=False): +def exec_func_python(func, d, runfile, cwd=None): """Execute a python BB 'function'""" code = _functionfmt.format(function=func)
@@ -311,14 +289,7 @@ def exec_func_python(func, d, runfile, cwd=None, pythonexception=False): bb.methodpool.insert_method(func, text, fn, lineno - 1) comp = utils.better_compile(code, func, "exec_python_func() autogenerated") - utils.better_exec(comp, {"d": d}, code, "exec_python_func() autogenerated", pythonexception=pythonexception) - except (bb.parse.SkipRecipe, bb.build.FuncFailed): - raise - except Exception as e: - if pythonexception: - raise - logger.error(str(e)) - raise FuncFailed(func, None) + utils.better_exec(comp, {"d": d}, code, "exec_python_func() autogenerated") finally: bb.debug(2, "Python function %s finished" % func)
@@ -475,13 +446,8 @@ exit $ret with open(fifopath, 'r+b', buffering=0) as fifo: try: bb.debug(2, "Executing shell function %s" % func) - - try: - with open(os.devnull, 'r+') as stdin, logfile: - bb.process.run(cmd, shell=False, stdin=stdin, log=logfile, extrafiles=[(fifo,readfifo)]) - except bb.process.CmdError: - logfn = d.getVar('BB_LOGFILE') - raise FuncFailed(func, logfn) + with open(os.devnull, 'r+') as stdin, logfile: + bb.process.run(cmd, shell=False, stdin=stdin, log=logfile, extrafiles=[(fifo,readfifo)]) finally: os.unlink(fifopath)
@@ -609,9 +575,6 @@ def _exec_task(fn, task, d, quieterr): event.fire(TaskStarted(task, logfn, flags, localdata), localdata) except (bb.BBHandledException, SystemExit): return 1 - except FuncFailed as exc: - logger.error(str(exc)) - return 1 try: for func in (prefuncs or '').split():
@@ -619,7 +582,10 @@ def _exec_task(fn, task, d, quieterr): exec_func(task, localdata) for func in (postfuncs or '').split(): exec_func(func, localdata) - except FuncFailed as exc: + except bb.BBHandledException: + event.fire(TaskFailed(task, logfn, localdata, True), localdata) + return 1 + except Exception as exc: if quieterr: event.fire(TaskFailedSilent(task, logfn, localdata), localdata) else:
@@ -627,9 +593,6 @@ def _exec_task(fn, task, d, quieterr): logger.error(str(exc)) event.fire(TaskFailed(task, logfn, localdata, errprinted), localdata) return 1 - except bb.BBHandledException: - event.fire(TaskFailed(task, logfn, localdata, True), localdata) - return 1 finally: sys.stdout.flush() sys.stderr.flush()
lib/bb/data.py +1 -1
@@ -130,7 +130,7 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False): if all: oval = d.getVar(var, False) val = d.getVar(var) - except (KeyboardInterrupt, bb.build.FuncFailed): + except (KeyboardInterrupt): raise except Exception as exc: o.write('# expansion of %s threw %s: %s\n' % (var, exc.__class__.__name__, str(exc)))
lib/bb/utils.py +1 -1
@@ -394,7 +394,7 @@ def better_exec(code, context, text = None, realfile = "<code>", pythonexception code = better_compile(code, realfile, realfile) try: exec(code, get_context(), context) - except (bb.BBHandledException, bb.parse.SkipRecipe, bb.build.FuncFailed, bb.data_smart.ExpansionError): + except (bb.BBHandledException, bb.parse.SkipRecipe, bb.data_smart.ExpansionError): # Error already shown so passthrough, no need for traceback raise except Exception as e:
Signature · 1 line
2.20.1
PATCH 15/16 tests/runqueue: Add hashserv+runqueue test
In reply to Richard PurdieAdd a test which tests the runqueue adaptations for hash equivalency.
--- lib/bb/siggen.py | 23 +++++++++++++--- .../tests/runqueue-tests/classes/base.bbclass | 14 +++++++++- lib/bb/tests/runqueue-tests/conf/bitbake.conf | 2 +- lib/bb/tests/runqueue.py | 27 ++++++++++++++++++- 4 files changed, 59 insertions(+), 7 deletions(-)
lib/bb/siggen.py +19 -4
@@ -12,6 +12,7 @@ import bb.data import difflib import simplediff from bb.checksum import FileChecksumCache +from bb import runqueue logger = logging.getLogger('BitBake.SigGen')
@@ -473,10 +474,12 @@ class SignatureGeneratorUniHashMixIn(object): locs = {'path': path, 'sigfile': sigfile, 'task': task, 'd': d} - (module, method) = self.method.rsplit('.', 1) - locs['method'] = getattr(importlib.import_module(module), method) - - outhash = bb.utils.better_eval('method(path, sigfile, task, d)', locs) + if "." in self.method: + (module, method) = self.method.rsplit('.', 1) + locs['method'] = getattr(importlib.import_module(module), method) + outhash = bb.utils.better_eval('method(path, sigfile, task, d)', locs) + else: + outhash = bb.utils.better_eval(self.method + '(path, sigfile, task, d)', locs) try: url = '%s/v1/equivalent' % self.server
@@ -527,6 +530,18 @@ class SignatureGeneratorUniHashMixIn(object): except OSError: pass + +# +# Dummy class used for bitbake-selftest +# +class SignatureGeneratorTestEquivHash(SignatureGeneratorUniHashMixIn, SignatureGeneratorBasicHash): + name = "TestEquivHash" + def init_rundepcheck(self, data): + super().init_rundepcheck(data) + self.server = "http://" + data.getVar('BB_HASHSERVE') + self.method = "sstate_output_hash" + + def dump_this_task(outfile, d): import bb.parse fn = d.getVar("BB_FILENAME")
lib/bb/tests/runqueue-tests/classes/base.bbclass +13 -1
@@ -5,7 +5,8 @@ def stamptask(d): import time thistask = d.expand("${PN}:${BB_CURRENTTASK}") - with open(d.expand("${TOPDIR}/%s.run") % thistask, "a+") as f: + stampname = d.expand("${TOPDIR}/%s.run" % thistask) + with open(stampname, "a+") as f: f.write("\n") if d.getVar("BB_CURRENT_MC") != "default":
@@ -13,10 +14,21 @@ def stamptask(d): if thistask in d.getVar("SLOWTASKS").split(): bb.note("Slowing task %s" % thistask) time.sleep(0.5) + if d.getVar("BB_HASHSERVE"): + task = d.getVar("BB_CURRENTTASK") + if task in ['package', 'package_qa', 'packagedata', 'package_write_ipk', 'package_write_rpm', 'populate_lic', 'populate_sysroot']: + bb.parse.siggen.report_unihash(os.getcwd(), d.getVar("BB_CURRENTTASK"), d) with open(d.expand("${TOPDIR}/task.log"), "a+") as f: f.write(thistask + "\n") + +def sstate_output_hash(path, sigfile, task, d): + import hashlib + h = hashlib.sha256() + h.update(d.expand("${PN}:${BB_CURRENTTASK}").encode('utf-8')) + return h.hexdigest() + python do_fetch() { # fetch stamptask(d)
lib/bb/tests/runqueue-tests/conf/bitbake.conf +1 -1
@@ -11,6 +11,6 @@ STAMP = "${TMPDIR}/stamps/${PN}" T = "${TMPDIR}/workdir/${PN}/temp" BB_NUMBER_THREADS = "4" -BB_HASHBASE_WHITELIST = "BB_CURRENT_MC" +BB_HASHBASE_WHITELIST = "BB_CURRENT_MC BB_HASHSERVE" include conf/multiconfig/${BB_CURRENT_MC}.conf
lib/bb/tests/runqueue.py +26 -1
@@ -25,7 +25,7 @@ class RunQueueTests(unittest.TestCase): a1_sstatevalid = "a1:do_package a1:do_package_qa a1:do_packagedata a1:do_package_write_ipk a1:do_package_write_rpm a1:do_populate_lic a1:do_populate_sysroot" b1_sstatevalid = "b1:do_package b1:do_package_qa b1:do_packagedata b1:do_package_write_ipk b1:do_package_write_rpm b1:do_populate_lic b1:do_populate_sysroot" - def run_bitbakecmd(self, cmd, builddir, sstatevalid="", slowtasks="", extraenv=None): + def run_bitbakecmd(self, cmd, builddir, sstatevalid="", slowtasks="", extraenv=None, cleanup=False): env = os.environ.copy() env["BBPATH"] = os.path.realpath(os.path.join(os.path.dirname(__file__), "runqueue-tests")) env["BB_ENV_EXTRAWHITE"] = "SSTATEVALID SLOWTASKS"
@@ -42,6 +42,8 @@ class RunQueueTests(unittest.TestCase): tasks = [] with open(builddir + "/task.log", "r") as f: tasks = [line.rstrip() for line in f] + if cleanup: + os.remove(builddir + "/task.log") return tasks def test_no_setscenevalid(self):
@@ -226,3 +228,26 @@ class RunQueueTests(unittest.TestCase): expected.remove(x) self.assertEqual(set(tasks), set(expected)) + + def test_hashserv(self): + with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir: + extraenv = { + "BB_HASHSERVE" : "localhost:0", + "BB_SIGNATURE_HANDLER" : "TestEquivHash" + } + cmd = ["bitbake", "a1", "b1"] + setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene', + 'populate_sysroot_setscene', 'package_qa_setscene'] + sstatevalid = "" + tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True) + expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + self.assertEqual(set(tasks), set(expected)) + cmd = ["bitbake", "a1", "-c", "install", "-f"] + tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True) + expected = ['a1:install'] + self.assertEqual(set(tasks), set(expected)) + cmd = ["bitbake", "a1", "b1"] + tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True) + expected = ['a1:' + x for x in setscenetasks] + ['b1:' + x for x in setscenetasks] + ['a1:build', 'b1:build'] + self.assertEqual(set(tasks), set(expected)) +
Signature · 1 line
2.20.1
PATCH 16/16 bitbake: Bump version to 1.43.1 for API changes
In reply to Richard Purdie--- bin/bitbake | 2 +- lib/bb/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
bin/bitbake +1 -1
@@ -26,7 +26,7 @@ from bb.main import bitbake_main, BitBakeConfigParameters, BBMainException if sys.getfilesystemencoding() != "utf-8": sys.exit("Please use a locale setting which supports UTF-8 (such as LANG=en_US.UTF-8).\nPython can't change the filesystem locale after loading so we need a UTF-8 when Python starts or things won't work.") -__version__ = "1.43.0" +__version__ = "1.43.1" if __name__ == "__main__": if __version__ != bb.__version__:
lib/bb/__init__.py +1 -1
@@ -9,7 +9,7 @@ # SPDX-License-Identifier: GPL-2.0-only # -__version__ = "1.43.0" +__version__ = "1.43.1" import sys if sys.version_info < (3, 4, 0):
Signature · 1 line
2.20.1