diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-02-21 17:28:51 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-02-21 17:55:07 +0900 |
commit | 8531759bdbc1cd7ad5c206c9a9cbe25692d46dad (patch) | |
tree | c2409c694800382862ff89a90e18e49a3362a034 | |
parent | 84acd9ab40b8529b3573e800873ef90a4d45bd9a (diff) | |
download | ybd-8531759bdbc1cd7ad5c206c9a9cbe25692d46dad.tar.gz |
Store the original 'ref' and restore it before savingtristan-build-sha-if-exists
In case it was overridden by the 'sha' field for the purpose of
building, we still want to export the original 'ref' field in
the saved target.yml
-rw-r--r-- | ybd/config/defaults.conf | 1 | ||||
-rw-r--r-- | ybd/morphs.py | 13 | ||||
-rw-r--r-- | ybd/pots.py | 12 |
3 files changed, 20 insertions, 6 deletions
diff --git a/ybd/config/defaults.conf b/ybd/config/defaults.conf index 8a20f31..597eed7 100644 --- a/ybd/config/defaults.conf +++ b/ybd/config/defaults.conf @@ -13,6 +13,7 @@ morph-fields: ['arch', 'max-jobs', 'morph', 'name', + 'orig_ref', 'path', 'prefix', 'products', diff --git a/ybd/morphs.py b/ybd/morphs.py index 605af0b..a9aa035 100644 --- a/ybd/morphs.py +++ b/ybd/morphs.py @@ -196,16 +196,19 @@ class Morphs(object): dn = self._data.get(new_def['path']) if dn: - if dn.get('sha'): - if len(dn['sha']) != 40: - log(new_def, 'ERROR: invalid sha:', dn['sha'], exit=True) - dn['ref'] = dn['sha'] - if (dn.get('ref') is None or new_def.get('ref') is None): for key in new_def: if key is not 'name': dn[key] = new_def[key] + # If a sha was specified, we want to build it instead of the ref + # but preserve the ref in the output <target>.yml file. + if dn.get('sha'): + if len(dn['sha']) != 40: + log(new_def, 'ERROR: invalid sha:', dn['sha'], exit=True) + dn['orig_ref'] = dn['ref'] + dn['ref'] = dn['sha'] + if dn['name'] != new_def['name']: log(new_def, 'WARNING: %s also named as' % new_def['name'], dn['name'], exit=exit) diff --git a/ybd/pots.py b/ybd/pots.py index ec11d94..a66686e 100644 --- a/ybd/pots.py +++ b/ybd/pots.py @@ -16,6 +16,7 @@ import os import yaml +import copy from app import config, log from defaults import Defaults from morphs import Morphs @@ -62,8 +63,17 @@ class Pots(object): return self._data.get(dn.get('path', dn.keys()[0])) def save(self, filename): + + # Make a copy, restore any refs which may have been overridden + # with the sha field while building. + data = copy.deepcopy(self._data) + for key, value in data.items(): + if value.get('orig_ref') is not None: + value['ref'] = value['orig_ref'] + del value['orig_ref'] + with open(filename, 'w') as f: - f.write(yaml.dump(self._data, default_flow_style=False, + f.write(yaml.dump(data, default_flow_style=False, Dumper=ExplicitDumper)) log('CHECK', 'Saved yaml definitions at', filename) |