summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-12 15:34:33 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-12 15:36:16 +0900
commita66fcd50281a92842b3dd77261b8afa6718a0c5e (patch)
treef2828685fdda7eff403794c5c07eebc5c807e134
parent6ef3094f8abaa568b3f5efe8ae2c2aa4d0054ec2 (diff)
downloadbuildstream-a66fcd50281a92842b3dd77261b8afa6718a0c5e.tar.gz
_project.py: Add check for projects not written for BuildStream 1.
This checks the `min-version` added in BuildStream 2 to raise an error to the user informing them of what BuildStream version they should use for this project. This also adds the _parse_version() utility to utils.py in order to properly report the BuildStream version specified by project.conf.
-rw-r--r--buildstream/_project.py31
-rw-r--r--buildstream/utils.py23
2 files changed, 54 insertions, 0 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py
index 5530aa23d..0f327c66d 100644
--- a/buildstream/_project.py
+++ b/buildstream/_project.py
@@ -401,6 +401,37 @@ class Project():
"Project requested format version {}, but BuildStream {}.{} only supports up until format version {}"
.format(format_version, major, minor, BST_FORMAT_VERSION))
+ # Since BuildStream 2, project.conf is required to specify min-version.
+ #
+ # Detect this and raise an error, indicating which major version of BuildStream
+ # should be used for this project.
+ #
+ min_version = _yaml.node_get(pre_config_node, str, 'min-version', default_value=None)
+ if min_version:
+
+ # Handle case of malformed min-version
+ #
+ try:
+ major, minor = utils._parse_version(min_version)
+ except UtilError as e:
+ raise LoadError(
+ LoadErrorReason.UNSUPPORTED_PROJECT,
+ "This is not a BuildStream 1 project: {}".format(e)
+ ) from e
+
+ # Raise a helpful error indicating what the user should do to
+ # use this project.
+ #
+ raise LoadError(
+ LoadErrorReason.UNSUPPORTED_PROJECT,
+ "Tried to load a BuildStream {} project with BuildStream 1".format(major),
+
+ # TODO: Include a link to the appropriate documentation for parallel
+ # installing different BuildStream versions.
+ #
+ detail="Please install at least BuildStream {}.{} to use this project".format(major, minor)
+ )
+
# FIXME:
#
# Performing this check manually in the absense
diff --git a/buildstream/utils.py b/buildstream/utils.py
index d02777897..3a2372262 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -1207,3 +1207,26 @@ def _deduplicate(iterable, key=None):
if k not in seen:
seen_add(k)
yield element
+
+
+# _parse_version():
+#
+# Args:
+# version (str): The file name from which to determine compression
+#
+# Returns:
+# A 2-tuple of form (major_version: int, minor_version: int)
+#
+# Raises:
+# UtilError: In the case of a malformed version string
+#
+def _parse_version(version):
+
+ versions = version.split(".")
+ try:
+ major = int(versions[0])
+ minor = int(versions[1])
+ except (IndexError, ValueError):
+ raise UtilError("Malformed version string: {}".format(version),)
+
+ return (major, minor)