diff options
author | Ben Brown <ben.brown@codethink.co.uk> | 2018-01-18 12:58:22 +0000 |
---|---|---|
committer | Ben Brown <ben.brown@codethink.co.uk> | 2018-02-14 17:12:43 +0000 |
commit | d4c73a84ab81d513f80962d8e33e6ae83a810b7f (patch) | |
tree | 0fea0ec77c21de8ad021d069c68d210e408df2e7 | |
parent | 0c2633414867d6b83fb028a31c0bd963a3f557b5 (diff) | |
download | ybd-d4c73a84ab81d513f80962d8e33e6ae83a810b7f.tar.gz |
Have a separate cache-key for rpm building with rpm-metadata
When changing rpm-metadata, we don't want to rebuild the artifact we use
to generate the rpms, we just want to regenerate the rpm using the same
artifact.
-rw-r--r-- | ybd/cache.py | 34 | ||||
-rw-r--r-- | ybd/rpm.py | 4 |
2 files changed, 21 insertions, 17 deletions
diff --git a/ybd/cache.py b/ybd/cache.py index b4f5e27..1c5f366 100644 --- a/ybd/cache.py +++ b/ybd/cache.py @@ -30,18 +30,22 @@ import yaml import re -def cache_key(dn): +def cache_key(dn, mode='normal'): if dn is None: app.log(dn, 'No definition found for', dn, exit=True) if type(dn) is not dict: dn = app.defs.get(dn) - if dn.get('cache') == 'calculating': + cache_name = 'cache' + if mode != 'normal': + cache_name = '{}-{}'.format(mode, cache_name) + + if dn.get(cache_name) == 'calculating': app.log(dn, 'Recursion loop for', dn, exit=True) - if dn.get('cache'): - return dn['cache'] + if dn.get(cache_name): + return dn[cache_name] if dn.get('arch', app.config['arch']) != app.config['arch']: if 'tried' not in dn: @@ -50,7 +54,7 @@ def cache_key(dn): app.config['arch']) return False - dn['cache'] = 'calculating' + dn[cache_name] = 'calculating' key = 'no-build' if app.config.get('mode', 'normal') in ['keys-only', 'normal']: @@ -59,11 +63,11 @@ def cache_key(dn): dn['tree'], dn['sha'] = get_tree(dn) if not dn.get('repourl'): dn['repourl'] = get_repo_url(dn.get('repo')) - factors = hash_factors(dn) + factors = hash_factors(dn, mode) factors = json.dumps(factors, sort_keys=True).encode('utf-8') key = hashlib.sha256(factors).hexdigest() - dn['cache'] = dn['name'] + "." + key + dn[cache_name] = dn['name'] + "." + key app.config['total'] += 1 x = 'x' @@ -78,16 +82,16 @@ def cache_key(dn): if dn.get('kind', 'chunk') == 'system': app.config['systems'] += 1 - app.log('CACHE-KEYS', '[%s]' % x, dn['cache']) + app.log('CACHE-KEYS', '[%s]' % x, dn[cache_name]) if app.config.get('manifest', False): update_manifest(dn, app.config['manifest']) if 'keys' in app.config: - app.config['keys'] += [dn['cache']] - return dn['cache'] + app.config['keys'] += [dn[cache_name]] + return dn[cache_name] -def hash_factors(dn): +def hash_factors(dn, mode='normal'): hash_factors = {'arch': app.config['arch']} for factor in dn.get('contents', []): @@ -139,10 +143,6 @@ def hash_factors(dn): else: hash_factors['max-jobs'] = 'parallel' - if artifact_version not in range(0, 10): - if dn.get('rpm-metadata'): - hash_factors['rpm-metadata'] = dn['rpm-metadata'] - if artifact_version in range(0, 12): for factor in dn.get('build-depends', []): hash_factors[factor] = cache_key(factor) @@ -155,6 +155,10 @@ def hash_factors(dn): if dn.get('prefix'): hash_factors['prefix'] = dn['prefix'] + if artifact_version >= 10 and (artifact_version < 13 or mode == 'rpm'): + if dn.get('rpm-metadata'): + hash_factors['rpm-metadata'] = dn['rpm-metadata'] + return hash_factors @@ -51,7 +51,7 @@ def foreach_def(dn, callback, user_data, traversed=None, whitelist=None): dn = app.defs.get(dn) # if we can't calculate cache key, we can't create this component - if cache_key(dn) is False: + if cache_key(dn, mode='rpm') is False: if 'tried' not in dn: log(dn, 'No cache_key, so skipping compose') dn['tried'] = True @@ -334,7 +334,7 @@ def get_remote_rpm(dn, pkgfilename): def get_cache_pkgfilename(pkgname, dn): - return "{}.{}.rpm".format(pkgname, cache_key(dn)) + return "{}.{}.rpm".format(pkgname, cache_key(dn, mode='rpm')) def all_rpms_cached(system, dn): |