diff options
author | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2019-07-24 10:38:35 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-24 12:27:10 +0000 |
commit | da2f04daf39963aaa6bc6c9385c80574395d8aeb (patch) | |
tree | cf7690e5ed5acdaadda93cdeb4e9ea489af4ed12 | |
parent | 3fcd62c32fdad8e107c5b1fd8cef56a00dcac435 (diff) | |
download | buildstream-da2f04daf39963aaa6bc6c9385c80574395d8aeb.tar.gz |
_platform: make picklable, no nested methods
Make the _platform implementations pickable by moving the nested
_setup_*_sandbox methods up into their enclosing classes.
-rw-r--r-- | src/buildstream/_platform/darwin.py | 22 | ||||
-rw-r--r-- | src/buildstream/_platform/fallback.py | 22 | ||||
-rw-r--r-- | src/buildstream/_platform/linux.py | 58 |
3 files changed, 53 insertions, 49 deletions
diff --git a/src/buildstream/_platform/darwin.py b/src/buildstream/_platform/darwin.py index e8c1ffaf3..f23535373 100644 --- a/src/buildstream/_platform/darwin.py +++ b/src/buildstream/_platform/darwin.py @@ -53,16 +53,18 @@ class Darwin(Platform): soft_limit = min(max(self.OPEN_MAX, old_soft_limit), hard_limit) resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit)) - def _setup_dummy_sandbox(self): - def _check_dummy_sandbox_config(config): - return True - self.check_sandbox_config = _check_dummy_sandbox_config + @staticmethod + def _check_dummy_sandbox_config(config): + return True - def _create_dummy_sandbox(*args, **kwargs): - kwargs['dummy_reason'] = \ - "OSXFUSE is not supported and there are no supported sandbox " + \ - "technologies for MacOS at this time" - return SandboxDummy(*args, **kwargs) - self.create_sandbox = _create_dummy_sandbox + @staticmethod + def _create_dummy_sandbox(*args, **kwargs): + kwargs['dummy_reason'] = \ + "OSXFUSE is not supported and there are no supported sandbox " + \ + "technologies for MacOS at this time" + return SandboxDummy(*args, **kwargs) + def _setup_dummy_sandbox(self): + self.check_sandbox_config = Darwin._check_dummy_sandbox_config + self.create_sandbox = Darwin._create_dummy_sandbox return True diff --git a/src/buildstream/_platform/fallback.py b/src/buildstream/_platform/fallback.py index 39669e0c2..4f7ff8086 100644 --- a/src/buildstream/_platform/fallback.py +++ b/src/buildstream/_platform/fallback.py @@ -21,17 +21,17 @@ from .platform import Platform class Fallback(Platform): - def _setup_dummy_sandbox(self): - def _check_dummy_sandbox_config(config): - return True - self.check_sandbox_config = _check_dummy_sandbox_config + def _check_dummy_sandbox_config(self, config): + return True - def _create_dummy_sandbox(*args, **kwargs): - kwargs['dummy_reason'] = \ - ("FallBack platform only implements dummy sandbox, " - "Buildstream may be having issues correctly detecting your platform, platform " - "can be forced with BST_FORCE_BACKEND") - return SandboxDummy(*args, **kwargs) - self.create_sandbox = _create_dummy_sandbox + def _create_dummy_sandbox(self, *args, **kwargs): + kwargs['dummy_reason'] = \ + ("FallBack platform only implements dummy sandbox, " + "Buildstream may be having issues correctly detecting your platform, " + "platform can be forced with BST_FORCE_BACKEND") + return SandboxDummy(*args, **kwargs) + def _setup_dummy_sandbox(self): + self.check_sandbox_config = self._check_dummy_sandbox_config + self.create_sandbox = self._create_dummy_sandbox return True diff --git a/src/buildstream/_platform/linux.py b/src/buildstream/_platform/linux.py index 3d85fdf34..b69dd456e 100644 --- a/src/buildstream/_platform/linux.py +++ b/src/buildstream/_platform/linux.py @@ -67,19 +67,28 @@ class Linux(Platform): # Private Methods # ################################################ - def _setup_dummy_sandbox(self): + @staticmethod + def _check_dummy_sandbox_config(config): + return True + + def _create_dummy_sandbox(self, *args, **kwargs): dummy_reasons = " and ".join(self.dummy_reasons) + kwargs['dummy_reason'] = dummy_reasons + return SandboxDummy(*args, **kwargs) - def _check_dummy_sandbox_config(config): - return True - self.check_sandbox_config = _check_dummy_sandbox_config + def _setup_dummy_sandbox(self): + self.check_sandbox_config = Linux._check_dummy_sandbox_config + self.create_sandbox = self._create_dummy_sandbox + return True - def _create_dummy_sandbox(*args, **kwargs): - kwargs['dummy_reason'] = dummy_reasons - return SandboxDummy(*args, **kwargs) - self.create_sandbox = _create_dummy_sandbox + def _check_sandbox_config_bwrap(self, config): + from ..sandbox._sandboxbwrap import SandboxBwrap + return SandboxBwrap.check_sandbox_config(self, config) - return True + def _create_bwrap_sandbox(self, *args, **kwargs): + from ..sandbox._sandboxbwrap import SandboxBwrap + kwargs['linux32'] = self.linux32 + return SandboxBwrap(*args, **kwargs) def _setup_bwrap_sandbox(self): from ..sandbox._sandboxbwrap import SandboxBwrap @@ -90,29 +99,22 @@ class Linux(Platform): SandboxBwrap._have_good_bwrap = None self._check_sandbox(SandboxBwrap) + self.check_sandbox_config = self._check_sandbox_config_bwrap + self.create_sandbox = self._create_bwrap_sandbox + return True - def _check_sandbox_config_bwrap(config): - return SandboxBwrap.check_sandbox_config(self, config) - self.check_sandbox_config = _check_sandbox_config_bwrap - - def _create_bwrap_sandbox(*args, **kwargs): - kwargs['linux32'] = self.linux32 - return SandboxBwrap(*args, **kwargs) - self.create_sandbox = _create_bwrap_sandbox + def _check_sandbox_config_chroot(self, config): + from ..sandbox._sandboxchroot import SandboxChroot + return SandboxChroot.check_sandbox_config(self, config) - return True + @staticmethod + def _create_chroot_sandbox(*args, **kwargs): + from ..sandbox._sandboxchroot import SandboxChroot + return SandboxChroot(*args, **kwargs) def _setup_chroot_sandbox(self): from ..sandbox._sandboxchroot import SandboxChroot - self._check_sandbox(SandboxChroot) - - def _check_sandbox_config_chroot(config): - return SandboxChroot.check_sandbox_config(self, config) - self.check_sandbox_config = _check_sandbox_config_chroot - - def _create_chroot_sandbox(*args, **kwargs): - return SandboxChroot(*args, **kwargs) - self.create_sandbox = _create_chroot_sandbox - + self.check_sandbox_config = self._check_sandbox_config_chroot + self.create_sandbox = Linux._create_chroot_sandbox return True |