From b581801d265154ee94b1bc51eb986e4497b536e4 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 09:06:50 +0000 Subject: cachedrepo: Remove unused load_morphology method --- morphlib/cachedrepo.py | 9 --------- morphlib/cachedrepo_tests.py | 4 ---- 2 files changed, 13 deletions(-) diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index 996b42f7..88ceed48 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -195,15 +195,6 @@ class CachedRepo(object): self._checkout_ref(ref, target_dir) - def load_morphology(self, ref, name): - '''Loads a morphology from a given ref''' - - if not morphlib.git.is_valid_sha1(ref): - ref = self._rev_parse(ref) - text = self.cat(ref, '%s.morph' % name) - morphology = morphlib.morph2.Morphology(text) - return morphology - def ls_tree(self, ref): '''Return file names found in root tree. Does not recurse to subtrees. diff --git a/morphlib/cachedrepo_tests.py b/morphlib/cachedrepo_tests.py index 74c16591..d3ae331a 100644 --- a/morphlib/cachedrepo_tests.py +++ b/morphlib/cachedrepo_tests.py @@ -219,10 +219,6 @@ class CachedRepoTests(unittest.TestCase): morph_filename = os.path.join(unpack_dir, 'foo.morph') self.assertTrue(os.path.exists(morph_filename)) - def test_load_morphology_from_existing_ref(self): - morph = self.repo.load_morphology('master', 'foo') - self.assertTrue(morph['name'] == 'foo') - def test_ls_tree_in_existing_ref(self): data = self.repo.ls_tree('e28a23812eadf2fce6583b8819b9c5dbd36b9fb9') self.assertEqual(data, ['foo.morph']) -- cgit v1.2.1 From 9afaefb4c84ca1623d8eb9766f0d6031d2ed2f83 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 09:09:51 +0000 Subject: show-dependencies: Use sanitise_morphology_path instead of stripping `.morph` --- morphlib/plugins/show_dependencies_plugin.py | 4 ++-- tests/show-dependencies.stdout | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/morphlib/plugins/show_dependencies_plugin.py b/morphlib/plugins/show_dependencies_plugin.py index c59cf507..3a1cb7ad 100644 --- a/morphlib/plugins/show_dependencies_plugin.py +++ b/morphlib/plugins/show_dependencies_plugin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2013 Codethink Limited +# Copyright (C) 2012-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -65,7 +65,7 @@ class ShowDependenciesPlugin(cliapp.Plugin): # traverse the morphs to list all the sources for repo, ref, filename in self.app.itertriplets(args): - morph = filename[:-len('.morph')] + morph = morphlib.util.sanitise_morphology_path(filename) self.app.output.write('dependency graph for %s|%s|%s:\n' % (repo, ref, morph)) diff --git a/tests/show-dependencies.stdout b/tests/show-dependencies.stdout index 5d6a6e58..91d289a9 100644 --- a/tests/show-dependencies.stdout +++ b/tests/show-dependencies.stdout @@ -1,4 +1,4 @@ -dependency graph for test-repo|master|xfce-system: +dependency graph for test-repo|master|xfce-system.morph: test-repo|master|xfce-system.morph|xfce-system-rootfs -> test-repo|master|xfce-core.morph|xfce-core-devel -> test-repo|master|xfce-core.morph|xfce-core-runtime -- cgit v1.2.1 From e15c4fd713ee4222ebd0a0c1740e6fb91e15cbad Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 08:32:46 +0000 Subject: morphset: Don't expect to be able to find `morph` or `name` Currently, morphloader sets the morph field in chunk specs by default. A later commit will remove this behaviour, so morphset needs to stop expecting the `morph` field to exist in morphology specs. However, stratum specs don't have a `name` field so we can't expect to be able to find that either. --- morphlib/morphset.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/morphlib/morphset.py b/morphlib/morphset.py index fa525973..bf061f94 100644 --- a/morphlib/morphset.py +++ b/morphlib/morphset.py @@ -127,7 +127,8 @@ class MorphologySet(object): specs = m[kind] for spec in specs: if cb_filter(m, kind, spec): - fn = morphlib.util.sanitise_morphology_path(spec['morph']) + fn = morphlib.util.sanitise_morphology_path( + spec['morph'] if 'morph' in spec else spec['name']) orig_spec = (spec.get('repo'), spec.get('ref'), fn) dirtied = cb_process(m, kind, spec) if dirtied: @@ -148,7 +149,8 @@ class MorphologySet(object): if m.ref != spec.get('ref'): m.ref = spec.get('ref') m.dirty = True - file = morphlib.util.sanitise_morphology_path(spec['morph']) + file = morphlib.util.sanitise_morphology_path( + spec['morph'] if 'morph' in spec else spec['name']) assert (m.filename == file or m.repo_url == spec.get('repo')), \ 'Moving morphologies is not supported.' @@ -162,7 +164,7 @@ class MorphologySet(object): ''' def wanted_spec(m, kind, spec): - spec_name = spec.get('name', spec['morph']) + spec_name = spec['name'] if 'name' in spec else spec['morph'] return (spec.get('repo') == repo_url and spec.get('ref') == orig_ref and spec_name == morph_name) -- cgit v1.2.1 From 95c5f93d554883fdedaeb3e111e1be9f88e0045c Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 08:36:34 +0000 Subject: morphloader: Add and remove some default values This commit stops morphloader setting the `morph` field in chunk specs, and also makes it set defaults for the prefix and build-mode fields. Not setting the `morph` field is necessary as its presence in chunk specs is used by `traverse_morphs` to mean that the morphology file is in the definitions repository, not the chunk source repository. If we set a default value here, we end up looking for files which do not exist. --- morphlib/morphloader.py | 21 ++++++++++++++------- morphlib/morphloader_tests.py | 12 +++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index 21e10827..0249bbae 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -354,6 +354,8 @@ class MorphologyLoader(object): 'products': [], 'max-jobs': None, 'build-system': 'manual', + 'build-mode': 'staging', + 'prefix': '/usr', }, 'stratum': { 'chunks': [], @@ -438,9 +440,6 @@ class MorphologyLoader(object): self._require_field('kind', morph) # The rest of the validation is dependent on the kind. - - # FIXME: move validation of clusters from morph2 to - # here, and use morphload to load the morphology kind = morph['kind'] if kind not in ('system', 'stratum', 'chunk', 'cluster'): raise UnknownKindError(morph['kind'], morph.filename) @@ -731,16 +730,24 @@ class MorphologyLoader(object): for spec in morph['chunks']: if 'repo' not in spec: spec['repo'] = spec['name'] - if 'morph' not in spec: - spec['morph'] = spec['name'] + if 'build-mode' not in spec: + spec['build-mode'] = \ + self._static_defaults['chunk']['build-mode'] + if 'prefix' not in spec: + spec['prefix'] = \ + self._static_defaults['chunk']['prefix'] self._set_stratum_specs_defaults(morph, 'build-depends') def _unset_stratum_defaults(self, morph): for spec in morph['chunks']: if 'repo' in spec and spec['repo'] == spec['name']: del spec['repo'] - if 'morph' in spec and spec['morph'] == spec['name']: - del spec['morph'] + if 'build-mode' in spec and spec['build-mode'] == \ + self._static_defaults['chunk']['build-mode']: + del spec['build-mode'] + if 'prefix' in spec and spec['prefix'] == \ + self._static_defaults['chunk']['prefix']: + del spec['prefix'] self._unset_stratum_specs_defaults(morph, 'strata') def _set_chunk_defaults(self, morph): diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index f4d2f9b6..738f1c32 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -569,6 +569,7 @@ build-system: dummy 'name': 'foo', 'description': '', 'build-system': 'manual', + 'build-mode': 'staging', 'configure-commands': [], 'pre-configure-commands': [], @@ -589,6 +590,7 @@ build-system: dummy 'products': [], 'devices': [], 'max-jobs': None, + 'prefix': '/usr', }) def test_unsets_defaults_for_chunks(self): @@ -637,6 +639,7 @@ build-system: dummy "morph": "bar", 'build-mode': 'bootstrap', 'build-depends': [], + 'prefix': '/usr', }, ], 'products': [], @@ -650,8 +653,9 @@ build-system: dummy { 'name': 'bar', "ref": "bar", - 'build-mode': 'bootstrap', + 'build-mode': 'staging', 'build-depends': [], + 'prefix': '/usr', }, ], } @@ -754,7 +758,7 @@ build-system: dummy [{'morph': 'foo'}, {'morph': 'bar'}]) - def test_sets_stratum_chunks_repo_and_morph_from_name(self): + def test_sets_stratum_chunks_repo_from_name(self): m = morphlib.morph3.Morphology( { "name": "foo", @@ -771,9 +775,8 @@ build-system: dummy self.loader.set_defaults(m) self.loader.validate(m) self.assertEqual(m['chunks'][0]['repo'], 'le-chunk') - self.assertEqual(m['chunks'][0]['morph'], 'le-chunk') - def test_collapses_stratum_chunks_repo_and_morph_from_name(self): + def test_collapses_stratum_chunks_repo_from_name(self): m = morphlib.morph3.Morphology( { "name": "foo", @@ -791,7 +794,6 @@ build-system: dummy self.loader.unset_defaults(m) self.assertTrue('repo' not in m['chunks'][0]) - self.assertTrue('morph' not in m['chunks'][0]) def test_convertes_max_jobs_to_an_integer(self): m = morphlib.morph3.Morphology( -- cgit v1.2.1 From 9e35ea90a1f2c41c3808633e76930f86da6336e5 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 07:59:02 +0000 Subject: morphloader: Get commands when loading morphology Rather than having a `get_commands` method to obtain missing commands from the build system when they are needed, get the commands when loading a morphology. --- morphlib/builder2.py | 2 +- morphlib/cachekeycomputer.py | 2 +- morphlib/morphloader.py | 11 +++++++++++ morphlib/plugins/cross-bootstrap_plugin.py | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/morphlib/builder2.py b/morphlib/builder2.py index d739dc13..c1a49221 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -405,7 +405,7 @@ class ChunkBuilder(BuilderBase): for step, in_parallel in steps: with self.build_watch(step): key = '%s-commands' % step - cmds = m.get_commands(key) + cmds = m[key] if cmds: with open(logfilepath, 'a') as log: self.app.status(msg='Running %(key)s', key=key) diff --git a/morphlib/cachekeycomputer.py b/morphlib/cachekeycomputer.py index b124b789..7cbce730 100644 --- a/morphlib/cachekeycomputer.py +++ b/morphlib/cachekeycomputer.py @@ -114,7 +114,7 @@ class CacheKeyComputer(object): for prefix in ('pre-', '', 'post-'): for cmdtype in ('configure', 'build', 'test', 'install'): cmd_field = prefix + cmdtype + '-commands' - keys[cmd_field] = morphology.get_commands(cmd_field) + keys[cmd_field] = morphology[cmd_field] keys['devices'] = morphology.get('devices') keys['max-jobs'] = morphology.get('max-jobs') keys['system-integration'] = morphology.get('system-integration', diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index 0249bbae..d06c06dc 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -406,6 +406,7 @@ class MorphologyLoader(object): m = self.parse_morphology_text(string, filename) m.filename = filename self.validate(m) + self.set_commands(m) self.set_defaults(m) return m @@ -754,3 +755,13 @@ class MorphologyLoader(object): if morph['max-jobs'] is not None: morph['max-jobs'] = int(morph['max-jobs']) + def set_commands(self, morph): + if morph['kind'] == 'chunk': + for key in self._static_defaults['chunk']: + if 'commands' not in key: continue + if key not in morph: + attr = '_'.join(key.split('-')) + default = self._static_defaults['chunk']['build-system'] + bs = morphlib.buildsystem.lookup_build_system( + morph.get('build-system', default)) + morph[key] = getattr(bs, attr) diff --git a/morphlib/plugins/cross-bootstrap_plugin.py b/morphlib/plugins/cross-bootstrap_plugin.py index cd8e355e..0c3e3a4a 100644 --- a/morphlib/plugins/cross-bootstrap_plugin.py +++ b/morphlib/plugins/cross-bootstrap_plugin.py @@ -182,7 +182,7 @@ class BootstrapSystemBuilder(morphlib.builder2.BuilderBase): for step, in_parallel in steps: key = '%s-commands' % step - cmds = m.get_commands(key) + cmds = m[key] for cmd in cmds: f.write('(') if in_parallel: -- cgit v1.2.1 From 4984492dc11888ae35452c437d666cb64dce1a87 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 09:00:34 +0000 Subject: morphologyfactory: Use morphloader not morph2 This commit reworks morphologyfactory to stop using morph2. It removes the validation that is already handled by morphloader, and uses morphloader to load the morphology rather than using morph2. The unit tests are also changed to turn the example morphologies into YAML, and also to check for the correct exceptions. --- morphlib/morphologyfactory.py | 76 +---------------- morphlib/morphologyfactory_tests.py | 165 ++++++++++++++++-------------------- 2 files changed, 75 insertions(+), 166 deletions(-) diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index cd1972be..fd78c94f 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -37,31 +37,6 @@ class NotcachedError(MorphologyFactoryError): "remote cache specified" % repo_name) -class StratumError(MorphologyFactoryError): - pass - - -class NoChunkBuildDependsError(StratumError): - def __init__(self, stratum, chunk): - StratumError.__init__( - self, 'No build dependencies in stratum %s for chunk %s ' - '(build-depends is a mandatory field)' % (stratum, chunk)) - - -class EmptyStratumError(StratumError): - - def __init__(self, stratum): - cliapp.AppException.__init__(self, - "Stratum %s is empty (has no dependencies)" % stratum) - - -class NoStratumBuildDependsError(StratumError): - def __init__(self, stratum): - StratumError.__init__( - self, 'Stratum %s has no build-dependencies listed ' - 'and has no bootstrap chunks.' % stratum) - - class MorphologyFactory(object): '''A way of creating morphologies which will provide a default''' @@ -112,16 +87,8 @@ class MorphologyFactory(object): def get_morphology(self, reponame, sha1, filename): morph_name, text = self._get_morphology_text(reponame, sha1, filename) - try: - morphology = morphlib.morph2.Morphology(text) - except morphlib.YAMLError as e: # pragma: no cover - raise morphlib.Error("Error parsing %s: %s" % - (filename, str(e))) - - if morph_name != morphology['name']: - raise morphlib.Error( - "Name %s does not match basename of morphology file %s" % - (morphology['name'], filename)) + loader = morphlib.morphloader.MorphologyLoader() + morphology = loader.load_from_string(text) method_name = '_check_and_tweak_%s' % morphology['kind'] if hasattr(self, method_name): @@ -133,54 +100,17 @@ class MorphologyFactory(object): def _check_and_tweak_system(self, morphology, reponame, sha1, filename): '''Check and tweak a system morphology.''' - if morphology['arch'] is None: # pragma: no cover - raise morphlib.Error('No arch specified in system %s ' - '(arch is a mandatory field)' % - filename) - - if morphology['arch'] == 'armv7': - morphology._dict['arch'] = 'armv7l' - - if morphology['arch'] not in morphlib.valid_archs: - raise morphlib.Error('Unknown arch %s. This version of Morph ' - 'supports the following architectures: %s' % - (morphology['arch'], - ', '.join(morphlib.valid_archs))) - name = morphology['name'] morphology.builds_artifacts = [name + '-rootfs'] morphology.needs_artifact_metadata_cached = False - morphlib.morphloader.MorphologyLoader._validate_stratum_specs_fields( - morphology, 'strata') - morphlib.morphloader.MorphologyLoader._set_stratum_specs_defaults( - morphology, 'strata') - def _check_and_tweak_stratum(self, morphology, reponame, sha1, filename): '''Check and tweak a stratum morphology.''' - if len(morphology['chunks']) == 0: - raise EmptyStratumError(morphology['name']) - - for source in morphology['chunks']: - if source.get('build-depends', None) is None: - name = source.get('name', source.get('repo', 'unknown')) - raise NoChunkBuildDependsError(filename, name) - - if (len(morphology['build-depends'] or []) == 0 and - not any(c.get('build-mode') in ('bootstrap', 'test') - for c in morphology['chunks'])): - raise NoStratumBuildDependsError(filename) - morphology.builds_artifacts = [morphology['name']] morphology.needs_artifact_metadata_cached = True - morphlib.morphloader.MorphologyLoader._validate_stratum_specs_fields( - morphology, 'build-depends') - morphlib.morphloader.MorphologyLoader._set_stratum_specs_defaults( - morphology, 'build-depends') - def _check_and_tweak_chunk(self, morphology, reponame, sha1, filename): '''Check and tweak a chunk morphology.''' @@ -191,5 +121,3 @@ class MorphologyFactory(object): morphology.builds_artifacts = [morphology['name']] morphology.needs_artifact_metadata_cached = False - - morphlib.morphloader.MorphologyLoader._validate_chunk(morphology) diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index 47bf3153..347d93f7 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -17,7 +17,6 @@ import unittest import morphlib -from morphlib.morph2 import Morphology from morphlib.morphologyfactory import (MorphologyFactory, MorphologyNotFoundError, NotcachedError) @@ -41,94 +40,76 @@ class FakeRemoteRepoCache(object): class FakeLocalRepo(object): morphologies = { - 'chunk.morph': '''{ - "name": "chunk", - "kind": "chunk", - "build-system": "bar" - }''', - 'chunk-split.morph': '''{ - "name": "chunk-split", - "kind": "chunk", - "build-system": "bar", - "products": [ - { - "artifact": "chunk-split-runtime", - "include": [] - }, - { - "artifact": "chunk-split-devel", - "include": [] - } - ] - }''', - 'stratum.morph': '''{ - "name": "stratum", - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "test:repo", - "ref": "sha1", - "build-mode": "bootstrap", - "build-depends": [] - } - ] - }''', - 'stratum-no-chunk-bdeps.morph': '''{ - "name": "stratum-no-chunk-bdeps", - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "test:repo", - "ref": "sha1", - "build-mode": "bootstrap" - } - ] - }''', - 'stratum-no-bdeps-no-bootstrap.morph': '''{ - "name": "stratum-no-bdeps-no-bootstrap", - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "test:repo", - "ref": "sha1", - "build-depends": [] - } - ] - }''', - 'stratum-bdeps-no-bootstrap.morph': '''{ - "name": "stratum-bdeps-no-bootstrap", - "kind": "stratum", - "build-depends": [ - { - "morph": "stratum" - } - ], - "chunks": [ - { - "name": "chunk", - "repo": "test:repo", - "ref": "sha1", - "build-depends": [] - } - ] - }''', - 'stratum-empty.morph': '''{ - "name": "stratum-empty", - "kind": "stratum" - }''', - 'system.morph': '''{ - "name": "system", - "kind": "system", - "arch": "%(arch)s" - }''', - 'parse-error.morph': '''{ "name"''', - 'name-mismatch.morph': '''{ - "name": "fred", - "kind": "stratum" - }''', + 'chunk.morph': ''' + name: chunk + kind: chunk + build-system: bar + ''', + 'chunk-split.morph': ''' + name: chunk-split + kind: chunk + build-system: bar + products: + - artifact: chunk-split-runtime + include: [] + - artifact: chunk-split-devel + include: [] + ''', + 'stratum.morph': ''' + name: stratum + kind: stratum + chunks: + - name: chunk + repo: test:repo + ref: sha1 + build-mode: bootstrap + build-depends: [] + ''', + 'stratum-no-chunk-bdeps.morph': ''' + name: stratum-no-chunk-bdeps + kind: stratum + chunks: + - name: chunk + repo: test:repo + ref: sha1 + build-mode: bootstrap + ''', + 'stratum-no-bdeps-no-bootstrap.morph': ''' + name: stratum-no-bdeps-no-bootstrap + kind: stratum + chunks: + - name: chunk + repo: test:repo + ref: sha1 + build-depends: [] + ''', + 'stratum-bdeps-no-bootstrap.morph': ''' + name: stratum-bdeps-no-bootstrap + kind: stratum + build-depends: + - morph: stratum + chunks: + - name: chunk + repo: test:repo + ref: sha1 + build-depends: [] + ''', + 'stratum-empty.morph': ''' + name: stratum-empty + kind: stratum + ''', + 'system.morph': ''' + name: system + kind: system + arch: %(arch)s + strata: + - morph: stratum + ''', + 'parse-error.morph': ''' name''', + 'name-mismatch.morph': ''' + name: fred + kind: stratum + ''', } def __init__(self): @@ -313,13 +294,13 @@ class MorphologyFactoryTests(unittest.TestCase): 'reponame', 'sha1', 'parse-error.morph') def test_fails_on_no_chunk_bdeps(self): - self.assertRaises(morphlib.morphologyfactory.NoChunkBuildDependsError, + self.assertRaises(morphlib.morphloader.NoBuildDependenciesError, self.mf.get_morphology, 'reponame', 'sha1', 'stratum-no-chunk-bdeps.morph') def test_fails_on_no_bdeps_or_bootstrap(self): self.assertRaises( - morphlib.morphologyfactory.NoStratumBuildDependsError, + morphlib.morphloader.NoStratumBuildDependenciesError, self.mf.get_morphology, 'reponame', 'sha1', 'stratum-no-bdeps-no-bootstrap.morph') @@ -330,6 +311,6 @@ class MorphologyFactoryTests(unittest.TestCase): def test_fails_on_empty_stratum(self): self.assertRaises( - morphlib.morphologyfactory.EmptyStratumError, + morphlib.morphloader.EmptyStratumError, self.mf.get_morphology, 'reponame', 'sha1', 'stratum-empty.morph') -- cgit v1.2.1 From 39a0ad8d31d6a39bfa607187b1d76478ccbe2513 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 10:20:25 +0000 Subject: buildsystem: Generate a Morphology not text Rather than generating the text of a morphology which is later loaded, generate a Morphology object and return that. --- morphlib/buildsystem.py | 19 ++++++++----------- morphlib/buildsystem_tests.py | 8 ++++---- morphlib/morphologyfactory.py | 24 +++++++++++++----------- morphlib/morphologyfactory_tests.py | 8 ++++---- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/morphlib/buildsystem.py b/morphlib/buildsystem.py index 90cc15c2..fb99e70e 100644 --- a/morphlib/buildsystem.py +++ b/morphlib/buildsystem.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2013 Codethink Limited +# Copyright (C) 2012-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,6 +16,8 @@ import os +import morphlib + class BuildSystem(object): @@ -49,19 +51,14 @@ class BuildSystem(object): key = '_'.join(key.split('-')) return getattr(self, key) - def get_morphology_text(self, name): + def get_morphology(self, name): '''Return the text of an autodetected chunk morphology.''' - return ''' - { - "name": "%(name)s", - "kind": "chunk", - "build-system": "%(bs)s" - } - ''' % { + return morphlib.morphology.Morphology({ 'name': name, - 'bs': self.name, - } + 'kind': 'chunk', + 'build-system': self.name, + }) def used_by_project(self, file_list): '''Does a project use this build system? diff --git a/morphlib/buildsystem_tests.py b/morphlib/buildsystem_tests.py index 3171366b..56ba64d7 100644 --- a/morphlib/buildsystem_tests.py +++ b/morphlib/buildsystem_tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2013 Codethink Limited +# Copyright (C) 2012-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -49,10 +49,10 @@ class BuildSystemTests(unittest.TestCase): def test_has_install_commands(self): self.assertEqual(self.bs['install-commands'], []) - def test_returns_morphology_text(self): + def test_returns_morphology(self): self.bs.name = 'fake' - text = self.bs.get_morphology_text('foobar') - self.assertTrue(type(text) in (str, unicode)) + morph = self.bs.get_morphology('foobar') + self.assertTrue(morph.__class__.__name__ == 'Morphology') class ManualBuildSystemTests(unittest.TestCase): diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index fd78c94f..1a8e374e 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -50,16 +50,17 @@ class MorphologyFactory(object): if self._app is not None: self._app.status(*args, **kwargs) - def _get_morphology_text(self, reponame, sha1, filename): + def _load_morphology(self, reponame, sha1, filename): morph_name = os.path.splitext(os.path.basename(filename))[0] + loader = morphlib.morphloader.MorphologyLoader() if self._lrc.has_repo(reponame): self.status(msg="Looking for %s in local repo cache" % filename, chatty=True) try: repo = self._lrc.get_repo(reponame) - text = repo.cat(sha1, filename) + morph = loader.load_from_string(repo.cat(sha1, filename)) except IOError: - text = None + morph = None file_list = repo.ls_tree(sha1) elif self._rrc is not None: self.status(msg="Retrieving %(reponame)s %(sha1)s %(filename)s" @@ -68,27 +69,28 @@ class MorphologyFactory(object): chatty=True) try: text = self._rrc.cat_file(reponame, sha1, filename) + morph = loader.load_from_string(text) except morphlib.remoterepocache.CatFileError: - text = None + morph = None file_list = self._rrc.ls_tree(reponame, sha1) else: raise NotcachedError(reponame) - if text is None: + if morph is None: self.status(msg="File %s doesn't exist: attempting to infer " "chunk morph from repo's build system" % filename, chatty=True) bs = morphlib.buildsystem.detect_build_system(file_list) if bs is None: raise MorphologyNotFoundError(filename) - text = bs.get_morphology_text(morph_name) - return morph_name, text + morph = bs.get_morphology(morph_name) + loader.validate(morph) + loader.set_commands(morph) + loader.set_defaults(morph) + return morph def get_morphology(self, reponame, sha1, filename): - morph_name, text = self._get_morphology_text(reponame, sha1, filename) - - loader = morphlib.morphloader.MorphologyLoader() - morphology = loader.load_from_string(text) + morphology = self._load_morphology(reponame, sha1, filename) method_name = '_check_and_tweak_%s' % morphology['kind'] if hasattr(self, method_name): diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index 347d93f7..0b3253da 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -30,7 +30,7 @@ class FakeRemoteRepoCache(object): return '''{ "name": "%s", "kind": "chunk", - "build-system": "bar" + "build-system": "dummy" }''' % filename[:-len('.morph')] return 'text' @@ -43,12 +43,12 @@ class FakeLocalRepo(object): 'chunk.morph': ''' name: chunk kind: chunk - build-system: bar + build-system: dummy ''', 'chunk-split.morph': ''' name: chunk-split kind: chunk - build-system: bar + build-system: dummy products: - artifact: chunk-split-runtime include: [] @@ -125,7 +125,7 @@ class FakeLocalRepo(object): return '''{ "name": "%s", "kind": "chunk", - "build-system": "bar" + "build-system": "dummy" }''' % filename[:-len('.morph')] return 'text' -- cgit v1.2.1 From 0710a1529a7af7e33179c71a30d362dd46281d3f Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 09:58:59 +0000 Subject: unittests: Make the unittests use morphloader This commit removes all use of morph2 from the unittests, replacing it with morphloader/morph3. It also converts the test morphologies to YAML. --- morphlib/artifact_tests.py | 34 ++-- morphlib/artifactresolver_tests.py | 322 ++++++++++++++++------------------ morphlib/cachekeycomputer_tests.py | 118 ++++++------- morphlib/localartifactcache_tests.py | 30 ++-- morphlib/remoteartifactcache_tests.py | 36 ++-- morphlib/source_tests.py | 11 +- 6 files changed, 254 insertions(+), 297 deletions(-) diff --git a/morphlib/artifact_tests.py b/morphlib/artifact_tests.py index d4b15cba..62b1bfb9 100644 --- a/morphlib/artifact_tests.py +++ b/morphlib/artifact_tests.py @@ -23,24 +23,22 @@ import morphlib class ArtifactTests(unittest.TestCase): def setUp(self): - morph = morphlib.morph2.Morphology( - ''' - { - "name": "chunk", - "kind": "chunk", - "chunks": { - "chunk-runtime": [ - "usr/bin", - "usr/sbin", - "usr/lib", - "usr/libexec" - ], - "chunk-devel": [ - "usr/include" - ] - } - } - ''') + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( + ''' + name: chunk + kind: chunk + products: + - artifact: chunk-runtime + include: + - usr/bin + - usr/sbin + - usr/lib + - usr/libexec + - artifact: chunk-devel + include: + - usr/include + ''') self.source = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') self.artifact_name = 'chunk-runtime' diff --git a/morphlib/artifactresolver_tests.py b/morphlib/artifactresolver_tests.py index 6f62b4d1..96f7ced8 100644 --- a/morphlib/artifactresolver_tests.py +++ b/morphlib/artifactresolver_tests.py @@ -15,84 +15,68 @@ import itertools -import json import unittest +import yaml import morphlib -class FakeChunkMorphology(morphlib.morph2.Morphology): - - def __init__(self, name, artifact_names=[]): - assert(isinstance(artifact_names, list)) - - if artifact_names: - # fake a list of artifacts - artifacts = [] - for artifact_name in artifact_names: - artifacts.append({'artifact': artifact_name, - 'include': artifact_name}) - text = json.dumps({ - "name": name, - "kind": "chunk", - "products": artifacts - }) - self.builds_artifacts = artifact_names - else: - text = (''' - { - "name": "%s", - "kind": "chunk" - } - ''' % name) - self.builds_artifacts = [name] - morphlib.morph2.Morphology.__init__(self, text) - - -class FakeStratumMorphology(morphlib.morph2.Morphology): - - def __init__(self, name, chunks=[], build_depends=[]): - assert(isinstance(chunks, list)) - assert(isinstance(build_depends, list)) - - chunks_list = [] - for source_name, morph, repo, ref in chunks: - chunks_list.append({ - 'name': source_name, - 'morph': morph, - 'repo': repo, - 'ref': ref, - 'build-depends': [], - }) - build_depends_list = [] - for morph, repo, ref in build_depends: - build_depends_list.append({ - 'morph': morph, - 'repo': repo, - 'ref': ref - }) - if chunks_list: - text = (''' - { - "name": "%s", - "kind": "stratum", - "build-depends": %s, - "chunks": %s - } - ''' % (name, - json.dumps(build_depends_list), - json.dumps(chunks_list))) - else: - text = (''' - { - "name": "%s", - "kind": "stratum", - "build-depends": %s - } - ''' % (name, - json.dumps(build_depends_list))) - self.builds_artifacts = [name] - morphlib.morph2.Morphology.__init__(self, text) +def get_chunk_morphology(name, artifact_names=[]): + assert(isinstance(artifact_names, list)) + + if artifact_names: + # fake a list of artifacts + artifacts = [] + for artifact_name in artifact_names: + artifacts.append({'artifact': artifact_name, + 'include': [artifact_name]}) + text = yaml.dump({"name": name, + "kind": "chunk", + "products": artifacts}, default_flow_style=False) + builds_artifacts = artifact_names + else: + text = yaml.dump({'name': name, + 'kind': 'chunk'}, default_flow_style=False) + builds_artifacts = [name] + + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string(text) + morph.builds_artifacts = builds_artifacts + return morph + +def get_stratum_morphology(name, chunks=[], build_depends=[]): + assert(isinstance(chunks, list)) + assert(isinstance(build_depends, list)) + + chunks_list = [] + for source_name, morph, repo, ref in chunks: + chunks_list.append({ + 'name': source_name, + 'morph': morph, + 'repo': repo, + 'ref': ref, + 'build-depends': [], + }) + build_depends_list = [] + for morph in build_depends: + build_depends_list.append({ + 'morph': morph, + }) + if chunks_list: + text = yaml.dump({"name": name, + "kind": "stratum", + "build-depends": build_depends_list, + "chunks": chunks_list,}, default_flow_style=False) + else: + text = yaml.dump({"name": name, + "kind": "stratum", + "build-depends": build_depends_list}, + default_flow_style=False) + + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string(text) + morph.builds_artifacts = [name] + return morph class ArtifactResolverTests(unittest.TestCase): @@ -108,7 +92,7 @@ class ArtifactResolverTests(unittest.TestCase): def test_resolve_single_chunk_with_no_subartifacts(self): pool = morphlib.sourcepool.SourcePool() - morph = FakeChunkMorphology('chunk') + morph = get_chunk_morphology('chunk') source = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') pool.add(source) @@ -127,7 +111,7 @@ class ArtifactResolverTests(unittest.TestCase): def test_resolve_single_chunk_with_one_new_artifact(self): pool = morphlib.sourcepool.SourcePool() - morph = FakeChunkMorphology('chunk', ['chunk-foobar']) + morph = get_chunk_morphology('chunk', ['chunk-foobar']) source = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') pool.add(source) @@ -145,7 +129,7 @@ class ArtifactResolverTests(unittest.TestCase): def test_resolve_single_chunk_with_two_new_artifacts(self): pool = morphlib.sourcepool.SourcePool() - morph = FakeChunkMorphology('chunk', ['chunk-baz', 'chunk-qux']) + morph = get_chunk_morphology('chunk', ['chunk-baz', 'chunk-qux']) source = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') pool.add(source) @@ -165,12 +149,12 @@ class ArtifactResolverTests(unittest.TestCase): def test_resolve_stratum_and_chunk(self): pool = morphlib.sourcepool.SourcePool() - morph = FakeChunkMorphology('chunk') + morph = get_chunk_morphology('chunk') chunk = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') pool.add(chunk) - morph = FakeStratumMorphology( + morph = get_stratum_morphology( 'stratum', chunks=[('chunk', 'chunk', 'repo', 'ref')]) stratum = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph') @@ -199,12 +183,12 @@ class ArtifactResolverTests(unittest.TestCase): def test_resolve_stratum_and_chunk_with_two_new_artifacts(self): pool = morphlib.sourcepool.SourcePool() - morph = FakeChunkMorphology('chunk', ['chunk-foo', 'chunk-bar']) + morph = get_chunk_morphology('chunk', ['chunk-foo', 'chunk-bar']) chunk = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') pool.add(chunk) - morph = FakeStratumMorphology( + morph = get_stratum_morphology( 'stratum', chunks=[ ('chunk', 'chunk', 'repo', 'ref'), @@ -236,51 +220,42 @@ class ArtifactResolverTests(unittest.TestCase): def test_resolving_artifacts_for_a_system_with_two_dependent_strata(self): pool = morphlib.sourcepool.SourcePool() - morph = FakeChunkMorphology('chunk1') + morph = get_chunk_morphology('chunk1') chunk1 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph') pool.add(chunk1) - morph = FakeStratumMorphology( + morph = get_stratum_morphology( 'stratum1', chunks=[('chunk1', 'chunk1', 'repo', 'original/ref')]) stratum1 = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'stratum1.morph') pool.add(stratum1) - morph = morphlib.morph2.Morphology( + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( ''' - { - "name": "system", - "kind": "system", - "strata": [ - { - "repo": "repo", - "ref": "ref", - "morph": "stratum1" - }, - { - "repo": "repo", - "ref": "ref", - "morph": "stratum2" - } - ] - } + name: system + kind: system + arch: testarch + strata: + - morph: stratum1 + - morph: stratum2 ''') morph.builds_artifacts = ['system-rootfs'] system = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'system.morph') pool.add(system) - morph = FakeChunkMorphology('chunk2') + morph = get_chunk_morphology('chunk2') chunk2 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph') pool.add(chunk2) - morph = FakeStratumMorphology( + morph = get_stratum_morphology( 'stratum2', chunks=[('chunk2', 'chunk2', 'repo', 'original/ref')], - build_depends=[('stratum1', 'repo', 'ref')]) + build_depends=['stratum1']) stratum2 = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'stratum2.morph') pool.add(stratum2) @@ -337,52 +312,44 @@ class ArtifactResolverTests(unittest.TestCase): def test_resolving_stratum_with_explicit_chunk_dependencies(self): pool = morphlib.sourcepool.SourcePool() - morph = morphlib.morph2.Morphology( + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( ''' - { - "name": "stratum", - "kind": "stratum", - "chunks": [ - { - "name": "chunk1", - "repo": "repo", - "ref": "original/ref", - "build-depends": [] - }, - { - "name": "chunk2", - "repo": "repo", - "ref": "original/ref", - "build-depends": [] - }, - { - "name": "chunk3", - "repo": "repo", - "ref": "original/ref", - "build-depends": [ - "chunk1", - "chunk2" - ] - } - ] - } + name: stratum + kind: stratum + build-depends: [] + chunks: + - name: chunk1 + repo: repo + ref: original/ref + build-depends: [] + - name: chunk2 + repo: repo + ref: original/ref + build-depends: [] + - name: chunk3 + repo: repo + ref: original/ref + build-depends: + - chunk1 + - chunk2 ''') morph.builds_artifacts = ['stratum'] stratum = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph') pool.add(stratum) - morph = FakeChunkMorphology('chunk1') + morph = get_chunk_morphology('chunk1') chunk1 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph') pool.add(chunk1) - morph = FakeChunkMorphology('chunk2') + morph = get_chunk_morphology('chunk2') chunk2 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph') pool.add(chunk2) - morph = FakeChunkMorphology('chunk3') + morph = get_chunk_morphology('chunk3') chunk3 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk3.morph') pool.add(chunk3) @@ -418,20 +385,33 @@ class ArtifactResolverTests(unittest.TestCase): for c3a in chunk_artifacts[2])) def test_detection_of_mutual_dependency_between_two_strata(self): + loader = morphlib.morphloader.MorphologyLoader() pool = morphlib.sourcepool.SourcePool() - morph = FakeStratumMorphology( + chunk = get_chunk_morphology('chunk1') + chunk1 = morphlib.source.Source( + 'repo', 'original/ref', 'sha1', 'tree', chunk, 'chunk1.morph') + pool.add(chunk1) + + morph = get_stratum_morphology( 'stratum1', - chunks=[], - build_depends=[('stratum2', 'repo', 'original/ref')]) + chunks=[(loader.save_to_string(chunk), 'chunk1.morph', + 'repo', 'original/ref')], + build_depends=['stratum2']) stratum1 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum1.morph') pool.add(stratum1) - morph = FakeStratumMorphology( + chunk = get_chunk_morphology('chunk2') + chunk2 = morphlib.source.Source( + 'repo', 'original/ref', 'sha1', 'tree', chunk, 'chunk2.morph') + pool.add(chunk2) + + morph = get_stratum_morphology( 'stratum2', - chunks=[], - build_depends=[('stratum1', 'repo', 'original/ref')]) + chunks=[(loader.save_to_string(chunk), 'chunk2.morph', + 'repo', 'original/ref')], + build_depends=['stratum1']) stratum2 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum2.morph') pool.add(stratum2) @@ -442,39 +422,34 @@ class ArtifactResolverTests(unittest.TestCase): def test_detection_of_chunk_dependencies_in_invalid_order(self): pool = morphlib.sourcepool.SourcePool() - morph = morphlib.morph2.Morphology( + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( ''' - { - "name": "stratum", - "kind": "stratum", - "chunks": [ - { - "name": "chunk1", - "repo": "repo", - "ref": "original/ref", - "build-depends": [ - "chunk2" - ] - }, - { - "name": "chunk2", - "repo": "repo", - "ref": "original/ref" - } - ] - } + name: stratum + kind: stratum + build-depends: [] + chunks: + - name: chunk1 + repo: repo + ref: original/ref + build-depends: + - chunk2 + - name: chunk2 + repo: repo + ref: original/ref + build-depends: [] ''') morph.builds_artifacts = ['stratum'] stratum = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph') pool.add(stratum) - morph = FakeChunkMorphology('chunk1') + morph = get_chunk_morphology('chunk1') chunk1 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph') pool.add(chunk1) - morph = FakeChunkMorphology('chunk2') + morph = get_chunk_morphology('chunk2') chunk2 = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph') pool.add(chunk2) @@ -485,27 +460,24 @@ class ArtifactResolverTests(unittest.TestCase): def test_detection_of_invalid_build_depends_format(self): pool = morphlib.sourcepool.SourcePool() - morph = morphlib.morph2.Morphology( + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( ''' - { - "name": "stratum", - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "repo", - "ref": "original/ref", - "build-depends": "whatever" - } - ] - } + name: stratum + kind: stratum + build-depends: [] + chunks: + - name: chunk + repo: repo + ref: original/ref + build-depends: whatever ''') morph.builds_artifacts = ['stratum'] stratum = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph') pool.add(stratum) - morph = FakeChunkMorphology('chunk') + morph = get_chunk_morphology('chunk') chunk = morphlib.source.Source( 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk.morph') pool.add(chunk) diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py index 9e18b19d..8558db6d 100644 --- a/morphlib/cachekeycomputer_tests.py +++ b/morphlib/cachekeycomputer_tests.py @@ -32,73 +32,60 @@ class DummyBuildEnvironment: class CacheKeyComputerTests(unittest.TestCase): def setUp(self): + loader = morphlib.morphloader.MorphologyLoader() self.source_pool = morphlib.sourcepool.SourcePool() for name, text in { - 'chunk.morph': '''{ - "name": "chunk", - "kind": "chunk", - "description": "A test chunk" - }''', - 'chunk2.morph': '''{ - "name": "chunk2", - "kind": "chunk", - "description": "A test chunk" - }''', - 'chunk3.morph': '''{ - "name": "chunk3", - "kind": "chunk", - "description": "A test chunk" - }''', - 'stratum.morph': '''{ - "name": "stratum", - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "repo", - "ref": "original/ref", - "build-depends": [] - } - ] - }''', - 'stratum2.morph': '''{ - "name": "stratum2", - "kind": "stratum", - "chunks": [ - { - "name": "chunk2", - "repo": "repo", - "ref": "original/ref", - "build-depends": [] - }, - { - "name": "chunk3", - "repo": "repo", - "ref": "original/ref", - "build-depends": [] - } - ] - }''', - 'system.morph': '''{ - "name": "system", - "kind": "system", - "strata": [ - { - "morph": "stratum", - "repo": "repo", - "ref": "original/ref" - }, - { - "morph": "stratum2", - "repo": "repo", - "ref": "original/ref" - } - ] - }''', + 'chunk.morph': ''' + name: chunk + kind: chunk + description: A test chunk + ''', + 'chunk2.morph': ''' + name: chunk2 + kind: chunk + description: A test chunk + ''', + 'chunk3.morph': ''' + name: chunk3 + kind: chunk + description: A test chunk + ''', + 'stratum.morph': ''' + name: stratum + kind: stratum + build-depends: [] + chunks: + - name: chunk + repo: repo + ref: original/ref + build-depends: [] + ''', + 'stratum2.morph': ''' + name: stratum2 + kind: stratum + build-depends: [] + chunks: + - name: chunk2 + repo: repo + ref: original/ref + build-depends: [] + - name: chunk3 + repo: repo + ref: original/ref + build-depends: [] + ''', + 'system.morph': ''' + name: system + kind: system + arch: testarch + strata: + - morph: stratum + - morph: stratum2 + ''', }.iteritems(): source = morphlib.source.Source( 'repo', 'original/ref', 'sha', 'tree', - morphlib.morph2.Morphology(text), name) + loader.load_from_string(text), name) self.source_pool.add(source) # FIXME: This should use MorphologyFactory m = source.morphology @@ -202,7 +189,12 @@ class CacheKeyComputerTests(unittest.TestCase): self.assertEqual(old_sha, new_sha) def test_same_morphology_added_to_source_pool_only_appears_once(self): - m = morphlib.morph2.Morphology('{"name": "chunk", "kind": "chunk"}') + loader = morphlib.morphloader.MorphologyLoader() + m = loader.load_from_string( + ''' + name: chunk + kind: chunk + ''') src = morphlib.source.Source('repo', 'original/ref', 'sha', 'tree', m, 'chunk.morph') sp = morphlib.sourcepool.SourcePool() diff --git a/morphlib/localartifactcache_tests.py b/morphlib/localartifactcache_tests.py index f400a645..6283c833 100644 --- a/morphlib/localartifactcache_tests.py +++ b/morphlib/localartifactcache_tests.py @@ -27,23 +27,21 @@ class LocalArtifactCacheTests(unittest.TestCase): def setUp(self): self.tempfs = fs.tempfs.TempFS() - morph = morphlib.morph2.Morphology( + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( ''' - { - "name": "chunk", - "kind": "chunk", - "artifacts": { - "chunk-runtime": [ - "usr/bin", - "usr/sbin", - "usr/lib", - "usr/libexec" - ], - "chunk-devel": [ - "usr/include" - ] - } - } + name: chunk + kind: chunk + products: + - artifact: chunk-runtime + include: + - usr/bin + - usr/sbin + - usr/lib + - usr/libexec + - artifact: chunk-devel + include: + - usr/include ''') self.source = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') diff --git a/morphlib/remoteartifactcache_tests.py b/morphlib/remoteartifactcache_tests.py index d11bf264..ca959ebf 100644 --- a/morphlib/remoteartifactcache_tests.py +++ b/morphlib/remoteartifactcache_tests.py @@ -24,26 +24,24 @@ import morphlib class RemoteArtifactCacheTests(unittest.TestCase): def setUp(self): - morph = morphlib.morph2.Morphology( + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( ''' - { - "name": "chunk", - "kind": "chunk", - "artifacts": { - "chunk-runtime": [ - "usr/bin", - "usr/sbin", - "usr/lib", - "usr/libexec" - ], - "chunk-devel": [ - "usr/include" - ], - "chunk-doc": [ - "usr/share/doc" - ] - } - } + name: chunk + kind: chunk + products: + - artifact: chunk-runtime + include: + - usr/bin + - usr/sbin + - usr/lib + - usr/libexec + - artifact: chunk-devel + include: + - usr/include + - artifact: chunk-doc + include: + - usr/share/doc ''') self.source = morphlib.source.Source( 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') diff --git a/morphlib/source_tests.py b/morphlib/source_tests.py index 6643f0fc..f5ce5d4d 100644 --- a/morphlib/source_tests.py +++ b/morphlib/source_tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,10 +22,8 @@ import morphlib class SourceTests(unittest.TestCase): morphology_text = ''' - { - "name": "foo", - "kind": "chunk" - } + name: foo + kind: chunk ''' def setUp(self): @@ -33,7 +31,8 @@ class SourceTests(unittest.TestCase): self.original_ref = 'original/ref' self.sha1 = 'CAFEF00D' self.tree = 'F000000D' - self.morphology = morphlib.morph2.Morphology(self.morphology_text) + loader = morphlib.morphloader.MorphologyLoader() + self.morphology = loader.load_from_string(self.morphology_text) self.filename = 'foo.morph' self.source = morphlib.source.Source( self.repo_name, self.original_ref, self.sha1, self.tree, -- cgit v1.2.1 From a87d850a3b96010dd272bba1624fcf0b230afc6d Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 11:00:02 +0000 Subject: cmdtests: Change the error messages to be detected --- tests.as-root/archless-system-fails.script | 2 +- tests.as-root/archless-system-fails.stderr | 2 +- tests.build/empty-stratum.script | 2 +- tests.build/empty-stratum.stderr | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests.as-root/archless-system-fails.script b/tests.as-root/archless-system-fails.script index 2fdeb018..c5c423b4 100755 --- a/tests.as-root/archless-system-fails.script +++ b/tests.as-root/archless-system-fails.script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests.as-root/archless-system-fails.stderr b/tests.as-root/archless-system-fails.stderr index 585eb635..71e7dbb0 100644 --- a/tests.as-root/archless-system-fails.stderr +++ b/tests.as-root/archless-system-fails.stderr @@ -1 +1 @@ -ERROR: No arch specified in system archless-system.morph (arch is a mandatory field) +ERROR: Missing field arch from morphology string diff --git a/tests.build/empty-stratum.script b/tests.build/empty-stratum.script index 6856b2bd..cb39b94a 100755 --- a/tests.build/empty-stratum.script +++ b/tests.build/empty-stratum.script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests.build/empty-stratum.stderr b/tests.build/empty-stratum.stderr index d8c9bf28..6a4ecb05 100644 --- a/tests.build/empty-stratum.stderr +++ b/tests.build/empty-stratum.stderr @@ -1 +1 @@ -ERROR: Stratum hello-stratum is empty (has no dependencies) +ERROR: Stratum hello-stratum has no chunks in string -- cgit v1.2.1 From bba1d9e9f17edf885e857d0ddcf5b6f41e956b10 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 11:10:25 +0000 Subject: cmdtests: Use YAML not JSON to represent morphologies --- tests.as-root/archless-system-fails.script | 15 +- .../metadata-includes-morph-version.setup | 19 +- tests.as-root/metadata-includes-repo-alias.setup | 19 +- .../rootfs-tarball-builds-rootfs-and-kernel.script | 13 +- tests.as-root/system-overlap.script | 132 +++--- tests.as-root/tarball-image-is-sensible.setup | 63 ++- tests.build/build-chunk-failures-dump-log.script | 17 +- tests.build/build-stratum-with-submodules.script | 34 +- tests.build/build-system-autotools.script | 10 +- tests.build/build-system-cmake.script | 11 +- tests.build/build-system-cpan.script | 31 +- tests.build/build-system-python-distutils.script | 31 +- tests.build/build-system-qmake.script | 13 +- tests.build/empty-stratum.script | 6 +- tests.build/prefix.script | 62 ++- tests.build/setup | 58 +-- tests.build/setup-build-essential | 122 +++--- tests.build/stratum-overlap-warns.setup | 120 +++--- tests.deploy/setup | 128 +++--- tests/setup | 60 +-- tests/show-dependencies.setup | 452 ++++++++------------- 21 files changed, 549 insertions(+), 867 deletions(-) diff --git a/tests.as-root/archless-system-fails.script b/tests.as-root/archless-system-fails.script index c5c423b4..e34e9ad6 100755 --- a/tests.as-root/archless-system-fails.script +++ b/tests.as-root/archless-system-fails.script @@ -23,17 +23,10 @@ set -eu cd "$DATADIR/morphs" git checkout --quiet -b archless master cat <archless-system.morph -{ - "name": "archless-system", - "kind": "system", - "strata": [ - { - "morph": "hello-stratum", - "repo": "tests:morphs", - "ref": "archless" - } - ] -} +name: archless-system +kind: system +strata: + - morph: hello-stratum EOF git add archless-system.morph git commit --quiet -m "add archless system" diff --git a/tests.as-root/metadata-includes-morph-version.setup b/tests.as-root/metadata-includes-morph-version.setup index d7fc96e3..e4557302 100755 --- a/tests.as-root/metadata-includes-morph-version.setup +++ b/tests.as-root/metadata-includes-morph-version.setup @@ -24,19 +24,12 @@ morphsrepo="$DATADIR/morphs" cd "$morphsrepo" git checkout -b tarball cat < hello-tarball.morph -{ - "name": "hello-tarball", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "morph": "hello-stratum", - }, - { - "morph": "linux-stratum", - } - ] -} +name: hello-tarball +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - morph: hello-stratum + - morph: linux-stratum EOF git add hello-tarball.morph diff --git a/tests.as-root/metadata-includes-repo-alias.setup b/tests.as-root/metadata-includes-repo-alias.setup index d7fc96e3..e4557302 100755 --- a/tests.as-root/metadata-includes-repo-alias.setup +++ b/tests.as-root/metadata-includes-repo-alias.setup @@ -24,19 +24,12 @@ morphsrepo="$DATADIR/morphs" cd "$morphsrepo" git checkout -b tarball cat < hello-tarball.morph -{ - "name": "hello-tarball", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "morph": "hello-stratum", - }, - { - "morph": "linux-stratum", - } - ] -} +name: hello-tarball +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - morph: hello-stratum + - morph: linux-stratum EOF git add hello-tarball.morph diff --git a/tests.as-root/rootfs-tarball-builds-rootfs-and-kernel.script b/tests.as-root/rootfs-tarball-builds-rootfs-and-kernel.script index e0829968..ca1b1302 100755 --- a/tests.as-root/rootfs-tarball-builds-rootfs-and-kernel.script +++ b/tests.as-root/rootfs-tarball-builds-rootfs-and-kernel.script @@ -27,14 +27,11 @@ arch=$("$SRCDIR/scripts/test-morph" print-architecture) cd "$DATADIR/kernel-repo" cat <linux.morph -{ - "name": "linux", - "kind": "chunk", - "install-commands": [ - "mkdir -p \"\$DESTDIR/boot\"", - "touch \"\$DESTDIR\"/boot/zImage" - ] -} +name: linux +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR/boot" + - touch "\$DESTDIR/boot/zImage" EOF git add linux.morph git commit --quiet -m 'Make the kernel create a dummy zImage' diff --git a/tests.as-root/system-overlap.script b/tests.as-root/system-overlap.script index 1ce8379d..9be6df13 100755 --- a/tests.as-root/system-overlap.script +++ b/tests.as-root/system-overlap.script @@ -28,63 +28,44 @@ morphsrepo="$DATADIR/morphs" cd "$morphsrepo" git checkout --quiet -b overlap master cat <overlap-system.morph -{ - "name": "overlap-system", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "morph": "foo-baz-stratum", - }, - { - "morph": "foo-barqux-stratum", - } - ] -} +name: overlap-system +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - morph: foo-baz-stratum + - morph: foo-barqux-stratum EOF cat <foo-baz-stratum.morph -{ - "name": "foo-baz-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "overlap-foo-baz", - "repo": "test:chunk-repo", - "ref": "overlap", - "build-mode": "test", - "build-depends": [] - }, - { - "name": "linux", - "repo": "test:kernel-repo", - "ref": "master", - "build-mode": "test", - "build-depends": ["overlap-foo-baz"] - } - ] -} +name: foo-baz-stratum +kind: stratum +chunks: + - name: overlap-foo-baz + repo: test:chunk-repo + ref: overlap + build-mode: test + build-depends: [] + - name: linux + repo: test:kernel-repo + ref: master + build-mode: test + build-depends: + - overlap-foo-baz EOF cat <foo-barqux-stratum.morph -{ - "name": "foo-barqux-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "overlap-foobar", - "repo": "test:chunk-repo", - "ref": "overlap", - "build-mode": "test", - "build-depends": [] - }, - { - "name": "overlap-fooqux", - "repo": "test:chunk-repo", - "ref": "overlap", - "build-mode": "test", - "build-depends": ["overlap-foobar"] - } - ] -} +name: foo-barqux-stratum +kind: stratum +chunks: + - name: overlap-foobar + repo: test:chunk-repo + ref: overlap + build-mode: test + build-depends: [] + - name: overlap-fooqux + repo: test:chunk-repo + ref: overlap + build-mode: test + build-depends: + - overlap-foobar EOF git add overlap-system.morph foo-baz-stratum.morph foo-barqux-stratum.morph git commit --quiet -m "add overlapping system" @@ -92,39 +73,30 @@ git commit --quiet -m "add overlapping system" cd "$chunkrepo" git checkout --quiet -b overlap master cat <overlap-foo-baz.morph -{ - "name": "overlap-foo-baz", - "kind": "chunk", - "install-commands": [ - "mkdir -p \$DESTDIR/bin", - "for f in foo bar baz; do echo echo \$f >\$DESTDIR/bin/\$f; done" - ] -} +name: overlap-foo-baz +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR"/bin + - for f in foo bar baz; do echo echo \$f >"\$DESTDIR"/bin/\$f; done EOF cat <overlap-foobar.morph -{ - "name": "overlap-foobar", - "kind": "chunk", - "install-commands": [ - "mkdir -p \$DESTDIR/usr/bin \$DESTDIR/bin", - "echo echo foobar >\$DESTDIR/usr/bin/foobar", - "ln -s /usr/bin/foobar \$DESTDIR/bin/foo", - "ln -s /usr/bin/foobar \$DESTDIR/bin/bar" - ] -} +name: overlap-foobar +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR"/usr/bin "\$DESTDIR"/bin + - echo echo foobar >"\$DESTDIR"/usr/bin/foobar + - ln -s /usr/bin/foobar "\$DESTDIR"/bin/foo + - ln -s /usr/bin/foobar "\$DESTDIR"/bin/bar EOF cat <overlap-fooqux.morph -{ - "name": "overlap-fooqux", - "kind": "chunk", - "install-commands": [ - "mkdir -p \$DESTDIR/usr/bin \$DESTDIR/bin", - "for f in qux fooqux; do echo echo \$f >\$DESTDIR/usr/bin/\$f; done", - "ln -s /usr/bin/fooqux \$DESTDIR/bin/foo" - ] -} +name: overlap-fooqux +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR"/usr/bin "\$DESTDIR"/bin + - for f in qux fooqux; do echo echo \$f >"\$DESTDIR"/usr/bin/\$f; done + - ln -s /usr/bin/fooqux "\$DESTDIR"/bin/foo EOF git add overlap-*.morph diff --git a/tests.as-root/tarball-image-is-sensible.setup b/tests.as-root/tarball-image-is-sensible.setup index c47a5336..a687b691 100755 --- a/tests.as-root/tarball-image-is-sensible.setup +++ b/tests.as-root/tarball-image-is-sensible.setup @@ -24,17 +24,14 @@ chunkrepo="$DATADIR/chunk-repo" cd "$chunkrepo" git checkout -b tarball-links cat >links.morph <<'EOF' -{ - "name": "links", - "kind": "chunk", - "build-system": "manual", - "install-commands": [ - "mkdir -p \"$DESTDIR/bin\"", - "touch \"$DESTDIR/bin/true\"", - "cd \"$DESTDIR/bin\" && ln true true-hardlink", - "cd \"$DESTDIR/bin\" && ln -s true true-symlink" - ] -} +name: links +kind: chunk +build-system: manual +install-commands: + - mkdir -p "$DESTDIR/bin" + - touch "$DESTDIR/bin/true" + - cd "$DESTDIR/bin" && ln true true-hardlink + - cd "$DESTDIR/bin" && ln -s true true-symlink EOF git add links.morph git commit --quiet -m 'Add link adding chunk' @@ -43,22 +40,13 @@ morphsrepo="$DATADIR/morphs" cd "$morphsrepo" git checkout -b tarball-links cat < hello-tarball.morph -{ - "name": "hello-tarball", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "morph": "link-stratum", - }, - { - "morph": "hello-stratum", - }, - { - "morph": "linux-stratum", - } - ] -} +name: hello-tarball +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - morph: link-stratum + - morph: hello-stratum + - morph: linux-stratum EOF git add hello-tarball.morph @@ -69,19 +57,14 @@ sed -i linux-stratum.morph \ git add linux-stratum.morph cat < link-stratum.morph -{ - "name": "link-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "links", - "repo": "test:chunk-repo", - "ref": "tarball-links", - "build-mode": "test", - "build-depends": [] - } - ] -} +name: link-stratum +kind: stratum +chunks: + - name: links + repo: test:chunk-repo + ref: tarball-links + build-mode: test + build-depends: [] EOF git add link-stratum.morph git commit --quiet -m "add morphs" diff --git a/tests.build/build-chunk-failures-dump-log.script b/tests.build/build-chunk-failures-dump-log.script index e5c7c38d..645fd59a 100755 --- a/tests.build/build-chunk-failures-dump-log.script +++ b/tests.build/build-chunk-failures-dump-log.script @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,15 +25,12 @@ chunkrepo="$DATADIR/chunk-repo" cd "$chunkrepo" git checkout --quiet farrokh cat <hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "dummy", - "build-commands": [ - "echo The next command will fail", - "false" - ] -} +name: hello +kind: chunk +build-system: dummy +build-commands: + - echo The next command will fail + - "false" EOF git add hello.morph git commit --quiet -m "Make morphology fail to build." diff --git a/tests.build/build-stratum-with-submodules.script b/tests.build/build-stratum-with-submodules.script index c996e769..015db3f2 100755 --- a/tests.build/build-stratum-with-submodules.script +++ b/tests.build/build-stratum-with-submodules.script @@ -26,14 +26,11 @@ set -eu parent="$DATADIR/parent-repo" mkdir "$parent" cat < "$parent/parent.morph" -{ - "name": "parent", - "kind": "chunk", - "build-system": "manual", - "build-commands": [ - "test -f le-sub/README" - ] -} +name: parent +kind: chunk +build-system: manual +build-commands: + - test -f le-sub/README EOF "$SRCDIR/scripts/run-git-in" "$parent" init --quiet @@ -47,19 +44,14 @@ EOF morphs="$DATADIR/morphs-repo" cat < "$morphs/hello-stratum.morph" -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "parent", - "repo": "test:parent-repo", - "ref": "master", - "build-depends": [], - "build-mode": "test" - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: parent + repo: test:parent-repo + ref: master + build-depends: [] + build-mode: test EOF "$SRCDIR/scripts/run-git-in" "$morphs" add hello-stratum.morph "$SRCDIR/scripts/run-git-in" "$morphs" commit --quiet -m 'foo' diff --git a/tests.build/build-system-autotools.script b/tests.build/build-system-autotools.script index ba5cd32f..2ea53174 100755 --- a/tests.build/build-system-autotools.script +++ b/tests.build/build-system-autotools.script @@ -37,12 +37,10 @@ EOF git add Makefile cat < hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "autotools", - "configure-commands": [] -} +name: hello +kind: chunk +build-system: autotools +configure-commands: [] EOF git add hello.morph git commit --quiet -m "Convert hello to an autotools project" diff --git a/tests.build/build-system-cmake.script b/tests.build/build-system-cmake.script index ab5186d7..570a9af7 100755 --- a/tests.build/build-system-cmake.script +++ b/tests.build/build-system-cmake.script @@ -38,12 +38,11 @@ EOF git add CMakeLists.txt cat < hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "cmake", - "install-commands": ["make DESTDIR=\"\$DESTDIR\" install"] -} +name: hello +kind: chunk +build-system: cmake +install-commands: + - make DESTDIR="\$DESTDIR" install EOF git add hello.morph git commit --quiet -m "Convert hello to a cmake project" diff --git a/tests.build/build-system-cpan.script b/tests.build/build-system-cpan.script index f66d4027..735dac84 100755 --- a/tests.build/build-system-cpan.script +++ b/tests.build/build-system-cpan.script @@ -44,11 +44,9 @@ EOF git add Makefile.PL cat <hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "cpan" -} +name: hello +kind: chunk +build-system: cpan EOF git add hello.morph @@ -57,20 +55,15 @@ git commit --quiet -m 'convert hello into a perl cpan project' # Set 'prefix' of hello to something custom cd "$DATADIR/morphs-repo" cat < hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "hello", - "repo": "test:chunk-repo", - "ref": "farrokh", - "build-depends": [], - "build-mode": "test", - "prefix": "/" - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: hello + repo: test:chunk-repo + ref: farrokh + build-depends: [] + build-mode: test + prefix: / EOF git add hello-stratum.morph git commit -q -m "Set custom install prefix for hello" diff --git a/tests.build/build-system-python-distutils.script b/tests.build/build-system-python-distutils.script index e1dccb4b..9a751491 100755 --- a/tests.build/build-system-python-distutils.script +++ b/tests.build/build-system-python-distutils.script @@ -41,11 +41,9 @@ EOF git add setup.py cat <hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "python-distutils" -} +name: hello +kind: chunk +build-system: python-distutils EOF git add hello.morph @@ -55,20 +53,15 @@ git commit --quiet -m 'convert hello into a python project' # Set 'prefix' of hello to something custom cd "$DATADIR/morphs-repo" cat < hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "hello", - "repo": "test:chunk-repo", - "ref": "farrokh", - "build-depends": [], - "build-mode": "test", - "prefix": "" - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: hello + repo: test:chunk-repo + ref: farrokh + build-depends: [] + build-mode: test + prefix: "" EOF git add hello-stratum.morph git commit -q -m "Set custom install prefix for hello" diff --git a/tests.build/build-system-qmake.script b/tests.build/build-system-qmake.script index d9e21fba..b3861936 100755 --- a/tests.build/build-system-qmake.script +++ b/tests.build/build-system-qmake.script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -46,12 +46,11 @@ EOF git add hello.pro cat < hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "qmake", - "install-commands": ["make INSTALL_ROOT=\"\$DESTDIR\" install"] -} +name: hello +kind: chunk +build-system: qmake +install-commands: + - make INSTALL_ROOT="\$DESTDIR" install EOF git add hello.morph git commit --quiet -m "Convert hello to an qmake project" diff --git a/tests.build/empty-stratum.script b/tests.build/empty-stratum.script index cb39b94a..19c36558 100755 --- a/tests.build/empty-stratum.script +++ b/tests.build/empty-stratum.script @@ -24,10 +24,8 @@ git checkout --quiet -b empty-stratum # Create empty stratum to test S4585 cat < hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum" -} +name: hello-stratum +kind: stratum EOF sed -i 's/master/empty-stratum/' hello-system.morph git add hello-stratum.morph hello-system.morph diff --git a/tests.build/prefix.script b/tests.build/prefix.script index ca9648c9..209c1a54 100755 --- a/tests.build/prefix.script +++ b/tests.build/prefix.script @@ -24,24 +24,18 @@ set -eu cd "$DATADIR/chunk-repo" git checkout -q master cat <<\EOF > xyzzy.morph -{ - "name": "xyzzy", - "kind": "chunk", - "configure-commands": [ - "echo First chunk: prefix $PREFIX" - ] -} +name: xyzzy +kind: chunk +configure-commands: + - "echo First chunk: prefix $PREFIX" EOF cat <<\EOF > plugh.morph -{ - "name": "plugh", - "kind": "chunk", - "configure-commands": [ - "echo Second chunk: prefix $PREFIX", - "echo Path: $(echo $PATH | grep -o '/plover')" - ] -} +name: plugh +kind: chunk +configure-commands: + - "echo Second chunk: prefix $PREFIX" + - "echo Path: $(echo $PATH | grep -o '/plover')" EOF git add xyzzy.morph @@ -51,29 +45,21 @@ git commit -q -m "Add chunks" # Change stratum to include those two chunks, and use a custom install prefix cd "$DATADIR/morphs-repo" cat < hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "xyzzy", - "repo": "test:chunk-repo", - "ref": "master", - "build-depends": [], - "build-mode": "test", - "prefix": "/plover" - }, - { - "name": "plugh", - "repo": "test:chunk-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "xyzzy" - ] - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: xyzzy + repo: test:chunk-repo + ref: master + build-depends: [] + build-mode: test + prefix: /plover + - name: plugh + repo: test:chunk-repo + ref: master + build-mode: test + build-depends: + - xyzzy EOF git add hello-stratum.morph git commit -q -m "Update stratum" diff --git a/tests.build/setup b/tests.build/setup index 559825b1..833f132d 100755 --- a/tests.build/setup +++ b/tests.build/setup @@ -57,19 +57,15 @@ EOF git add hello.c cat < hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "dummy", - "build-commands": [ - "gcc -o hello hello.c" - ], - "install-commands": [ - "install -d \\"\$DESTDIR\\"/etc", - "install -d \\"\$DESTDIR\\"/bin", - "install hello \\"\$DESTDIR\\"/bin/hello" - ] -} +name: hello +kind: chunk +build-system: dummy +build-commands: + - gcc -o hello hello.c +install-commands: + - install -d "\$DESTDIR"/etc + - install -d "\$DESTDIR"/bin + - install hello "\$DESTDIR"/bin/hello EOF git add hello.morph @@ -87,33 +83,23 @@ cd "$morphsrepo" git init --quiet cat < hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "hello", - "repo": "test:chunk-repo", - "ref": "farrokh", - "build-mode": "test", - "build-depends": [] - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: hello + repo: test:chunk-repo + ref: farrokh + build-mode: test + build-depends: [] EOF git add hello-stratum.morph cat < hello-system.morph -{ - "name": "hello-system", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "morph": "hello-stratum", - } - ] -} +name: hello-system +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - morph: hello-stratum EOF git add hello-system.morph diff --git a/tests.build/setup-build-essential b/tests.build/setup-build-essential index 5674020d..9ffb7774 100755 --- a/tests.build/setup-build-essential +++ b/tests.build/setup-build-essential @@ -28,28 +28,21 @@ EOF chmod +x morph-test-cc cat < "stage1-cc.morph" -{ - "name": "stage1-cc", - "kind": "chunk", - "install-commands": [ - "install -d \"\$DESTDIR\$PREFIX/bin\"", - "install -m 755 morph-test-cc \"\$DESTDIR\$PREFIX/bin/morph-test-cc\"" - ] -} +name: stage1-cc +kind: chunk +install-commands: + - install -d "\$DESTDIR\$PREFIX/bin" + - install -m 755 morph-test-cc "\$DESTDIR\$PREFIX/bin/morph-test-cc" EOF cat < "cc.morph" -{ - "name": "cc", - "kind": "chunk", - "configure-commands": [ - "[ -e ../tools/bin/morph-test-cc ]" - ], - "install-commands": [ - "install -d \"\$DESTDIR\$PREFIX/bin\"", - "install -m 755 morph-test-cc \"\$DESTDIR\$PREFIX/bin/morph-test-cc\"" - ] -} +name: cc +kind: chunk +configure-commands: + - [ -e ../tools/bin/morph-test-cc ] +install-commands: + - install -d "\$DESTDIR\$PREFIX/bin" + - install -m 755 morph-test-cc "\$DESTDIR\$PREFIX/bin/morph-test-cc" EOF git init -q @@ -61,21 +54,16 @@ git commit -q -m "Create compiler chunk" cd "$DATADIR/chunk-repo" git checkout -q farrokh cat < "hello.morph" -{ - "name": "hello", - "kind": "chunk", - "configure-commands": [ - "[ ! -e ../tools/bin/morph-test-cc ]", - "[ -e ../usr/bin/morph-test-cc ]" - ], - "build-commands": [ - "../usr/bin/morph-test-cc > hello" - ], - "install-commands": [ - "install -d \"\$DESTDIR\$PREFIX/bin\"", - "install hello \"\$DESTDIR\$PREFIX/bin/hello\"" - ] -} +name: hello +kind: chunk +configure-commands: + - [ ! -e ../tools/bin/morph-test-cc ] + - [ -e ../usr/bin/morph-test-cc ] +build-commands: + - ../usr/bin/morph-test-cc > hello +install-commands: + - install -d "\$DESTDIR\$PREFIX/bin" + - install hello "\$DESTDIR\$PREFIX/bin/hello" EOF git add hello.morph git commit -q -m "Make 'hello' require our mock compiler" @@ -85,50 +73,34 @@ git commit -q -m "Make 'hello' require our mock compiler" # artifact, and neither should make it into the system. cd "$DATADIR/morphs-repo" cat < "build-essential.morph" -{ - "name": "build-essential", - "kind": "stratum", - "chunks": [ - { - "name": "stage1-cc", - "repo": "test:cc-repo", - "ref": "master", - "build-depends": [], - "build-mode": "bootstrap", - "prefix": "/tools" - }, - { - "name": "cc", - "repo": "test:cc-repo", - "ref": "master", - "build-depends": [ - "stage1-cc" - ], - "build-mode": "test" - } - ] -} +name: build-essential +kind: stratum +chunks: + - name: stage1-cc + repo: test:cc-repo + ref: master + build-depends: [] + build-mode: bootstrap + prefix: /tools + - name: cc + repo: test:cc-repo + ref: master + build-depends: + - stage1-cc + build-mode: test EOF cat < "hello-stratum.morph" -{ - "name": "hello-stratum", - "kind": "stratum", - "build-depends": [ - { - "morph": "build-essential", - } - ], - "chunks": [ - { - "name": "hello", - "repo": "test:chunk-repo", - "ref": "farrokh", - "build-depends": [], - "build-mode": "test" - } - ] -} +name: hello-stratum +kind: stratum +build-depends: + - morph: build-essential +chunks: + - name: hello + repo: test:chunk-repo + ref: farrokh + build-depends: [] + build-mode: test EOF git add build-essential.morph hello-stratum.morph hello-system.morph diff --git a/tests.build/stratum-overlap-warns.setup b/tests.build/stratum-overlap-warns.setup index 5ebd217c..b969822d 100755 --- a/tests.build/stratum-overlap-warns.setup +++ b/tests.build/stratum-overlap-warns.setup @@ -3,7 +3,7 @@ # If a stratum has multiple chunks that have the same files in them, # then this should be notified # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,40 +26,32 @@ morphsrepo="$DATADIR/morphs-repo" cd "$morphsrepo" git checkout --quiet -b overlap master cat <hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "dirs", - "repo": "test:chunk-repo", - "ref": "overlap", - "build-depends": [], - "build-mode": "test" - }, - { - "name": "overlap-foobar", - "repo": "test:chunk-repo", - "ref": "overlap", - "build-depends": ["dirs"], - "build-mode": "test" - }, - { - "name": "overlap-fooqux", - "repo": "test:chunk-repo", - "ref": "overlap", - "build-depends": ["overlap-foobar"], - "build-mode": "test" - }, - { - "name": "overlap-foo-baz", - "repo": "test:chunk-repo", - "ref": "overlap", - "build-depends": ["overlap-fooqux"], - "build-mode": "test" - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: dirs + repo: test:chunk-repo + ref: overlap + build-depends: [] + build-mode: test + - name: overlap-foobar + repo: test:chunk-repo + ref: overlap + build-depends: + - dirs + build-mode: test + - name: overlap-fooqux + repo: test:chunk-repo + ref: overlap + build-depends: + - overlap-foobar + build-mode: test + - name: overlap-foo-baz + repo: test:chunk-repo + ref: overlap + build-depends: + - overlap-fooqux + build-mode: test EOF sed -i 's/master/overlap/' hello-system.morph git add hello-stratum.morph hello-system.morph @@ -69,53 +61,41 @@ cd "$chunkrepo" git checkout --quiet -b overlap master cat <dirs.morph -{ - "name": "dirs", - "kind": "chunk", - "install-commands": [ - "mkdir -p \$DESTDIR/bin", - "ln -s .. \$DESTDIR/usr" - ] -} +name: dirs +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR/bin" + - ln -s .. "\$DESTDIR/usr" EOF git add dirs.morph cat <overlap-foo-baz.morph -{ - "name": "overlap-foo-baz", - "kind": "chunk", - "install-commands": [ - "mkdir -p \$DESTDIR/bin", - "for f in foo bar baz; do echo echo \$f >\$DESTDIR/bin/\$f; done" - ] -} +name: overlap-foo-baz +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR/bin" + - for f in foo bar baz; do echo echo \$f >"\$DESTDIR/bin/\$f"; done EOF git add overlap-foo-baz.morph cat <overlap-foobar.morph -{ - "name": "overlap-foobar", - "kind": "chunk", - "install-commands": [ - "mkdir -p \$DESTDIR/usr/bin \$DESTDIR/bin", - "echo echo foobar >\$DESTDIR/usr/bin/foobar", - "ln -s /usr/bin/foobar \$DESTDIR/bin/foo", - "ln -s /usr/bin/foobar \$DESTDIR/bin/bar" - ] -} +name: overlap-foobar +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR/usr/bin" "\$DESTDIR/bin" + - echo echo foobar >"\$DESTDIR/usr/bin/foobar" + - ln -s /usr/bin/foobar "\$DESTDIR/bin/foo" + - ln -s /usr/bin/foobar "\$DESTDIR/bin/bar" EOF git add overlap-foobar.morph cat <overlap-fooqux.morph -{ - "name": "overlap-fooqux", - "kind": "chunk", - "install-commands": [ - "mkdir -p \$DESTDIR/usr/bin \$DESTDIR/bin", - "for f in qux fooqux; do echo echo \$f >\$DESTDIR/usr/bin/\$f; done", - "ln -s /usr/bin/fooqux \$DESTDIR/bin/foo" - ] -} +name: overlap-fooqux +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR/usr/bin" "\$DESTDIR/bin" + - for f in qux fooqux; do echo echo \$f >"\$DESTDIR/usr/bin/\$f"; done + - ln -s /usr/bin/fooqux "\$DESTDIR/bin/foo" EOF git add overlap-fooqux.morph diff --git a/tests.deploy/setup b/tests.deploy/setup index ece8819a..033598bc 100755 --- a/tests.deploy/setup +++ b/tests.deploy/setup @@ -62,19 +62,15 @@ EOF git add hello.c cat < hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "dummy", - "build-commands": [ - "gcc -o hello hello.c" - ], - "install-commands": [ - "install -d \\"\$DESTDIR\\"/etc", - "install -d \\"\$DESTDIR\\"/bin", - "install hello \\"\$DESTDIR\\"/bin/hello" - ] -} +name: hello +kind: chunk +build-system: dummy +build-commands: + - gcc -o hello hello.c +install-commands: + - install -d "\$DESTDIR/etc" + - install -d "\$DESTDIR/bin" + - install hello "\$DESTDIR/bin/hello" EOF git add hello.morph @@ -92,76 +88,49 @@ cd "$morphsrepo" git init --quiet cat < hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "hello", - "repo": "test:chunk-repo", - "ref": "farrokh", - "build-depends": [], - "build-mode": "test" - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: hello + repo: test:chunk-repo + ref: farrokh + build-depends: [] + build-mode: test EOF git add hello-stratum.morph cat < hello-system.morph -{ - "name": "hello-system", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "morph": "hello-stratum", - } - ] -} +name: hello-system +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - morph: hello-stratum EOF git add hello-system.morph cat < linux-stratum.morph -{ - "name": "linux-stratum", - "kind": "stratum", - "build-depends": [ - { - "morph": "hello-stratum", - } - ], - "chunks": [ - { - "name": "linux", - "repo": "test:kernel-repo", - "ref": "master", - "build-depends": [], - "build-mode": "test" - } - ] -} +name: linux-stratum +kind: stratum +build-depends: + - morph: hello-stratum +chunks: + - name: linux + repo: test:kernel-repo + ref: master + build-depends: [] + build-mode: test EOF git add linux-stratum.morph cat < linux-system.morph -{ - "name": "linux-system", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "morph": "hello-stratum", - }, - { - "morph": "linux-stratum", - } - ], - "configuration-extensions": [ - set-hostname - ] - -} +name: linux-system +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - morph: hello-stratum + - morph: linux-stratum +configuration-extensions: + - set-hostname EOF git add linux-system.morph @@ -222,16 +191,13 @@ git commit --quiet -m "add morphs" # Make a dummy kernel chunk. mkdir "$DATADIR/kernel-repo" cat < "$DATADIR/kernel-repo/linux.morph" -{ - "name": "linux", - "kind": "chunk", - "install-commands": [ - "mkdir -p \"\$DESTDIR/boot\"", - "touch \"\$DESTDIR\"/extlinux.conf", - "touch \"\$DESTDIR\"/boot/vmlinuz", - "touch \"\$DESTDIR\"/boot/System.map" - ] -} +name: linux +kind: chunk +install-commands: + - mkdir -p "\$DESTDIR/boot" + - touch "\$DESTDIR/extlinux.conf" + - touch "\$DESTDIR/boot/vmlinuz" + - touch "\$DESTDIR/boot/System.map" EOF "$SRCDIR/scripts/run-git-in" "$DATADIR/kernel-repo" init --quiet "$SRCDIR/scripts/run-git-in" "$DATADIR/kernel-repo" add . diff --git a/tests/setup b/tests/setup index 07643ddc..02ddb3af 100755 --- a/tests/setup +++ b/tests/setup @@ -10,7 +10,7 @@ # The stratum repository contains a single branch, "master", with a # stratum and a system morphology that include the chunk above. # -# Copyright (C) 2011-2013 Codethink Limited +# Copyright (C) 2011-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -57,19 +57,15 @@ EOF git add hello.c cat < hello.morph -{ - "name": "hello", - "kind": "chunk", - "build-system": "dummy", - "build-commands": [ - "gcc -o hello hello.c" - ], - "install-commands": [ - "install -d \\"\$DESTDIR\\"/etc", - "install -d \\"\$DESTDIR\\"/bin", - "install hello \\"\$DESTDIR\\"/bin/hello" - ] -} +name: hello +kind: chunk +build-system: dummy +build-commands: + - gcc -o hello hello.c +install-commands: + - install -d "\$DESTDIR/etc" + - install -d "\$DESTDIR/bin" + - install hello "\$DESTDIR/bin/hello" EOF git add hello.morph @@ -87,34 +83,22 @@ cd "$morphsrepo" git init --quiet cat < hello-stratum.morph -{ - "name": "hello-stratum", - "kind": "stratum", - "chunks": [ - { - "name": "hello", - "repo": "test:chunk-repo", - "ref": "farrokh", - "build-mode": "test", - "build-depends": [] - } - ] -} +name: hello-stratum +kind: stratum +chunks: + - name: hello + repo: test:chunk-repo + ref: farrokh + build-mode: test + build-depends: [] EOF git add hello-stratum.morph cat < hello-system.morph -{ - "name": "hello-system", - "kind": "system", - "strata": [ - { - "morph": "hello-stratum", - "repo": "test:morphs-repo", - "ref": "master" - } - ] -} +name: hello-system +kind: system +strata: + - morph: hello-stratum EOF git add hello-system.morph diff --git a/tests/show-dependencies.setup b/tests/show-dependencies.setup index 510656e6..c99e90a9 100755 --- a/tests/show-dependencies.setup +++ b/tests/show-dependencies.setup @@ -42,18 +42,14 @@ gtkcomponents=(freetype fontconfig cairo pango glib gdk-pixbuf gtk for component in "${gtkcomponents[@]}" do cat < $component.morph -{ - "name": "$component", - "kind": "chunk", - "build-commands": [ - "gcc -o hello hello.c" - ], - "install-commands": [ - "install -d \\"\$DESTDIR\\"/etc", - "install -d \\"\$DESTDIR\\"/bin", - "install hello \\"\$DESTDIR\\"/bin/$component" - ] -} +name: $component +kind: chunk +build-commands: + - gcc -o hello hello.c +install-commands: + - install -d "\$DESTDIR"/etc + - install -d "\$DESTDIR"/bin + - install hello "\$DESTDIR"/bin/$component EOF git add $component.morph done @@ -61,95 +57,64 @@ git commit --quiet -m "add .c source file and GTK chunk morphologies" # Define a stratum for the GTK stack cat < gtk-stack.morph -{ - "name": "gtk-stack", - "kind": "stratum", - "build-depends": [ - ], - "chunks": [ - { - "name": "freetype", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - ] - }, - { - "name": "fontconfig", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - ] - }, - { - "name": "cairo", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - ] - }, - { - "name": "pango", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "freetype", - "fontconfig" - ] - }, - { - "name": "glib", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - ] - }, - { - "name": "gdk-pixbuf", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "glib" - ] - }, - { - "name": "gtk", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "cairo", - "gdk-pixbuf", - "glib", - "pango" - ] - }, - { - "name": "dbus", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - ] - }, - { - "name": "dbus-glib", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "dbus", - "glib" - ] - } - ] -} +name: gtk-stack +kind: stratum +build-depends: [] +chunks: + - name: freetype + repo: test:test-repo + ref: master + build-mode: test + build-depends: [] + - name: fontconfig + repo: test:test-repo + ref: master + build-mode: test + build-depends: [] + - name: cairo + repo: test:test-repo + ref: master + build-mode: test + build-depends: [] + - name: pango + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - freetype + - fontconfig + - name: glib + repo: test:test-repo + ref: master + build-mode: test + build-depends: [] + - name: gdk-pixbuf + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - glib + - name: gtk + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - cairo + - gdk-pixbuf + - glib + - pango + - name: dbus + repo: test:test-repo + ref: master + build-mode: test + build-depends: [] + - name: dbus-glib + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - dbus + - glib EOF git add gtk-stack.morph git commit --quiet -m "add gtk-stack.morph stratum" @@ -172,18 +137,14 @@ xfcecomponents=(xfce4-dev-tools libxfce4util libxfce4ui exo xfconf garcon for component in "${xfcecomponents[@]}" do cat < $component.morph -{ - "name": "$component", - "kind": "chunk", - "build-commands": [ - "gcc -o hello hello.c" - ], - "install-commands": [ - "install -d \\"\$DESTDIR\\"/etc", - "install -d \\"\$DESTDIR\\"/bin", - "install hello \\"\$DESTDIR\\"/bin/$component" - ] -} +name: $component +kind: chunk +build-commands: + - gcc -o hello hello.c +install-commands: + - install -d "\$DESTDIR"/etc + - install -d "\$DESTDIR"/bin + - install hello "\$DESTDIR"/bin/$component EOF git add $component.morph done @@ -191,170 +152,117 @@ git commit --quiet -m "add .c source file and GTK chunk morphologies" # Define a stratum for the Xfce core cat < xfce-core.morph -{ - "name": "xfce-core", - "kind": "stratum", - "build-depends": [ - { - "morph": "gtk-stack", - } - ], - "chunks": [ - { - "name": "libxfce4util", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - ] - }, - { - "name": "xfconf", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4util" - ] - }, - { - "name": "libxfce4ui", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "xfconf" - ] - }, - { - "name": "exo", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4util" - ] - }, - { - "name": "garcon", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4util" - ] - }, - { - "name": "thunar", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "exo" - ] - }, - { - "name": "tumbler", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - ] - }, - { - "name": "xfce4-panel", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "exo", - "garcon" - ] - }, - { - "name": "xfce4-settings", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "exo", - "xfconf" - ] - }, - { - "name": "xfce4-session", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "exo", - "xfconf" - ] - }, - { - "name": "xfwm4", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "xfconf" - ] - }, - { - "name": "xfdesktop", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "xfconf" - ] - }, - { - "name": "xfce4-appfinder", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "garcon", - "xfconf" - ] - }, - { - "name": "gtk-xfce-engine", - "repo": "test:test-repo", - "ref": "master", - "build-mode": "test", - "build-depends": [ - "libxfce4ui", - "garcon", - "xfconf" - ] - } - ] -} +name: xfce-core +kind: stratum +build-depends: + - morph: gtk-stack +chunks: + - name: libxfce4util + repo: test:test-repo + ref: master + build-mode: test + build-depends: [] + - name: xfconf + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4util + - name: libxfce4ui + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - xfconf + - name: exo + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4util + - name: garcon + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4util + - name: thunar + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - exo + - name: tumbler + repo: test:test-repo + ref: master + build-mode: test + build-depends: [] + - name: xfce4-panel + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - exo + - garcon + - name: xfce4-settings + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - exo + - xfconf + - name: xfce4-session + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - exo + - xfconf + - name: xfwm4 + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - xfconf + - name: xfdesktop + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - xfconf + - name: xfce4-appfinder + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - garcon + - xfconf + - name: gtk-xfce-engine + repo: test:test-repo + ref: master + build-mode: test + build-depends: + - libxfce4ui + - garcon + - xfconf EOF git add xfce-core.morph git commit --quiet -m "add xfce-core.morph stratum" cat < xfce-system.morph -{ - "name": "xfce-system", - "kind": "system", - "arch": "$("$SRCDIR/scripts/test-morph" print-architecture)", - "strata": [ - { - "build-mode": "test", - "morph": "xfce-core" - } - ] -} +name: xfce-system +kind: system +arch: $("$SRCDIR/scripts/test-morph" print-architecture) +strata: + - build-mode: test + morph: xfce-core EOF git add xfce-system.morph git commit --quiet -m "add xfce-system" -- cgit v1.2.1 From bc0bffcb2da939862f6f494229c1f8ed5dda00ac Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 10:24:43 +0000 Subject: edit-morph: Use morphloader rather than morph2 Update the edit-morph script used in the test suite to use morphloader for saving/loading morphologies rather than morph2. Also remove some unused code. --- scripts/edit-morph | 60 ++++++++---------------------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/scripts/edit-morph b/scripts/edit-morph index d0b793a4..90679b23 100755 --- a/scripts/edit-morph +++ b/scripts/edit-morph @@ -32,13 +32,8 @@ class EditMorph(cliapp.Application): 'automatically') def load_morphology(self, file_name, expected_kind = None): - with open(file_name) as f: - text = f.read() - try: - morphology = morphlib.morph2.Morphology(text) - except ValueError as e: - raise morphlib.Error("Error parsing %s: %s" % - (file_name, str(e))) + loader = morphlib.morphloader.MorphologyLoader() + morphology = loader.load_from_file(file_name) if expected_kind is not None and morphology['kind'] != expected_kind: raise morphlib.Error("Expected: a %s morphology" % expected_kind) @@ -67,10 +62,10 @@ class EditMorph(cliapp.Application): elif chunk_name in info['build-depends']: info['build-depends'].remove(chunk_name) build_depends_count += 1 - morphology._dict['chunks'] = new_chunks + morphology['chunks'] = new_chunks - with morphlib.savefile.SaveFile(file_name, 'w') as f: - morphology.update_text(text, f) + loader = morphlib.morphloader.MorphologyLoader() + loader.save_to_file(file_name, morphology) self.output.write("Removed: %i chunk(s) and %i build depend(s).\n" % (component_count, build_depends_count)) @@ -88,49 +83,10 @@ class EditMorph(cliapp.Application): for chunk in morphology['chunks']: chunk['build-depends'].sort() - morphology._dict['chunks'] = self.sort_chunks(morphology['chunks']) + morphology['chunks'] = self.sort_chunks(morphology['chunks']) - with morphlib.savefile.SaveFile(file_name, 'w') as f: - morphology.update_text(text, f) - - def cmd_to_json(self, args): - """Convert one or more FILES to JSON. - - Assumes a .yaml extension, which will be removed in the output file. - """ - - if len(args) == 0: - raise cliapp.AppException("to-json expects one or more filenames") - - for file_name in args: - try: - morphology, text = self.load_morphology(file_name) - - if not file_name.endswith('.yaml'): - raise morphlib.Error('file name does not end with .yaml') - out_file_name = file_name[:-len('.yaml')] - - with morphlib.savefile.SaveFile(out_file_name, 'w') as f: - morphology.update_text(text, f, convert_to='json') - except Exception as e: - self.output.write('%s: %s\n' % (file_name, e)) - - def cmd_to_yaml(self, args): - """Convert one or more FILES to YAML. - - Adds a .yaml extension for each input file.""" - - if len(args) == 0: - raise cliapp.AppException("to-yaml expects one or more filenames") - - for file_name in args: - try: - morphology, text = self.load_morphology(file_name) - - with morphlib.savefile.SaveFile(file_name + '.yaml', 'w') as f: - morphology.update_text(text, f, convert_to='yaml') - except Exception as e: - self.output.write('%s: %s\n' % (file_name, e)) + loader = morphlib.morphloader.MorphologyLoader() + loader.save_to_file(file_name, morphology) def sort_chunks(self, chunks_list): """Sort stratum chunks -- cgit v1.2.1 From 8c8ea75f681fa86d4c29a07419aae3bbcb3b8582 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 07:51:04 +0000 Subject: Remove morph2 and its tests This commit removes the now unneeded morph2 and its associated tests. --- morphlib/__init__.py | 1 - morphlib/morph2.py | 313 ------------------------------------- morphlib/morph2_tests.py | 391 ----------------------------------------------- 3 files changed, 705 deletions(-) delete mode 100644 morphlib/morph2.py delete mode 100644 morphlib/morph2_tests.py diff --git a/morphlib/__init__.py b/morphlib/__init__.py index 0c928fd3..a31cf04c 100644 --- a/morphlib/__init__.py +++ b/morphlib/__init__.py @@ -68,7 +68,6 @@ import gitindex import localartifactcache import localrepocache import mountableimage -import morph2 import morphologyfactory import morphologyfinder import morph3 diff --git a/morphlib/morph2.py b/morphlib/morph2.py deleted file mode 100644 index b49c0f73..00000000 --- a/morphlib/morph2.py +++ /dev/null @@ -1,313 +0,0 @@ -# Copyright (C) 2012-2014 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -import re - -import morphlib -from morphlib.util import OrderedDict, json - -class Morphology(object): - - '''An in-memory representation of a morphology. - - This is a parsed version of the morphology, with rules for default - values applied. No other processing. - - ''' - - static_defaults = { - 'chunk': [ - ('description', ''), - ('pre-configure-commands', None), - ('configure-commands', None), - ('post-configure-commands', None), - ('pre-build-commands', None), - ('build-commands', None), - ('post-build-commands', None), - ('pre-test-commands', None), - ('test-commands', None), - ('post-test-commands', None), - ('pre-install-commands', None), - ('install-commands', None), - ('post-install-commands', None), - ('devices', None), - ('products', []), - ('max-jobs', None), - ('build-system', 'manual') - ], - 'stratum': [ - ('chunks', []), - ('description', ''), - ('build-depends', None), - ], - 'system': [ - ('strata', []), - ('description', ''), - ('arch', None), - ('configuration-extensions', []), - ], - 'cluster': [ - ('description', ''), - ], - } - - @staticmethod - def _load_json(text): - return json.loads(text, object_pairs_hook=OrderedDict, - encoding='unicode-escape') - - @staticmethod - def _dump_json(obj, f): - text = json.dumps(obj, indent=4, encoding='unicode-escape') - text = re.sub(" \n", "\n", text) - f.write(text) - f.write('\n') - - def __init__(self, text): - self._dict, self._dumper = self._load_morphology_dict(text) - self._set_defaults() - self._validate_children() - - def __getitem__(self, key): - return self._dict[key] - - def __contains__(self, key): - return key in self._dict - - # Not covered by tests, since it's trivial, morph2 is going away - # and only exists so the new morphology validation code can use it. - def get(self, key, default=None): # pragma: no cover - try: - return self[key] - except KeyError: - return default - - def get_commands(self, which): - '''Return the commands to run from a morphology or the build system''' - if self[which] is None: - attr = '_'.join(which.split('-')) - bs = morphlib.buildsystem.lookup_build_system(self['build-system']) - return getattr(bs, attr) - else: - return self[which] - - def keys(self): - return self._dict.keys() - - def _load_morphology_dict(self, text): - '''Load morphology, identifying whether it is JSON or YAML''' - - try: - data = self._load_json(text) - dumper = self._dump_json - except ValueError as e: # pragma: no cover - data = morphlib.yamlparse.load(text) - dumper = morphlib.yamlparse.dump - - if data is None: - raise morphlib.YAMLError("Morphology is empty") - if type(data) not in [dict, OrderedDict]: - raise morphlib.YAMLError("Morphology did not parse as a dict") - - return data, dumper - - def _validate_children(self): - if self['kind'] == 'system': - names = set() - for info in self['strata']: - name = info.get('alias', info['morph']) - if name in names: - raise ValueError('Duplicate stratum "%s"' % name) - names.add(name) - elif self['kind'] == 'stratum': - names = set() - for info in self['chunks']: - name = info.get('alias', info['name']) - if name in names: - raise ValueError('Duplicate chunk "%s"' % name) - names.add(name) - elif self['kind'] == 'cluster': - if not 'systems' in self: - raise KeyError('"systems" not found') - if not self['systems']: - raise ValueError('"systems" is empty') - for system in self['systems']: - if 'morph' not in system: - raise KeyError('"morph" not found') - if 'deploy-defaults' in system: - if not isinstance(system['deploy-defaults'], dict): - raise ValueError('deploy defaults for morph "%s" ' - 'are not a mapping: %r' - % (system['morph'], - system['deploy-defaults'])) - if 'deploy' in system: - for system_id, deploy_params in system['deploy'].items(): - if not isinstance(deploy_params, dict): - raise ValueError('deployment parameters for ' - 'system "%s" are not a mapping:' - ' %r' - % (system_id, deploy_params)) - - def _set_default_value(self, target_dict, key, value): - '''Change a value in the in-memory representation of the morphology - - Record the default value separately, so that when writing out the - morphology we can determine whether the change from the on-disk value - was done at load time, or later on (we want to only write back out - the later, deliberate changes). - - ''' - target_dict[key] = value - target_dict['_orig_' + key] = value - - def _set_defaults(self): - if 'max-jobs' in self: - self._set_default_value(self._dict, 'max-jobs', - int(self['max-jobs'])) - - for name, value in self.static_defaults[self['kind']]: - if name not in self._dict: - self._set_default_value(self._dict, name, value) - - if self['kind'] == 'stratum': - self._set_stratum_defaults() - elif self['kind'] == 'cluster': - self._set_cluster_defaults() - - def _set_stratum_defaults(self): - for source in self['chunks']: - if 'repo' not in source: - self._set_default_value(source, 'repo', source['name']) - if 'build-depends' not in source: - self._set_default_value(source, 'build-depends', None) - if 'build-mode' not in source: - self._set_default_value(source, 'build-mode', 'staging') - if 'prefix' not in source: - self._set_default_value(source, 'prefix', '/usr') - - def _set_cluster_defaults(self): - if 'systems' in self and self['systems']: - for system in self['systems']: - if 'deploy-defaults' not in system: - self._set_default_value(system, - 'deploy-defaults', - dict()) - if 'deploy' not in system: - self._set_default_value(system, - 'deploy', - dict()) - - def lookup_child_by_name(self, name): - '''Find child reference by its name. - - This lookup honors aliases. - - ''' - - if self['kind'] == 'system': - for info in self['strata']: - source_name = info.get('alias', info['morph']) - if source_name == name: - return info - elif self['kind'] == 'stratum': - for info in self['chunks']: - source_name = info.get('alias', info['name']) - if source_name == name: - return info - raise KeyError('"%s" not found' % name) - - def _apply_changes(self, live_dict, original_dict): - '''Returns a new dict updated with changes from the in-memory object - - This allows us to write out a morphology including only the changes - that were done after the morphology was loaded -- not the changes done - to set default values during construction. - - ''' - output_dict = {} - - for key in live_dict.keys(): - if key.startswith('_orig_'): - continue - - value = self._apply_changes_for_key(key, live_dict, original_dict) - # VILE HACK to preserve nulls in repo/ref fields - if value is not None or key in ('repo', 'ref'): - output_dict[key] = value - return output_dict - - def _apply_changes_for_key(self, key, live_dict, original_dict): - '''Return value to write out for one key, recursing if necessary''' - - live_value = live_dict.get(key, None) - orig_value = original_dict.get(key, None) - - if type(live_value) in [dict, OrderedDict] and orig_value is not None: - # Recursively apply changes for dict - result = self._apply_changes(live_value, orig_value) - elif type(live_value) is list and orig_value is not None: - # Recursively apply changes for list (existing, then new items). - result = [] - for i in range(0, min(len(orig_value), len(live_value))): - if type(live_value[i]) in [dict, OrderedDict]: - item = self._apply_changes(live_value[i], orig_value[i]) - else: - item = live_value[i] - result.append(item) - for i in range(len(orig_value), len(live_value)): - if type(live_value[i]) in [dict, OrderedDict]: - item = self._apply_changes(live_value[i], {}) - else: - item = live_value[i] - result.append(item) - else: - # Simple values. Use original value unless it has been changed from - # the default in memmory. - if live_dict[key] == live_dict.get('_orig_' + key, None): - result = original_dict.get(key, None) - else: - result = live_dict[key] - return result - - def update_text(self, text, output_fd, convert_to=None): - '''Write out in-memory changes to loaded morphology text - - Similar in function to update_file(). - - ''' - original_dict, dumper = self._load_morphology_dict(text) - - if convert_to == 'json': # pragma: no cover - dumper = self._dump_json - elif convert_to == 'yaml': # pragma: no cover - dumper = morphlib.yamlparse.dump - - output_dict = self._apply_changes(self._dict, original_dict) - dumper(output_dict, output_fd) - - def update_file(self, filename, output_fd=None, **kws): # pragma: no cover - '''Write out in-memory changes to on-disk morphology file - - This function reads the original morphology text from 'filename', so - that it can avoid writing out properties that are set in memory - to their default value but weren't specified by the user at all. - - ''' - with open(filename, 'r') as f: - text = f.read() - - with output_fd or morphlib.savefile.SaveFile(filename, 'w') as f: - self.update_text(text, f, **kws) diff --git a/morphlib/morph2_tests.py b/morphlib/morph2_tests.py deleted file mode 100644 index c9957ad5..00000000 --- a/morphlib/morph2_tests.py +++ /dev/null @@ -1,391 +0,0 @@ -# Copyright (C) 2012-2014 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -import copy -import json -import StringIO -import unittest - -import yaml - -import morphlib -from morphlib.morph2 import Morphology - - -class MorphologyTests(unittest.TestCase): - - def test_parses_simple_json_chunk(self): - m = Morphology(''' - { - "name": "foo", - "kind": "chunk", - "build-system": "manual" - } - ''') - - self.assertEqual(m['name'], 'foo') - self.assertEqual(m['kind'], 'chunk') - self.assertEqual(m['build-system'], 'manual') - self.assertEqual(m['pre-configure-commands'], None) - self.assertEqual(m['configure-commands'], None) - self.assertEqual(m['post-configure-commands'], None) - self.assertEqual(m['pre-build-commands'], None) - self.assertEqual(m['build-commands'], None) - self.assertEqual(m['post-build-commands'], None) - self.assertEqual(m['pre-test-commands'], None) - self.assertEqual(m['test-commands'], None) - self.assertEqual(m['post-test-commands'], None) - self.assertEqual(m['pre-install-commands'], None) - self.assertEqual(m['install-commands'], None) - self.assertEqual(m['post-install-commands'], None) - self.assertEqual(m['max-jobs'], None) - self.assertEqual(m['products'], []) - - if morphlib.got_yaml: - def test_parses_simple_yaml_chunk(self): - m = Morphology(''' - name: foo - kind: chunk - build-system: manual - ''') - - self.assertEqual(m['name'], 'foo') - self.assertEqual(m['kind'], 'chunk') - self.assertEqual(m['build-system'], 'manual') - self.assertEqual(m['pre-configure-commands'], None) - self.assertEqual(m['configure-commands'], None) - self.assertEqual(m['post-configure-commands'], None) - self.assertEqual(m['pre-build-commands'], None) - self.assertEqual(m['build-commands'], None) - self.assertEqual(m['post-build-commands'], None) - self.assertEqual(m['pre-test-commands'], None) - self.assertEqual(m['test-commands'], None) - self.assertEqual(m['post-test-commands'], None) - self.assertEqual(m['pre-install-commands'], None) - self.assertEqual(m['install-commands'], None) - self.assertEqual(m['post-install-commands'], None) - self.assertEqual(m['max-jobs'], None) - self.assertEqual(m['products'], []) - - def test_sets_stratum_chunks_repo_and_morph_from_name(self): - m = Morphology(''' - { - "name": "foo", - "kind": "stratum", - "chunks": [ - { - "name": "le-chunk", - "ref": "ref" - } - ] - } - ''') - - self.assertEqual(m['chunks'][0]['repo'], 'le-chunk') - self.assertEqual(m['chunks'][0]['build-depends'], None) - - def test_returns_dict_keys(self): - m = Morphology(''' - { - "name": "foo", - "kind": "system", - } - ''') - - self.assertTrue('name' in m.keys()) - self.assertTrue('kind' in m.keys()) - - def test_system_indexes_strata(self): - m = Morphology(''' - { - "kind": "system", - "strata": [ - { - "morph": "stratum1", - "repo": "repo", - "ref": "ref" - }, - { - "alias": "aliased-stratum", - "morph": "stratum2", - "repo": "repo", - "ref": "ref" - } - ] - } - ''') - self.assertEqual(m.lookup_child_by_name('stratum1'), - {'morph': 'stratum1', 'repo': 'repo', 'ref': 'ref' }) - self.assertEqual(m.lookup_child_by_name('aliased-stratum'), - {'alias': 'aliased-stratum', 'morph': 'stratum2', - 'repo': 'repo', 'ref': 'ref'}) - - def test_stratum_indexes_chunks(self): - m = Morphology(''' - { - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "repo", - "ref": "ref" - } - ] - } - ''') - - child = m.lookup_child_by_name('chunk') - self.assertEqual(child['name'], 'chunk') - self.assertEqual(child['repo'], 'repo') - self.assertEqual(child['ref'], 'ref') - - def test_raises_error_when_child_lookup_fails(self): - m = Morphology(''' - { - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "repo", - "ref": "ref" - } - ] - } - ''') - - self.assertRaises(KeyError, m.lookup_child_by_name, 'foo') - - ## Validation tests - - def test_not_empty(self): - self.assertRaises(morphlib.YAMLError, Morphology, '') - - def test_is_dict(self): - self.assertRaises(morphlib.YAMLError, Morphology, 'foo') - - def test_makes_max_jobs_be_an_integer(self): - m = Morphology(''' - { - "name": "foo", - "kind": "chunk", - "max-jobs": "42" - } - ''') - self.assertEqual(m['max-jobs'], 42) - - def test_stratum_names_must_be_unique_within_a_system(self): - text = ''' - { - "kind": "system", - "strata": [ - { - "morph": "stratum", - "repo": "test1", - "ref": "ref" - }, - { - "morph": "stratum", - "repo": "test2", - "ref": "ref" - } - ] - } - ''' - self.assertRaises(ValueError, - Morphology, - text) - - def test_chunk_names_must_be_unique_within_a_stratum(self): - text = ''' - { - "kind": "stratum", - "chunks": [ - { - "name": "chunk", - "repo": "test1", - "ref": "ref" - }, - { - "name": "chunk", - "repo": "test2", - "ref": "ref" - } - ] - } - ''' - self.assertRaises(ValueError, - Morphology, - text) - - ## Writing tests - - stratum_text = '''{ - "kind": "stratum", - "chunks": [ - { - "name": "foo", - "repo": "morphs", - "ref": "ref", - "build-depends": [] - }, - { - "name": "bar", - "repo": "morphs", - "ref": "ref", - "build-depends": [ - "foo" - ] - } - ] -}''' - - def test_writing_handles_added_chunks(self): - text_lines = self.stratum_text.splitlines() - text_lines = text_lines[0:16] + text_lines[8:17] + text_lines[17:] - text_lines[18] = ' "name": "baz",' - - # Add a new chunk to the list - morphology = Morphology(self.stratum_text) - morphology['chunks'].append(copy.copy(morphology['chunks'][1])) - morphology['chunks'][2]['name'] = 'baz' - - output = StringIO.StringIO() - morphology.update_text(self.stratum_text, output) - d = yaml.load(output.getvalue()) - self.assertEqual(d['chunks'][2]['name'], 'baz') - - def test_writing_handles_deleted_chunks(self): - text_lines = self.stratum_text.splitlines() - text_lines = text_lines[0:3] + text_lines[9:] - - # Delete a chunk - morphology = Morphology(self.stratum_text) - del morphology['chunks'][0] - - output = StringIO.StringIO() - morphology.update_text(self.stratum_text, output) - d = yaml.load(output.getvalue()) - self.assertEqual(len(d['chunks']), 1) - - system_text = '''{ - "kind": "system", - "arch": "x86_64", -}''' - - def test_nested_dict(self): - # Real morphologies don't trigger this code path, so we test manually - original_dict = { - 'dict': { '1': 'fee', '2': 'fie', '3': 'foe', '4': 'foo' } - } - live_dict = copy.deepcopy(original_dict) - live_dict['_orig_dict'] = live_dict['dict'] - - dummy = Morphology(self.stratum_text) - output_dict = dummy._apply_changes(live_dict, original_dict) - self.assertEqual(original_dict, output_dict) - - def test_uses_morphology_commands_when_given(self): - m = Morphology(''' - { - 'name': 'foo', - 'kind': 'chunk', - 'build-system': 'dummy', - 'build-commands': ['build-it'] - } - ''') - cmds = m.get_commands('build-commands') - self.assertEqual(cmds, ['build-it']) - - def test_uses_build_system_commands_when_morphology_doesnt(self): - m = Morphology(''' - { - 'name': 'foo', - 'kind': 'chunk', - 'build-system': 'dummy', - } - ''') - cmds = m.get_commands('build-commands') - self.assertEqual(cmds, ['echo dummy build']) - - def test_uses_morphology_commands_when_morphology_has_empty_list(self): - m = Morphology(''' - { - 'name': 'foo', - 'kind': 'chunk', - 'build-system': 'dummy', - 'build-commands': [] - } - ''') - cmds = m.get_commands('build-commands') - self.assertEqual(cmds, []) - - ## Cluster morphologies tests - - def test_parses_simple_cluster_morph(self): - m = Morphology(''' - name: foo - kind: cluster - systems: - - morph: bar - ''') - self.assertEqual(m['name'], 'foo') - self.assertEqual(m['kind'], 'cluster') - self.assertEqual(m['systems'][0]['morph'], 'bar') - - def test_fails_without_systems(self): - text = ''' - name: foo - kind: cluster - ''' - self.assertRaises(KeyError, Morphology, text) - - def test_fails_with_empty_systems(self): - text = ''' - name: foo - kind: cluster - systems: - ''' - self.assertRaises(ValueError, Morphology, text) - - def test_fails_without_morph(self): - text = ''' - name: foo - kind: cluster - systems: - - deploy: - ''' - self.assertRaises(KeyError, Morphology, text) - - def test_fails_with_invalid_deploy_defaults(self): - text = ''' - name: foo - kind: cluster - systems: - - morph: bar - deploy-defaults: ooops_i_am_not_a_mapping - ''' - self.assertRaises(ValueError, Morphology, text) - - def test_fails_with_invalid_deployment_params(self): - text = ''' - name: foo - kind: cluster - systems: - - morph: bar - deploy: - qux: ooops_i_am_not_a_mapping - ''' - self.assertRaises(ValueError, Morphology, text) -- cgit v1.2.1 From 43fb9e05c2a22c01c2d432af9500b531106eda8d Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 15:16:20 +0000 Subject: Revert "Ensure that none of the _orig_* fields are in the cache key" This reverts commit 4124c50b8dc3dfb0ffb933153d0fe6385edf389c. This commit is no longer needed now that morph2 is gone. Conflicts: morphlib/cachekeycomputer.py --- morphlib/cachekeycomputer.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/morphlib/cachekeycomputer.py b/morphlib/cachekeycomputer.py index 7cbce730..588fc8d3 100644 --- a/morphlib/cachekeycomputer.py +++ b/morphlib/cachekeycomputer.py @@ -122,10 +122,7 @@ class CacheKeyComputer(object): # products is omitted as they are part of the split-rules elif kind in ('system', 'stratum'): morphology = artifact.source.morphology - # Exclude fields starting with _orig_. This filtering can be - # removed once the morph2 code is gone. - morph_dict = dict((k, morphology[k]) for k in morphology.keys() - if not k.startswith('_orig_')) + morph_dict = dict((k, morphology[k]) for k in morphology.keys()) # Disregard all fields of a morphology that aren't important ignored_fields = ( -- cgit v1.2.1 From 5f705f1e2c95b988ae39df7820f4034c49f375e4 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 15:42:03 +0000 Subject: Rename morph3 to morphology Instead of leaving morph3 with a potentially confusing name, rename it to `morphology` since it is now the only implementation of the Morphology class. --- morphlib/__init__.py | 2 +- morphlib/morph3.py | 45 -------------------- morphlib/morph3_tests.py | 48 --------------------- morphlib/morphloader.py | 2 +- morphlib/morphloader_tests.py | 98 +++++++++++++++++++++---------------------- morphlib/morphology.py | 45 ++++++++++++++++++++ morphlib/morphology_tests.py | 48 +++++++++++++++++++++ morphlib/morphset_tests.py | 6 +-- 8 files changed, 147 insertions(+), 147 deletions(-) delete mode 100644 morphlib/morph3.py delete mode 100644 morphlib/morph3_tests.py create mode 100644 morphlib/morphology.py create mode 100644 morphlib/morphology_tests.py diff --git a/morphlib/__init__.py b/morphlib/__init__.py index a31cf04c..f98c11aa 100644 --- a/morphlib/__init__.py +++ b/morphlib/__init__.py @@ -70,7 +70,7 @@ import localrepocache import mountableimage import morphologyfactory import morphologyfinder -import morph3 +import morphology import morphloader import morphset import remoteartifactcache diff --git a/morphlib/morph3.py b/morphlib/morph3.py deleted file mode 100644 index 477cac1a..00000000 --- a/morphlib/morph3.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# =*= License: GPL-2 =*= - - -import UserDict - - -class Morphology(UserDict.IterableUserDict): - - '''A container for a morphology, plus its metadata. - - A morphology is, basically, a dict. This class acts as that dict, - plus stores additional metadata about the morphology, such as where - it came from, and the ref that was used for it. It also has a dirty - attribute, to indicate whether the morphology has had changes done - to it, but does not itself set that attribute: the caller has to - maintain the flag themselves. - - This class does NO validation of the data, nor does it parse the - morphology text, or produce a textual form of itself. For those - things, see MorphologyLoader. - - ''' - - def __init__(self, *args, **kwargs): - UserDict.IterableUserDict.__init__(self, *args, **kwargs) - self.repo_url = None - self.ref = None - self.filename = None - self.dirty = None - diff --git a/morphlib/morph3_tests.py b/morphlib/morph3_tests.py deleted file mode 100644 index e150bf33..00000000 --- a/morphlib/morph3_tests.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# =*= License: GPL-2 =*= - - -import unittest - -import morphlib - - -class MorphologyTests(unittest.TestCase): - - def setUp(self): - self.morph = morphlib.morph3.Morphology() - - def test_has_repo_url_attribute(self): - self.assertEqual(self.morph.repo_url, None) - self.morph.repo_url = 'foo' - self.assertEqual(self.morph.repo_url, 'foo') - - def test_has_ref_attribute(self): - self.assertEqual(self.morph.ref, None) - self.morph.ref = 'foo' - self.assertEqual(self.morph.ref, 'foo') - - def test_has_filename_attribute(self): - self.assertEqual(self.morph.filename, None) - self.morph.filename = 'foo' - self.assertEqual(self.morph.filename, 'foo') - - def test_has_dirty_attribute(self): - self.assertEqual(self.morph.dirty, None) - self.morph.dirty = True - self.assertEqual(self.morph.dirty, True) - diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index d06c06dc..05dcb62c 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -394,7 +394,7 @@ class MorphologyLoader(object): if not isinstance(obj, dict): raise NotADictionaryError(morph_filename) - return morphlib.morph3.Morphology(obj) + return morphlib.morphology.Morphology(obj) def load_from_string(self, string, filename='string'): '''Load a morphology from a string. diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index 738f1c32..d47ec750 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -59,21 +59,21 @@ build-system: dummy self.loader.parse_morphology_text, '- item1\n- item2\n', 'test') def test_fails_to_validate_dict_without_kind(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'invalid': 'field', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_chunk_with_no_fields(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_chunk_with_invalid_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', 'invalid': 'field', @@ -82,7 +82,7 @@ build-system: dummy morphlib.morphloader.InvalidFieldError, self.loader.validate, m) def test_validate_requires_products_list(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products={ @@ -98,7 +98,7 @@ build-system: dummy self.assertEqual(e.morphology_name, 'foo') def test_validate_requires_products_list_of_mappings(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -113,7 +113,7 @@ build-system: dummy self.assertEqual(e.morphology_name, 'foo') def test_validate_requires_products_list_required_fields(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -136,7 +136,7 @@ build-system: dummy self.assertEqual(exs[3].field, 'products[0].factiart') def test_validate_requires_products_list_include_is_list(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -154,7 +154,7 @@ build-system: dummy self.assertEqual(ex.morphology_name, 'foo') def test_validate_requires_products_list_include_is_list_of_strings(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -175,14 +175,14 @@ build-system: dummy def test_fails_to_validate_stratum_with_no_fields(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_stratum_with_invalid_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'invalid': 'field', @@ -191,7 +191,7 @@ build-system: dummy morphlib.morphloader.InvalidFieldError, self.loader.validate, m) def test_validate_requires_chunk_refs_in_stratum_to_be_strings(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'build-depends': [], @@ -209,7 +209,7 @@ build-system: dummy self.loader.validate(m) def test_fails_to_validate_stratum_with_empty_refs_for_a_chunk(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'build-depends': [], @@ -227,7 +227,7 @@ build-system: dummy self.loader.validate(m) def test_fails_to_validate_system_with_obsolete_system_kind_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'system', 'name': 'foo', 'arch': 'x86_64', @@ -240,7 +240,7 @@ build-system: dummy morphlib.morphloader.ObsoleteFieldsError, self.loader.validate, m) def test_fails_to_validate_system_with_obsolete_disk_size_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'system', 'name': 'foo', 'arch': 'x86_64', @@ -253,14 +253,14 @@ build-system: dummy morphlib.morphloader.ObsoleteFieldsError, self.loader.validate, m) def test_fails_to_validate_system_with_no_fields(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'system', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_system_with_invalid_field(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind="system", name="foo", arch="blah", @@ -272,14 +272,14 @@ build-system: dummy morphlib.morphloader.InvalidFieldError, self.loader.validate, m) def test_fails_to_validate_morphology_with_unknown_kind(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'invalid', }) self.assertRaises( morphlib.morphloader.UnknownKindError, self.loader.validate, m) def test_validate_requires_unique_stratum_names_within_a_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "kind": "system", "name": "foo", @@ -301,7 +301,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_unique_chunk_names_within_a_stratum(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "kind": "stratum", "name": "foo", @@ -322,7 +322,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_a_valid_architecture(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind="system", name="foo", arch="blah", @@ -334,7 +334,7 @@ build-system: dummy self.loader.validate, m) def test_validate_normalises_architecture_armv7_to_armv7l(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind="system", name="foo", arch="armv7", @@ -345,7 +345,7 @@ build-system: dummy self.assertEqual(m['arch'], 'armv7l') def test_validate_requires_build_deps_for_chunks_in_strata(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "kind": "stratum", "name": "foo", @@ -365,7 +365,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_build_deps_or_bootstrap_mode_for_strata(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "stratum-no-bdeps-no-bootstrap", "kind": "stratum", @@ -395,7 +395,7 @@ build-system: dummy self.loader.validate(m) def test_validate_requires_chunks_in_strata(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "stratum", "kind": "stratum", @@ -415,7 +415,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_strata_in_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch') @@ -425,7 +425,7 @@ build-system: dummy def test_validate_requires_list_of_strata_in_system(self): for v in (None, {}): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch', @@ -437,7 +437,7 @@ build-system: dummy self.assertEqual(cm.exception.strata_type, type(v)) def test_validate_requires_non_empty_strata_in_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch', @@ -447,7 +447,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_stratum_specs_in_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch', @@ -460,7 +460,7 @@ build-system: dummy def test_validate_requires_unique_deployment_names_in_cluster(self): subsystem = [{'morph': 'baz', 'deploy': {'foobar': None}}] - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='cluster', kind='cluster', systems=[{'morph': 'foo', @@ -513,7 +513,7 @@ build-system: dummy self.assertEqual(morph['build-system'], 'dummy') def test_saves_to_string(self): - morph = morphlib.morph3.Morphology({ + morph = morphlib.morphology.Morphology({ 'name': 'foo', 'kind': 'chunk', 'build-system': 'dummy', @@ -529,7 +529,7 @@ build-system: dummy ''') def test_saves_to_file(self): - morph = morphlib.morph3.Morphology({ + morph = morphlib.morphology.Morphology({ 'name': 'foo', 'kind': 'chunk', 'build-system': 'dummy', @@ -548,7 +548,7 @@ build-system: dummy ''') def test_validate_does_not_set_defaults(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', }) @@ -556,7 +556,7 @@ build-system: dummy self.assertEqual(sorted(m.keys()), sorted(['kind', 'name'])) def test_sets_defaults_for_chunks(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', }) @@ -594,7 +594,7 @@ build-system: dummy }) def test_unsets_defaults_for_chunks(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', 'build-system': 'manual', @@ -608,7 +608,7 @@ build-system: dummy }) def test_sets_defaults_for_strata(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'chunks': [ @@ -661,14 +661,14 @@ build-system: dummy } test_dict_with_build_depends = dict(test_dict) test_dict_with_build_depends["build-depends"] = [] - m = morphlib.morph3.Morphology(test_dict_with_build_depends) + m = morphlib.morphology.Morphology(test_dict_with_build_depends) self.loader.unset_defaults(m) self.assertEqual( dict(m), test_dict) def test_sets_defaults_for_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='system', name='foo', arch='testarch', @@ -696,7 +696,7 @@ build-system: dummy dict(m)) def test_unsets_defaults_for_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { 'description': '', 'kind': 'system', @@ -724,7 +724,7 @@ build-system: dummy }) def test_sets_defaults_for_cluster(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='foo', kind='cluster', systems=[ @@ -741,7 +741,7 @@ build-system: dummy 'deploy': {}}]) def test_unsets_defaults_for_cluster(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='foo', kind='cluster', description='', @@ -759,7 +759,7 @@ build-system: dummy {'morph': 'bar'}]) def test_sets_stratum_chunks_repo_from_name(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "foo", "kind": "stratum", @@ -777,7 +777,7 @@ build-system: dummy self.assertEqual(m['chunks'][0]['repo'], 'le-chunk') def test_collapses_stratum_chunks_repo_from_name(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "foo", "kind": "stratum", @@ -796,7 +796,7 @@ build-system: dummy self.assertTrue('repo' not in m['chunks'][0]) def test_convertes_max_jobs_to_an_integer(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "foo", "kind": "chunk", @@ -829,7 +829,7 @@ build-system: dummy def test_warns_when_systems_refer_to_strata_with_repo_or_ref(self): for obsolete_field in ('repo', 'ref'): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name="foo", kind="system", arch="testarch", @@ -852,7 +852,7 @@ build-system: dummy def test_warns_when_strata_refer_to_build_depends_with_repo_or_ref(self): for obsolete_field in ('repo', 'ref'): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { 'name': 'foo', 'kind': 'stratum', @@ -885,7 +885,7 @@ build-system: dummy def test_unordered_asciibetically_after_ordered(self): # We only get morphologies with arbitrary keys in clusters - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='foo', kind='cluster', systems=[ @@ -926,21 +926,21 @@ build-system: dummy self.assertEqual(s, self.loader.save_to_string(m)) def test_smoketest_multi_line_unicode(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name=u'foo', description=u'1 2 3\n4 5 6\n7 8 9\n', ) s = self.loader.save_to_string(m) def test_smoketest_multi_line_unicode_encoded(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name=u'foo \u263A'.encode('utf-8'), description=u'1 \u263A\n2 \u263A\n3 \u263A\n'.encode('utf-8'), ) s = self.loader.save_to_string(m) def test_smoketest_binary_garbage(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( description='\x92', ) s = self.loader.save_to_string(m) diff --git a/morphlib/morphology.py b/morphlib/morphology.py new file mode 100644 index 00000000..314c315a --- /dev/null +++ b/morphlib/morphology.py @@ -0,0 +1,45 @@ +# Copyright (C) 2013-2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# =*= License: GPL-2 =*= + + +import UserDict + + +class Morphology(UserDict.IterableUserDict): + + '''A container for a morphology, plus its metadata. + + A morphology is, basically, a dict. This class acts as that dict, + plus stores additional metadata about the morphology, such as where + it came from, and the ref that was used for it. It also has a dirty + attribute, to indicate whether the morphology has had changes done + to it, but does not itself set that attribute: the caller has to + maintain the flag themselves. + + This class does NO validation of the data, nor does it parse the + morphology text, or produce a textual form of itself. For those + things, see MorphologyLoader. + + ''' + + def __init__(self, *args, **kwargs): + UserDict.IterableUserDict.__init__(self, *args, **kwargs) + self.repo_url = None + self.ref = None + self.filename = None + self.dirty = None + diff --git a/morphlib/morphology_tests.py b/morphlib/morphology_tests.py new file mode 100644 index 00000000..385f62ee --- /dev/null +++ b/morphlib/morphology_tests.py @@ -0,0 +1,48 @@ +# Copyright (C) 2013-2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# =*= License: GPL-2 =*= + + +import unittest + +import morphlib + + +class MorphologyTests(unittest.TestCase): + + def setUp(self): + self.morph = morphlib.morphology.Morphology() + + def test_has_repo_url_attribute(self): + self.assertEqual(self.morph.repo_url, None) + self.morph.repo_url = 'foo' + self.assertEqual(self.morph.repo_url, 'foo') + + def test_has_ref_attribute(self): + self.assertEqual(self.morph.ref, None) + self.morph.ref = 'foo' + self.assertEqual(self.morph.ref, 'foo') + + def test_has_filename_attribute(self): + self.assertEqual(self.morph.filename, None) + self.morph.filename = 'foo' + self.assertEqual(self.morph.filename, 'foo') + + def test_has_dirty_attribute(self): + self.assertEqual(self.morph.dirty, None) + self.morph.dirty = True + self.assertEqual(self.morph.dirty, True) + diff --git a/morphlib/morphset_tests.py b/morphlib/morphset_tests.py index af1333d8..81b5810f 100644 --- a/morphlib/morphset_tests.py +++ b/morphlib/morphset_tests.py @@ -26,7 +26,7 @@ class MorphologySetTests(unittest.TestCase): def setUp(self): self.morphs = morphlib.morphset.MorphologySet() - self.system = morphlib.morph3.Morphology({ + self.system = morphlib.morphology.Morphology({ 'kind': 'system', 'name': 'foo-system', 'strata': [ @@ -41,7 +41,7 @@ class MorphologySetTests(unittest.TestCase): self.system.ref = 'master' self.system.filename = 'foo-system.morph' - self.stratum = morphlib.morph3.Morphology({ + self.stratum = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo-stratum', 'chunks': [ @@ -111,7 +111,7 @@ class MorphologySetTests(unittest.TestCase): }) def test_changes_stratum_ref_in_build_depends(self): - other_stratum = morphlib.morph3.Morphology({ + other_stratum = morphlib.morphology.Morphology({ 'name': 'other-stratum', 'kind': 'stratum', 'chunks': [], -- cgit v1.2.1