You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 08:22:56 UTC
[buildstream] 20/25: LATER: sandboxnone: use initial SandboxNone
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch aevri/win32_minimal
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 20a47f024620f57a9ef0415e290911034e0ac81b
Author: Angelos Evripiotis <je...@bloomberg.net>
AuthorDate: Tue Jul 16 14:20:21 2019 +0100
LATER: sandboxnone: use initial SandboxNone
---
src/buildstream/_platform/darwin.py | 4 +-
src/buildstream/_platform/win32.py | 4 +-
src/buildstream/sandbox/__init__.py | 1 +
src/buildstream/sandbox/_sandboxnone.py | 68 +++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/src/buildstream/_platform/darwin.py b/src/buildstream/_platform/darwin.py
index f235353..6c06cff 100644
--- a/src/buildstream/_platform/darwin.py
+++ b/src/buildstream/_platform/darwin.py
@@ -18,7 +18,7 @@
import os
import resource
-from ..sandbox import SandboxDummy
+from ..sandbox import SandboxNone
from .platform import Platform
@@ -62,7 +62,7 @@ class Darwin(Platform):
kwargs['dummy_reason'] = \
"OSXFUSE is not supported and there are no supported sandbox " + \
"technologies for MacOS at this time"
- return SandboxDummy(*args, **kwargs)
+ return SandboxNone(*args, **kwargs)
def _setup_dummy_sandbox(self):
self.check_sandbox_config = Darwin._check_dummy_sandbox_config
diff --git a/src/buildstream/_platform/win32.py b/src/buildstream/_platform/win32.py
index 128f1ed..dd070ff 100644
--- a/src/buildstream/_platform/win32.py
+++ b/src/buildstream/_platform/win32.py
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
-from ..sandbox import SandboxDummy
+from ..sandbox import SandboxNone
from .platform import Platform
@@ -48,7 +48,7 @@ class Win32(Platform):
@staticmethod
def _create_dummy_sandbox(*args, **kwargs):
kwargs['dummy_reason'] = "There are no supported sandbox technologies for Win32 at this time."
- return SandboxDummy(*args, **kwargs)
+ return SandboxNone(*args, **kwargs)
def _setup_dummy_sandbox(self):
self.check_sandbox_config = Win32._check_dummy_sandbox_config
diff --git a/src/buildstream/sandbox/__init__.py b/src/buildstream/sandbox/__init__.py
index 5966d19..6544348 100644
--- a/src/buildstream/sandbox/__init__.py
+++ b/src/buildstream/sandbox/__init__.py
@@ -20,3 +20,4 @@
from .sandbox import Sandbox, SandboxFlags, SandboxCommandError
from ._sandboxremote import SandboxRemote
from ._sandboxdummy import SandboxDummy
+from ._sandboxnone import SandboxNone
diff --git a/src/buildstream/sandbox/_sandboxnone.py b/src/buildstream/sandbox/_sandboxnone.py
new file mode 100644
index 0000000..f8a2bda
--- /dev/null
+++ b/src/buildstream/sandbox/_sandboxnone.py
@@ -0,0 +1,68 @@
+#
+# Copyright (C) 2019 Bloomberg Finance LP
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+# Authors:
+# Angelos Evripiotis <je...@bloomberg.net>
+
+import pathlib
+import pprint
+import subprocess
+
+from .._exceptions import SandboxError
+from .sandbox import Sandbox
+
+
+class SandboxNone(Sandbox):
+
+ def __init__(self, *args, **kwargs):
+ # TODO: don't require a dict copy.
+ kwargs = kwargs.copy()
+ kwargs['allow_real_directory'] = True
+
+ super().__init__(*args, **kwargs)
+
+ uid = self._get_config().build_uid
+ gid = self._get_config().build_gid
+ if uid != 0 or gid != 0:
+ raise SandboxError("Chroot sandboxes cannot specify a non-root uid/gid "
+ "({},{} were supplied via config)".format(uid, gid))
+
+ self.mount_map = None
+
+ def _run(self, command, flags, *, cwd, env):
+
+ install_path = pathlib.Path(self.get_directory()) / 'buildstream-install'
+
+ env = env.copy()
+ env['BST_INSTALLPATH'] = str(install_path)
+
+ # TODO: figure out what to do with 'flags'.
+
+ # TODO: do this in a robust way.
+ if cwd.startswith("/"):
+ cwd = cwd[1:]
+
+ # pprint.pprint(env)
+
+ path = pathlib.Path(self.get_directory()) / cwd
+ print('run', command, 'in', path)
+ #result = subprocess.run(command, cwd=path, env=env)
+ result = subprocess.run(command, cwd=path)
+
+ # out = pathlib.Path(self.get_directory()) / 'buildstream-install'
+ # out.mkdir(exist_ok=True)
+
+ return result.returncode