summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2018-01-18 12:58:22 +0000
committerBen Brown <ben.brown@codethink.co.uk>2018-02-15 11:30:10 +0000
commit30709ae2050494125407686e755546b62315981a (patch)
tree403c02e328b14dc5e35dad67421e0903c478290c
parent726a45e4ba6a6f93aa9de332828f9247bf3cd5b4 (diff)
downloadybd-30709ae2050494125407686e755546b62315981a.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.py35
-rw-r--r--ybd/rpm.py4
2 files changed, 22 insertions, 17 deletions
diff --git a/ybd/cache.py b/ybd/cache.py
index b4f5e27..2109f2b 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,11 @@ def hash_factors(dn):
if dn.get('prefix'):
hash_factors['prefix'] = dn['prefix']
+ if artifact_version not in range(0, 10):
+ if artifact_version < 13 or mode == 'rpm':
+ if dn.get('rpm-metadata'):
+ hash_factors['rpm-metadata'] = dn['rpm-metadata']
+
return hash_factors
diff --git a/ybd/rpm.py b/ybd/rpm.py
index 912c748..00c628f 100644
--- a/ybd/rpm.py
+++ b/ybd/rpm.py
@@ -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
@@ -335,7 +335,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):