From 61eb7d04e2cd11e56affc1a49feae5145e825ad5 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 4 Aug 2016 22:30:01 +0000 Subject: petrify all example Change-Id: Ia0315f76cb993d29e7cf20a89d13485f9d122024 --- morphlib/plugins/fix_ref_plugin.py | 113 +++++++------------------------------ 1 file changed, 20 insertions(+), 93 deletions(-) diff --git a/morphlib/plugins/fix_ref_plugin.py b/morphlib/plugins/fix_ref_plugin.py index 40130ad0..d06487f0 100644 --- a/morphlib/plugins/fix_ref_plugin.py +++ b/morphlib/plugins/fix_ref_plugin.py @@ -92,7 +92,7 @@ class FixRefPlugin(cliapp.Plugin): # bc = morphlib.buildcommand.BuildCommand(self.app) # root = bc.resolve_artifacts(source_pool) # print root - def unset_defaults(self, morphology): + def unset_defaults(morphology): '''If a field is equal to its default, delete it. The morphology is assumed to be valid. @@ -100,19 +100,32 @@ class FixRefPlugin(cliapp.Plugin): ''' kind = morphology['kind'] - defaults = morphlib.morphloader._static_defaults[kind] + defaults = morphlib.morphloader.MorphologyLoader._static_defaults[kind] for key in defaults: if key in morphology and morphology[key] == defaults[key]: - del morphology[key] - getattr(self, '_unset_%s_defaults' % kind)(morphology) + del morphology[key] + for spec in morphology['chunks']: + if 'repo' in spec and spec['repo'] == spec['name']: + del spec['repo'] + if 'build-mode' in spec and spec['build-mode'] == \ + morphlib.morphloader.MorphologyLoader._static_defaults['chunk']['build-mode']: + del spec['build-mode'] + if 'prefix' in spec and spec['prefix'] == \ + morphlib.morphloader.MorphologyLoader._static_defaults['chunk']['prefix']: + del spec['prefix'] + if 'submodules' in spec and spec['submodules'] == \ + morphlib.morphloader.MorphologyLoader._static_defaults['chunk']['submodules']: + del spec['submodules'] - for morph in definitions_repo.load_all_morphologies(): - print morph - print morph.filename + for morph in definitions_repo.load_all_morphologies(): + print morph['name'] if morph['kind'] != 'stratum': continue + # TODO for testing + if morph['name'] != "build-essential": + continue for chunk in morph['chunks']: repo = chunk.get('repo') ref = chunk.get('ref') @@ -125,92 +138,6 @@ class FixRefPlugin(cliapp.Plugin): loader.save_to_file(morph.filename, morph) - continue - # TODO: Handle refs that are only in workspace in general - if (repo == sb.root_repository_url - and ref == sb.system_branch_name): - continue - commit_sha1, tree_sha1 = self.app.resolve_ref( - lrc, rrc, repo, ref, update=update_repos) - - def _load_all_sysbranch_morphologies(root): - '''Read in all the morphologies in the root repository.''' - self.app.status(msg='Loading in all morphologies') - morphs = morphlib.morphset.MorphologySet() - for source in set(a.source for a in root.walk()): - morphs.add_morphology(source) - return morphs - - morphs = _load_all_sysbranch_morphologies(root) - for repo, ref in morphs.list_refs(): - print repo - #print morphs - - - for source in set(a.source for a in root.walk()): - if source.morphology['kind'] != 'stratum': - continue - - name = source.morphology['name'] - print name - ref = source.original_ref - print ref - print source.morphology - unpetrify = source.morphology['unpetrify-ref'] - print unpetrify - - - # Test that chunk has a sha1 ref - # TODO: Could allow either sha1 or existent tag. - if not morphlib.git.is_valid_sha1(ref): - warnings.warn('Chunk "{}" has non-sha1 ref: "{}"\n' - .format(name, ref)) - certified = False - - cached = self.repo_cache.get_updated_repo(source.repo_name, ref) - - # Test that sha1 ref is anchored in a tag or branch, - # and thus not a candidate for removal on `git gc`. - if (morphlib.git.is_valid_sha1(ref) and - not len(cached.tags_containing_sha1(ref)) and - not len(cached.branches_containing_sha1(ref))): - warnings.warn('Chunk "{}" has unanchored ref: "{}"\n' - .format(name, ref)) - certified = False - - -########### - - ws = morphlib.workspace.open('.') - sb = morphlib.sysbranchdir.open_from_within('.') - loader = morphlib.morphloader.MorphologyLoader() - lrc, rrc = morphlib.util.new_repo_caches(self.app) - update_repos = not self.app.settings['no-git-update'] - - morphs = self._load_all_sysbranch_morphologies(sb, loader) - - #TODO: Stop using app.resolve_ref - def resolve_refs(morphs): - for repo, ref in morphs.list_refs(): - # You can't resolve null refs, so don't attempt to. - if repo is None or ref is None: - continue - # TODO: Handle refs that are only in workspace in general - if (repo == sb.root_repository_url - and ref == sb.system_branch_name): - continue - commit_sha1, tree_sha1 = self.app.resolve_ref( - lrc, rrc, repo, ref, update=update_repos) - yield ((repo, ref), commit_sha1) - - morphs.repoint_refs(sb.root_repository_url, - sb.system_branch_name) - - morphs.petrify_chunks(dict(resolve_refs(morphs))) - - # Write morphologies back out again. - self._save_dirty_morphologies(loader, sb, morphs.morphologies) - def unfix(self, args): '''Reverse the process of petrification. -- cgit v1.2.1