From f14c4355ad02118a03317b0d76ead78c93ff2501 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrg=20Billeter?= <j@bitron.ch>
Date: Wed, 26 Sep 2018 10:08:25 +0100
Subject: [PATCH] Use lazy platform instantiation

Now that the platform is independent of the context, explicit
instantiation is no longer required. This avoids issues with platform
instances used across test cases with mismatching context.
---
 buildstream/_frontend/app.py      | 2 +-
 buildstream/_platform/platform.py | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index ddbb673bba..aea0daf5dc 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -198,7 +198,7 @@ class App():
             if option_value is not None:
                 setattr(self.context, context_attr, option_value)
         try:
-            Platform.create_instance()
+            Platform.get_platform()
         except BstError as e:
             self._error_exit(e, "Error instantiating platform")
 
diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py
index bbd2e65abe..b379649866 100644
--- a/buildstream/_platform/platform.py
+++ b/buildstream/_platform/platform.py
@@ -35,7 +35,7 @@ class Platform():
         pass
 
     @classmethod
-    def create_instance(cls, *args, **kwargs):
+    def _create_instance(cls):
         if sys.platform.startswith('linux'):
             backend = 'linux'
         else:
@@ -54,12 +54,12 @@ class Platform():
         else:
             raise PlatformError("No such platform: '{}'".format(backend))
 
-        cls._instance = PlatformImpl(*args, **kwargs)
+        cls._instance = PlatformImpl()
 
     @classmethod
     def get_platform(cls):
         if not cls._instance:
-            raise PlatformError("Platform needs to be initialized first")
+            cls._create_instance()
         return cls._instance
 
     ##################################################################
-- 
GitLab