summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Salmon <will.salmon@codethink.co.uk>2018-08-17 10:28:27 +0000
committerWill Salmon <will.salmon@codethink.co.uk>2018-08-17 10:28:27 +0000
commiteda495a5be098e575ecae9c4c8393cf0c0b36d69 (patch)
treee70e603c96701a14d9a9de47e86866a66061bcde
parent6c35850b535d7cc5f20d7c9178f7ac35a70ce727 (diff)
parent22b6fa21074650413a220ace7e68c8135e279142 (diff)
downloadbuildstream-eda495a5be098e575ecae9c4c8393cf0c0b36d69.tar.gz
Merge branch 'willsalmon/580-backport' into 'bst-1.2'
Add warning to git track if track and ref are not present See merge request BuildStream/buildstream!621
-rw-r--r--buildstream/_pipeline.py11
-rw-r--r--buildstream/plugins/sources/git.py7
-rw-r--r--buildstream/plugins/sources/ostree.py6
-rw-r--r--tests/sources/git.py49
-rw-r--r--tests/sources/ostree.py57
-rw-r--r--tests/sources/ostree/template/project.conf2
-rw-r--r--tests/sources/ostree/template/repofiles/file0
7 files changed, 129 insertions, 3 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py
index b74c7c302..2d3194f6b 100644
--- a/buildstream/_pipeline.py
+++ b/buildstream/_pipeline.py
@@ -358,10 +358,15 @@ class Pipeline():
inconsistent.append(element)
if inconsistent:
- detail = "Exact versions are missing for the following elements\n" + \
- "Try tracking these elements first with `bst track`\n\n"
+ detail = "Exact versions are missing for the following elements:\n\n"
for element in inconsistent:
- detail += " " + element._get_full_name() + "\n"
+ detail += " Element: {} is inconsistent\n".format(element._get_full_name())
+ for source in element.sources():
+ 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"
+
raise PipelineError("Inconsistent pipeline", detail=detail, reason="inconsistent-pipeline")
#############################################################
diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py
index b3cf903bf..56bf40e00 100644
--- a/buildstream/plugins/sources/git.py
+++ b/buildstream/plugins/sources/git.py
@@ -296,6 +296,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 06888c311..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
@@ -359,3 +381,30 @@ def test_submodule_track_ignore_inconsistent(cli, tmpdir, datafiles):
# Assert that we are just fine without it, and emit a warning to the user.
assert "Ignoring inconsistent submodule" in result.stderr
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@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('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+
+ # Write out our test target
+ gitsource = repo.source_config(ref=None)
+ gitsource.pop('track')
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ gitsource
+ ]
+ }
+
+ _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.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