summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-12-05 15:01:27 +0900
committerTristan van Berkom <tristan.vanberkom@codethink.co.uk>2019-08-03 22:18:16 -0400
commit3e3061e8903dd8d2135c965093cd9f26429d281e (patch)
tree32eadf614ea392754caf2fc99be3dde78903f7b5
parentc969fc86b2331be29055c1ffbb28589e5f990a85 (diff)
downloadbuildstream-3e3061e8903dd8d2135c965093cd9f26429d281e.tar.gz
git source plugin: Implementing submodule warnings
o Unlisted submodule warning Now the git plugin will issue a configurable warning if a submodule exists and is used (checking out the submodule is not disabled), but is not specified in the source configuration. o Invalid submodule warning Now the git source plugin will issue a warning if the configuration specified a submodule which does not exist in the underlying git repository. As a side effect, this patch also changes the flow control of the git plugin such that submodules which are explicitly set to not be checked out, are also not fetched but instead ignored completely.
-rw-r--r--buildstream/_versions.py2
-rw-r--r--buildstream/plugins/sources/git.py79
2 files changed, 73 insertions, 8 deletions
diff --git a/buildstream/_versions.py b/buildstream/_versions.py
index e4d503929..e55296513 100644
--- a/buildstream/_versions.py
+++ b/buildstream/_versions.py
@@ -23,7 +23,7 @@
# This version is bumped whenever enhancements are made
# to the `project.conf` format or the core element format.
#
-BST_FORMAT_VERSION = 16
+BST_FORMAT_VERSION = 17
# The base BuildStream artifact version
diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py
index 4b099b5ab..346c3ca21 100644
--- a/buildstream/plugins/sources/git.py
+++ b/buildstream/plugins/sources/git.py
@@ -72,7 +72,22 @@ git - stage files from a git repository
This plugin provides the following configurable warnings:
-- 'git:inconsistent-submodule' - A submodule was found to be missing from the underlying git repository.
+- ``git:inconsistent-submodule`` - A submodule present in the git repository's .gitmodules was never
+ added with `git submodule add`.
+
+- ``git:unlisted-submodule`` - A submodule is present in the git repository but was not specified in
+ the source configuration and was not disabled for checkout.
+
+ .. note::
+
+ The ``git:unlisted-submodule`` warning is available since :ref:`format version 20 <project_format_version>`
+
+- ``git:invalid-submodule`` - A submodule is specified in the source configuration but does not exist
+ in the repository.
+
+ .. note::
+
+ The ``git:invalid-submodule`` warning is available since :ref:`format version 20 <project_format_version>`
This plugin also utilises the following configurable core plugin warnings:
@@ -94,7 +109,9 @@ from buildstream.plugin import CoreWarnings
GIT_MODULES = '.gitmodules'
# Warnings
-INCONSISTENT_SUBMODULE = "inconsistent-submodules"
+WARN_INCONSISTENT_SUBMODULE = "inconsistent-submodule"
+WARN_UNLISTED_SUBMODULE = "unlisted-submodule"
+WARN_INVALID_SUBMODULE = "invalid-submodule"
# Because of handling of submodules, we maintain a GitMirror
@@ -312,7 +329,7 @@ class GitMirror(SourceFetcher):
"underlying git repository with `git submodule add`."
self.source.warn("{}: Ignoring inconsistent submodule '{}'"
- .format(self.source, submodule), detail=detail, warning_token=INCONSISTENT_SUBMODULE)
+ .format(self.source, submodule), detail=detail, warning_token=WARN_INCONSISTENT_SUBMODULE)
return None
@@ -475,6 +492,48 @@ class GitSource(Source):
for submodule in self.submodules:
yield submodule
+ def validate_cache(self):
+ discovered_submodules = {}
+ unlisted_submodules = []
+ invalid_submodules = []
+
+ for path, url in self.mirror.submodule_list():
+ discovered_submodules[path] = url
+ if self.ignore_submodule(path):
+ continue
+
+ override_url = self.submodule_overrides.get(path)
+ if not override_url:
+ unlisted_submodules.append((path, url))
+
+ # Warn about submodules which are explicitly configured but do not exist
+ for path, url in self.submodule_overrides.items():
+ if path not in discovered_submodules:
+ invalid_submodules.append((path, url))
+
+ if invalid_submodules:
+ detail = []
+ for path, url in invalid_submodules:
+ detail.append(" Submodule URL '{}' at path '{}'".format(url, path))
+
+ self.warn("{}: Invalid submodules specified".format(self),
+ warning_token=WARN_INVALID_SUBMODULE,
+ detail="The following submodules are specified in the source "
+ "description but do not exist according to the repository\n\n" +
+ "\n".join(detail))
+
+ # Warn about submodules which exist but have not been explicitly configured
+ if unlisted_submodules:
+ detail = []
+ for path, url in unlisted_submodules:
+ detail.append(" Submodule URL '{}' at path '{}'".format(url, path))
+
+ self.warn("{}: Unlisted submodules exist".format(self),
+ warning_token=WARN_UNLISTED_SUBMODULE,
+ detail="The following submodules exist but are not specified " +
+ "in the source description\n\n" +
+ "\n".join(detail))
+
###########################################################
# Local Functions #
###########################################################
@@ -499,10 +558,6 @@ class GitSource(Source):
self.mirror.ensure()
submodules = []
- # XXX Here we should issue a warning if either:
- # A.) A submodule exists but is not defined in the element configuration
- # B.) The element configuration configures submodules which dont exist at the current ref
- #
for path, url in self.mirror.submodule_list():
# Completely ignore submodules which are disabled for checkout
@@ -532,6 +587,16 @@ class GitSource(Source):
return not checkout
+ # Checks whether the plugin configuration has explicitly
+ # configured this submodule to be ignored
+ def ignore_submodule(self, path):
+ try:
+ checkout = self.submodule_checkout_overrides[path]
+ except KeyError:
+ checkout = self.checkout_submodules
+
+ return not checkout
+
# Plugin entry point
def setup():