diff options
author | Will Salmon <will.salmon@codethink.co.uk> | 2018-08-17 10:51:38 +0000 |
---|---|---|
committer | Will Salmon <will.salmon@codethink.co.uk> | 2018-08-17 10:51:38 +0000 |
commit | c43af4eb92c453c549dc185090ff5cd80035c3ec (patch) | |
tree | 1eb10810596fb8880f83dc56c77c820a71118c1b | |
parent | c102b92fe4a3f1c71a77629a57a9838b83ee19b8 (diff) | |
parent | d5ed4f45dd618236b19b54ea37edaeea89bdaafb (diff) | |
download | buildstream-c43af4eb92c453c549dc185090ff5cd80035c3ec.tar.gz |
Merge branch 'willsalmon/APIFix' into 'master'
Updating the no track or ref fix to match the buildstream style
See merge request BuildStream/buildstream!628
-rw-r--r-- | buildstream/_pipeline.py | 19 | ||||
-rw-r--r-- | buildstream/plugins/sources/git.py | 7 | ||||
-rw-r--r-- | buildstream/plugins/sources/ostree.py | 6 | ||||
-rw-r--r-- | tests/sources/git.py | 41 | ||||
-rw-r--r-- | tests/sources/ostree.py | 57 | ||||
-rw-r--r-- | tests/sources/ostree/template/project.conf | 2 | ||||
-rw-r--r-- | tests/sources/ostree/template/repofiles/file | 0 |
7 files changed, 101 insertions, 31 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index f1e51a05e..cc462c21a 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -359,23 +359,14 @@ class Pipeline(): if inconsistent: detail = "Exact versions are missing for the following elements:\n\n" - - missingTrack = 0 for element in inconsistent: - detail += " " + element._get_full_name() + detail += " Element: {} is inconsistent\n".format(element._get_full_name()) for source in element.sources(): - if not source._get_consistency() and not source.get_ref(): - if hasattr(source, 'tracking') and source.tracking is None: - detail += ": Source {} is missing ref and track. ".format(source._get_full_name()) + \ - "Please specify a ref or branch/tag to track." - missingTrack = 1 - - detail += "\n" + if source._get_consistency() == Consistency.INCONSISTENT: + detail += " Source {} is missing ref\n".format(source) + detail += '\n' + detail += "Try tracking these elements first with `bst track`\n" - if missingTrack: - detail += "\nThen track these elements with `bst track`\n" - else: - detail += "\nTry tracking these elements first with `bst track`\n" raise PipelineError("Inconsistent pipeline", detail=detail, reason="inconsistent-pipeline") ############################################################# diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py index 855e766d2..b3bc9cac7 100644 --- a/buildstream/plugins/sources/git.py +++ b/buildstream/plugins/sources/git.py @@ -309,6 +309,13 @@ class GitSource(Source): self.original_url = self.node_get_member(node, str, 'url') self.mirror = GitMirror(self, '', self.original_url, ref) self.tracking = self.node_get_member(node, str, 'track', None) + + # At this point we now know if the source has a ref and/or a track. + # If it is missing both then we will be unable to track or build. + if self.mirror.ref is None and self.tracking is None: + raise SourceError("{}: Git sources require a ref and/or track".format(self), + reason="missing-track-and-ref") + self.checkout_submodules = self.node_get_member(node, bool, 'checkout-submodules', True) self.submodules = [] diff --git a/buildstream/plugins/sources/ostree.py b/buildstream/plugins/sources/ostree.py index 6266731bf..526a91aa0 100644 --- a/buildstream/plugins/sources/ostree.py +++ b/buildstream/plugins/sources/ostree.py @@ -73,6 +73,12 @@ class OSTreeSource(Source): self.mirror = os.path.join(self.get_mirror_directory(), utils.url_directory_name(self.original_url)) + # At this point we now know if the source has a ref and/or a track. + # If it is missing both then we will be unable to track or build. + if self.ref is None and self.tracking is None: + raise SourceError("{}: OSTree sources require a ref and/or track".format(self), + reason="missing-track-and-ref") + # (optional) Not all repos are signed. But if they are, get the gpg key self.gpg_key_path = None if self.node_get_member(node, str, 'gpg-key', None): diff --git a/tests/sources/git.py b/tests/sources/git.py index ef18e3ce3..781d6d4d1 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -1,3 +1,25 @@ +# +# Copyright (C) 2018 Codethink Limited +# Copyright (C) 2018 Bloomberg Finance LP +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. +# +# Authors: Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> +# Jonathan Maw <jonathan.maw@codethink.co.uk> +# William Salmon <will.salmon@codethink.co.uk> +# + import os import pytest @@ -383,21 +405,6 @@ def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): _yaml.dump(element, os.path.join(project, 'target.bst')) # Track will encounter an inconsistent submodule without any ref - result = cli.run(project=project, args=['track', 'target.bst']) - result.assert_main_error(ErrorDomain.STREAM, None) - result.assert_task_error(ErrorDomain.SOURCE, 'track-attempt-no-track') - - # Assert that we are just fine without it, and emit a warning to the user. - assert "FAILURE git source at" in result.stderr - assert "Without a tracking branch ref can not be updated. Please " + \ - "provide a ref or a track." in result.stderr - - # Track will encounter an inconsistent submodule without any ref - result = cli.run(project=project, args=['build', 'target.bst']) - result.assert_main_error(ErrorDomain.PIPELINE, 'inconsistent-pipeline') + result = cli.run(project=project, args=['show', 'target.bst']) + result.assert_main_error(ErrorDomain.SOURCE, "missing-track-and-ref") result.assert_task_error(None, None) - - # Assert that we are just fine without it, and emit a warning to the user. - assert "Exact versions are missing for the following elements" in result.stderr - assert "is missing ref and track." in result.stderr - assert "Then track these elements with `bst track`" in result.stderr diff --git a/tests/sources/ostree.py b/tests/sources/ostree.py new file mode 100644 index 000000000..e059a882f --- /dev/null +++ b/tests/sources/ostree.py @@ -0,0 +1,57 @@ +# +# Copyright (C) 2018 Bloomberg Finance LP +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. +# +# Authors: William Salmon <will.salmon@codethink.co.uk> +# + +import os +import pytest + +from buildstream._exceptions import ErrorDomain +from buildstream import _yaml + +from tests.testutils import cli, create_repo + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'ostree', +) + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) +def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + + # Create the repo from 'repofiles' subdir + repo = create_repo('ostree', str(tmpdir)) + ref = repo.create(os.path.join(project, 'repofiles')) + + # Write out our test target + ostreesource = repo.source_config(ref=None) + ostreesource.pop('track') + element = { + 'kind': 'import', + 'sources': [ + ostreesource + ] + } + + _yaml.dump(element, os.path.join(project, 'target.bst')) + + # Track will encounter an inconsistent submodule without any ref + result = cli.run(project=project, args=['show', 'target.bst']) + result.assert_main_error(ErrorDomain.SOURCE, "missing-track-and-ref") + result.assert_task_error(None, None) diff --git a/tests/sources/ostree/template/project.conf b/tests/sources/ostree/template/project.conf new file mode 100644 index 000000000..afa0f5475 --- /dev/null +++ b/tests/sources/ostree/template/project.conf @@ -0,0 +1,2 @@ +# Basic project +name: foo diff --git a/tests/sources/ostree/template/repofiles/file b/tests/sources/ostree/template/repofiles/file new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/sources/ostree/template/repofiles/file |