diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-07-28 15:23:09 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-10-14 14:34:29 +0000 |
commit | b8b8de2b123ff96e6469196934359485bcd06b04 (patch) | |
tree | 2bb774dcaf3db88d6dafb8ab34322b5df4550ce0 /morphlib/morphloader.py | |
parent | 3c59628c80ffe47992bf7347268ca587fc6d368d (diff) | |
download | morph-b8b8de2b123ff96e6469196934359485bcd06b04.tar.gz |
Add support for Baserock definitions version 7
This adds a new 'Defaults' class to represent definitions defaults
The Python 'jsonschema' module is used to validate the contents of the
Defaults file. This module is already included in Baserock 'build' and
'devel' reference systems by way of the 'openstack-common' stratum.
This commit embeds a copy of the JSON-Schema schema for the DEFAULTS
file. I think the canonical location of this schema should be in the
reference definitions.git, for now. In future, the schemas should maybe
have their own repos. Either way, Morph should embed a copy for the time
being so that we are sure the schema matches how Morph expects to parse
the file.
Morph's automated tests are all updated to use definitions version 7.
I removed most of the tests for built-in build systems, because the
built-ins themselves are no longer part of Morph. Only the mechanism for
defining them needs to be tested now.
Change-Id: I65f8f1c967683ef605852bfae5c68518e53f9981
Diffstat (limited to 'morphlib/morphloader.py')
-rw-r--r-- | morphlib/morphloader.py | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index f85c5d4d..ba48b778 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -109,6 +109,13 @@ class UnknownArchitectureError(MorphologyValidationError): % (arch, morph_filename)) +class UnknownBuildSystemError(MorphologyValidationError): + + def __init__(self, build_system, morph_filename): + self.msg = ('Undefined build system %s in morphology %s' + % (build_system, morph_filename)) + + class NoStratumBuildDependenciesError(MorphologyValidationError): def __init__(self, stratum_name, morph_filename): @@ -404,8 +411,12 @@ class MorphologyLoader(object): } def __init__(self, - lookup_build_system=morphlib.buildsystem.lookup_build_system): - self._lookup_build_system = lookup_build_system + predefined_build_systems={}): + self._predefined_build_systems = predefined_build_systems.copy() + + if 'manual' not in self._predefined_build_systems: + self._predefined_build_systems['manual'] = \ + morphlib.buildsystem.ManualBuildSystem() def parse_morphology_text(self, text, morph_filename): '''Parse a textual morphology. @@ -811,10 +822,12 @@ class MorphologyLoader(object): if morph['max-jobs'] is not None: morph['max-jobs'] = int(morph['max-jobs']) - def _unset_chunk_defaults(self, morph): # pragma: no cover + def _unset_chunk_defaults(self, morph): # pragma: no cover + # This is only used by the deprecated branch-and-merge plugin, and + # probably doesn't work correctly for definitions V7 and newer. default_bs = self._static_defaults['chunk']['build-system'] - bs = self._lookup_build_system( - morph.get('build-system', default_bs)) + bs_name = morph.get('build-system', default_bs) + bs = self.lookup_build_system(bs_name) for key in self._static_defaults['chunk']: if key not in morph: continue if 'commands' not in key: continue @@ -823,11 +836,19 @@ class MorphologyLoader(object): if morph[key] == default_value: del morph[key] + def lookup_build_system(self, name): + return self._predefined_build_systems[name] + def set_commands(self, morph): - default = self._static_defaults['chunk']['build-system'] - bs = self._lookup_build_system( - morph.get('build-system', default)) if morph['kind'] == 'chunk': + default = self._static_defaults['chunk']['build-system'] + bs_name = morph.get('build-system', default) + + try: + bs = self.lookup_build_system(bs_name) + except KeyError: + raise UnknownBuildSystemError(bs_name, morph['name']) + for key in self._static_defaults['chunk']: if 'commands' not in key: continue if key not in morph: |