diff options
-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 |