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 07:49:49 UTC

[buildstream] 04/09: Artifact caches are now defined in platform.py

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch workspace_list_error_message
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit a88b155f1723064036d438678c8ae166153fb635
Author: knownexus <ph...@codethink.co.uk>
AuthorDate: Fri Sep 7 12:12:29 2018 +0100

    Artifact caches are now defined in platform.py
    
    This was done so a default exists, but allows platforms to override as needed
    
    _platform/platform.py: Added CAS call function
    
    _platform/linux.py: Added override to CAS call
    _platform/unix.py: Remove CAS call
---
 buildstream/_platform/linux.py    | 11 +++++++----
 buildstream/_platform/platform.py |  5 +++++
 buildstream/_platform/unix.py     |  2 --
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py
index 5543aee..6a1358a 100644
--- a/buildstream/_platform/linux.py
+++ b/buildstream/_platform/linux.py
@@ -17,7 +17,6 @@
 #  Authors:
 #        Tristan Maat <tr...@codethink.co.uk>
 
-import os
 import subprocess
 
 from .. import _site
@@ -33,15 +32,16 @@ class Linux(Platform):
 
     def __init__(self, context):
 
-        super().__init__(context)
-
         self._die_with_parent_available = _site.check_bwrap_version(0, 1, 8)
 
         if self._local_sandbox_available():
             self._user_ns_available = self._check_user_ns_available(context)
         else:
             self._user_ns_available = False
-        self._artifact_cache = CASCache(context, enable_push=self._user_ns_available)
+
+        # _user_ns_available needs to be set before chaining up to the super class
+        # This is because it will call create_artifact_cache()
+        super().__init__(context)
 
     @property
     def artifactcache(self):
@@ -53,6 +53,9 @@ class Linux(Platform):
         kwargs['die_with_parent_available'] = self._die_with_parent_available
         return SandboxBwrap(*args, **kwargs)
 
+    def create_artifact_cache(self, context, *, enable_push):
+        return super().create_artifact_cache(context=context, enable_push=self._user_ns_available)
+
     ################################################
     #              Private Methods                 #
     ################################################
diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py
index 524985c..bf1e5e8 100644
--- a/buildstream/_platform/platform.py
+++ b/buildstream/_platform/platform.py
@@ -22,6 +22,7 @@ import sys
 import resource
 
 from .._exceptions import PlatformError, ImplError
+from .._artifactcache.cascache import CASCache
 
 
 class Platform():
@@ -39,6 +40,7 @@ class Platform():
     def __init__(self, context):
         self.context = context
         self.set_resource_limits()
+        self._artifact_cache = self.create_artifact_cache(context, enable_push=True)
 
     @classmethod
     def create_instance(cls, *args, **kwargs):
@@ -109,3 +111,6 @@ class Platform():
             if hard_limit is None:
                 hard_limit = limits[1]
             resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit))
+
+    def create_artifact_cache(self, context, *, enable_push=True):
+        return CASCache(context=context, enable_push=enable_push)
diff --git a/buildstream/_platform/unix.py b/buildstream/_platform/unix.py
index 0306a4a..c79608c 100644
--- a/buildstream/_platform/unix.py
+++ b/buildstream/_platform/unix.py
@@ -19,7 +19,6 @@
 
 import os
 
-from .._artifactcache.cascache import CASCache
 from .._exceptions import PlatformError
 from ..sandbox import SandboxChroot
 
@@ -31,7 +30,6 @@ class Unix(Platform):
     def __init__(self, context):
 
         super().__init__(context)
-        self._artifact_cache = CASCache(context)
 
         # Not necessarily 100% reliable, but we want to fail early.
         if os.geteuid() != 0: