diff options
author | William Salmon <will.salmon@codethink.co.uk> | 2018-08-14 09:57:15 +0100 |
---|---|---|
committer | William Salmon <will.salmon@codethink.co.uk> | 2018-08-17 10:48:01 +0100 |
commit | 9b6fac5ada7c2541da5666fa63160a7cea3dbe67 (patch) | |
tree | 5047089944b57d9c4b0ef620c42cf6a714c3a884 | |
parent | c102b92fe4a3f1c71a77629a57a9838b83ee19b8 (diff) | |
download | buildstream-9b6fac5ada7c2541da5666fa63160a7cea3dbe67.tar.gz |
Add Error to git and ostree sources configure
Raise a error at configure time if the track and ref properties are
not present in the sources.
This is to address https://gitlab.com/BuildStream/buildstream/issues/471
that documented unhelpful behaviour when tracking git sources. However
the issue was also identified in ostree.
-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 |
6 files changed, 96 insertions, 17 deletions
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 |