diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-05-12 16:09:29 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-05-12 18:56:16 +0900 |
commit | f4200ae4e79eaa7d563ad77a4917ee59f0b789ea (patch) | |
tree | 4d8b394fef388d28735333469ebe18eef2c9f3f9 | |
parent | 27a0254faee23d8328ee5e0add06956abb4c67bb (diff) | |
download | buildstream-f4200ae4e79eaa7d563ad77a4917ee59f0b789ea.tar.gz |
_plugincontext.py: Add plugin version assertion for non BuildStream 1 plugins.
From BuildStream 2, we added BST_MIN_VERSION which must be specified by
all plugins. This new assertion in BuildStream 1 detects the presence of this
in order to issue an early assertion informing the user that they should
use BuildStream 1 plugins for BuildStream 1 projects.
-rw-r--r-- | buildstream/_plugincontext.py | 26 | ||||
-rw-r--r-- | buildstream/utils.py | 8 |
2 files changed, 32 insertions, 2 deletions
diff --git a/buildstream/_plugincontext.py b/buildstream/_plugincontext.py index 5a7097485..10e32e58a 100644 --- a/buildstream/_plugincontext.py +++ b/buildstream/_plugincontext.py @@ -22,6 +22,7 @@ import inspect from ._exceptions import PluginError, LoadError, LoadErrorReason from . import utils +from .utils import UtilError # A Context for loading plugin types @@ -223,6 +224,31 @@ class PluginContext(): plugin_type.BST_REQUIRED_VERSION_MAJOR, plugin_type.BST_REQUIRED_VERSION_MINOR)) + # If a BST_MIN_VERSION was specified, then we need to raise an error + # that we are loading a plugin which targets the wrong BuildStream version. + # + try: + min_version = plugin_type.BST_MIN_VERSION + except AttributeError: + return + + # Handle malformed version string specified by plugin + # + try: + major, minor = utils._parse_version(min_version) + except UtilError as e: + raise PluginError( + "Loaded plugin '{}' is not a BuildStream 1 plugin".format(kind), + detail="Error parsing BST_MIN_VERSION: {}".format(e), + reason="plugin-version-mismatch" + ) from e + + raise PluginError( + "Loaded plugin '{}' is a BuildStream {} plugin".format(kind, major), + detail="You need to use BuildStream 1 plugins with BuildStream 1 projects", + reason="plugin-version-mismatch" + ) + # _assert_plugin_format() # # Helper to raise a PluginError if the loaded plugin is of a lesser version then diff --git a/buildstream/utils.py b/buildstream/utils.py index 3a2372262..f141cb15d 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -1222,11 +1222,15 @@ def _deduplicate(iterable, key=None): # def _parse_version(version): - versions = version.split(".") + try: + versions = version.split(".") + except AttributeError as e: + raise UtilError("Malformed version string: {}".format(version),) + try: major = int(versions[0]) minor = int(versions[1]) except (IndexError, ValueError): raise UtilError("Malformed version string: {}".format(version),) - return (major, minor) + return major, minor |