diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-25 17:27:49 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-25 17:30:55 +0900 |
commit | c9b5692e7dd632ea1115fcb0e3e91f01b3fbac3b (patch) | |
tree | cd1e16f9190cc782a4dd915165023a24d866eb0a | |
parent | 83620b389e28f1248021c1c02be6834b0c023ab6 (diff) | |
download | buildstream-c9b5692e7dd632ea1115fcb0e3e91f01b3fbac3b.tar.gz |
Consider new sandbox configuration in cache keys.
This adds SandboxConfig.get_unique_key() to delegate
the cache key contribution to the SandboxConfig.
Further, this moves over the OS and Machine Architecture
parts of cache key calculation into SandboxConfig.get_unique_key(),
removing the comment which speaks of later delegating this
part of cache key calculation to sandboxes.
Cache key calculation algorithm is backward compatible,
and so the artifact version remains unchanged.
-rw-r--r-- | buildstream/element.py | 10 | ||||
-rw-r--r-- | buildstream/sandbox/_config.py | 34 |
2 files changed, 35 insertions, 9 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index 57d3732e7..e0cefbbe2 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -926,7 +926,6 @@ class Element(Plugin): context = self._get_context() project = self._get_project() - operating_system, _, _, _, machine_arch = os.uname() self.__cache_key_dict = { 'artifact-version': "{}.{}".format(_BST_CORE_ARTIFACT_VERSION, @@ -934,14 +933,7 @@ class Element(Plugin): 'context': context._get_cache_key(), 'project': project._get_cache_key(), 'element': self.get_unique_key(), - - # The execution environment may later be delegated - # to sandboxes which support virtualization - # - 'execution-environment': { - 'os': operating_system, - 'arch': machine_arch - }, + 'execution-environment': self.__sandbox_config.get_unique_key(), 'environment': cache_env, 'sources': [s._get_unique_key() for s in self.__sources], 'public': self.__public, diff --git a/buildstream/sandbox/_config.py b/buildstream/sandbox/_config.py index ca5273864..8893e3faa 100644 --- a/buildstream/sandbox/_config.py +++ b/buildstream/sandbox/_config.py @@ -17,6 +17,7 @@ # # Authors: # Jim MacArthur <jim.macarthur@codethink.co.uk> +import os # SandboxConfig @@ -27,3 +28,36 @@ class SandboxConfig(): def __init__(self, build_uid, build_gid): self.build_uid = build_uid self.build_gid = build_gid + + # get_unique_key(): + # + # This returns the SandboxConfig's contribution + # to an element's cache key. + # + # Returns: + # (dict): A dictionary to add to an element's cache key + # + def get_unique_key(self): + + # Currently operating system and machine architecture + # are not configurable and we have no sandbox implementation + # which can conform to such configurations. + # + # However this should be the right place to support + # such configurations in the future. + # + operating_system, _, _, _, machine_arch = os.uname() + unique_key = { + 'os': operating_system, + 'arch': machine_arch + } + + # Avoid breaking cache key calculation with + # the addition of configurabuild build uid/gid + if self.build_uid != 0: + unique_key['build-uid'] = self.build_uid + + if self.build_gid != 0: + unique_key['build-gid'] = self.build_gid + + return unique_key |