From a66fcd50281a92842b3dd77261b8afa6718a0c5e Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Tue, 12 May 2020 15:34:33 +0900 Subject: _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. --- buildstream/_project.py | 31 +++++++++++++++++++++++++++++++ buildstream/utils.py | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) 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) -- cgit v1.2.1