diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-10-31 11:25:16 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2017-11-01 10:01:40 +0000 |
commit | d64ea749379100f61ed2c3342bcda4d8e5a46d71 (patch) | |
tree | 3e12bf841da3b2056aece86b03fa8611a1f79dde | |
parent | de35793125af66650568316c21b4a878b00ecb23 (diff) | |
download | buildstream-d64ea749379100f61ed2c3342bcda4d8e5a46d71.tar.gz |
Make the platform object a singleton
-rw-r--r-- | buildstream/_pipeline.py | 3 | ||||
-rw-r--r-- | buildstream/_platform/platform.py | 12 |
2 files changed, 11 insertions, 4 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 6f6d40fa2..69121a971 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -146,7 +146,8 @@ class Pipeline(): load_ticker(None) # Load selected platform - self.platform = Platform.get_platform(context, project) + Platform._create_instance(context, project) + self.platform = Platform.get_platform() self.artifacts = self.platform.artifactcache # Create the factories after resolving the project diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py index 920fddbde..d4b5f89a3 100644 --- a/buildstream/_platform/platform.py +++ b/buildstream/_platform/platform.py @@ -27,6 +27,7 @@ from .. import PlatformError, ProgramNotFoundError, ImplError class Platform(): + _instance = None # Platform() # @@ -42,8 +43,7 @@ class Platform(): self.project = project @classmethod - def get_platform(cls, *args, **kwargs): - + def _create_instance(cls, *args, **kwargs): if sys.platform.startswith('linux'): backend = 'linux' else: @@ -62,7 +62,13 @@ class Platform(): else: raise PlatformError("No such platform: '{}'".format(backend)) - return PlatformImpl(*args, **kwargs) + cls._instance = PlatformImpl(*args, **kwargs) + + @classmethod + def get_platform(cls, *args, **kwargs): + if not cls._instance: + raise PlatformError("Platform needs to be initialized first") + return cls._instance ################################################################## # Platform properties # |