Jürg Billeter pushed to branch juerg/context-default-values at BuildStream / buildstream
Commits:
-
7918db20
by Richard Maw at 2018-11-15T14:44:54Z
-
7f15cf8b
by Jürg Billeter at 2018-11-15T14:46:06Z
-
2d5a5cc0
by Jürg Billeter at 2018-11-15T14:46:38Z
-
f78a72a2
by Jürg Billeter at 2018-11-15T14:46:38Z
9 changed files:
- buildstream/_context.py
- buildstream/sandbox/_sandboxremote.py
- buildstream/sandbox/sandbox.py
- buildstream/storage/_casbaseddirectory.py
- tests/artifactcache/push.py
- tests/plugins/pipeline.py
- tests/sandboxes/storage-tests.py
- tests/storage/virtual_directory_import.py
- tests/testutils/artifactshare.py
Changes:
... | ... | @@ -63,25 +63,25 @@ class Context(): |
63 | 63 |
self.artifactdir = None
|
64 | 64 |
|
65 | 65 |
# The locations from which to push and pull prebuilt artifacts
|
66 |
- self.artifact_cache_specs = []
|
|
66 |
+ self.artifact_cache_specs = None
|
|
67 | 67 |
|
68 | 68 |
# The directory to store build logs
|
69 | 69 |
self.logdir = None
|
70 | 70 |
|
71 | 71 |
# The abbreviated cache key length to display in the UI
|
72 |
- self.log_key_length = 0
|
|
72 |
+ self.log_key_length = None
|
|
73 | 73 |
|
74 | 74 |
# Whether debug mode is enabled
|
75 |
- self.log_debug = False
|
|
75 |
+ self.log_debug = None
|
|
76 | 76 |
|
77 | 77 |
# Whether verbose mode is enabled
|
78 |
- self.log_verbose = False
|
|
78 |
+ self.log_verbose = None
|
|
79 | 79 |
|
80 | 80 |
# Maximum number of lines to print from build logs
|
81 |
- self.log_error_lines = 0
|
|
81 |
+ self.log_error_lines = None
|
|
82 | 82 |
|
83 | 83 |
# Maximum number of lines to print in the master log for a detailed message
|
84 |
- self.log_message_lines = 0
|
|
84 |
+ self.log_message_lines = None
|
|
85 | 85 |
|
86 | 86 |
# Format string for printing the pipeline at startup time
|
87 | 87 |
self.log_element_format = None
|
... | ... | @@ -90,19 +90,22 @@ class Context(): |
90 | 90 |
self.log_message_format = None
|
91 | 91 |
|
92 | 92 |
# Maximum number of fetch or refresh tasks
|
93 |
- self.sched_fetchers = 4
|
|
93 |
+ self.sched_fetchers = None
|
|
94 | 94 |
|
95 | 95 |
# Maximum number of build tasks
|
96 |
- self.sched_builders = 4
|
|
96 |
+ self.sched_builders = None
|
|
97 | 97 |
|
98 | 98 |
# Maximum number of push tasks
|
99 |
- self.sched_pushers = 4
|
|
99 |
+ self.sched_pushers = None
|
|
100 | 100 |
|
101 | 101 |
# Maximum number of retries for network tasks
|
102 |
- self.sched_network_retries = 2
|
|
102 |
+ self.sched_network_retries = None
|
|
103 | 103 |
|
104 | 104 |
# What to do when a build fails in non interactive mode
|
105 |
- self.sched_error_action = 'continue'
|
|
105 |
+ self.sched_error_action = None
|
|
106 |
+ |
|
107 |
+ # Size of the artifact cache in bytes
|
|
108 |
+ self.config_cache_quota = None
|
|
106 | 109 |
|
107 | 110 |
# Whether elements must be rebuilt when their dependencies have changed
|
108 | 111 |
self._strict_build_plan = None
|
... | ... | @@ -120,7 +123,6 @@ class Context(): |
120 | 123 |
self._workspaces = None
|
121 | 124 |
self._log_handle = None
|
122 | 125 |
self._log_filename = None
|
123 |
- self.config_cache_quota = 'infinity'
|
|
124 | 126 |
|
125 | 127 |
# load()
|
126 | 128 |
#
|
... | ... | @@ -180,7 +182,7 @@ class Context(): |
180 | 182 |
cache = _yaml.node_get(defaults, Mapping, 'cache')
|
181 | 183 |
_yaml.node_validate(cache, ['quota'])
|
182 | 184 |
|
183 |
- self.config_cache_quota = _yaml.node_get(cache, str, 'quota', default_value='infinity')
|
|
185 |
+ self.config_cache_quota = _yaml.node_get(cache, str, 'quota')
|
|
184 | 186 |
|
185 | 187 |
# Load artifact share configuration
|
186 | 188 |
self.artifact_cache_specs = ArtifactCache.specs_from_config_node(defaults)
|
... | ... | @@ -182,7 +182,7 @@ class SandboxRemote(Sandbox): |
182 | 182 |
# to replace the sandbox's virtual directory with that. Creating a new virtual directory object
|
183 | 183 |
# from another hash will be interesting, though...
|
184 | 184 |
|
185 |
- new_dir = CasBasedDirectory(self._get_context(), ref=dir_digest)
|
|
185 |
+ new_dir = CasBasedDirectory(self._get_context().artifactcache.cas, ref=dir_digest)
|
|
186 | 186 |
self._set_virtual_directory(new_dir)
|
187 | 187 |
|
188 | 188 |
def run(self, command, flags, *, cwd=None, env=None):
|
... | ... | @@ -191,7 +191,7 @@ class SandboxRemote(Sandbox): |
191 | 191 |
|
192 | 192 |
if isinstance(upload_vdir, FileBasedDirectory):
|
193 | 193 |
# Make a new temporary directory to put source in
|
194 |
- upload_vdir = CasBasedDirectory(self._get_context(), ref=None)
|
|
194 |
+ upload_vdir = CasBasedDirectory(self._get_context().artifactcache.cas, ref=None)
|
|
195 | 195 |
upload_vdir.import_files(self.get_virtual_directory()._get_underlying_directory())
|
196 | 196 |
|
197 | 197 |
upload_vdir.recalculate_hash()
|
... | ... | @@ -156,7 +156,7 @@ class Sandbox(): |
156 | 156 |
"""
|
157 | 157 |
if self._vdir is None or self._never_cache_vdirs:
|
158 | 158 |
if 'BST_CAS_DIRECTORIES' in os.environ:
|
159 |
- self._vdir = CasBasedDirectory(self.__context, ref=None)
|
|
159 |
+ self._vdir = CasBasedDirectory(self.__context.artifactcache.cas, ref=None)
|
|
160 | 160 |
else:
|
161 | 161 |
self._vdir = FileBasedDirectory(self._root)
|
162 | 162 |
return self._vdir
|
... | ... | @@ -249,13 +249,11 @@ class CasBasedDirectory(Directory): |
249 | 249 |
_pb2_path_sep = "/"
|
250 | 250 |
_pb2_absolute_path_prefix = "/"
|
251 | 251 |
|
252 |
- def __init__(self, context, ref=None, parent=None, common_name="untitled", filename=None):
|
|
253 |
- self.context = context
|
|
254 |
- self.cas_directory = os.path.join(context.artifactdir, 'cas')
|
|
252 |
+ def __init__(self, cas_cache, ref=None, parent=None, common_name="untitled", filename=None):
|
|
255 | 253 |
self.filename = filename
|
256 | 254 |
self.common_name = common_name
|
257 | 255 |
self.pb2_directory = remote_execution_pb2.Directory()
|
258 |
- self.cas_cache = context.artifactcache.cas
|
|
256 |
+ self.cas_cache = cas_cache
|
|
259 | 257 |
if ref:
|
260 | 258 |
with open(self.cas_cache.objpath(ref), 'rb') as f:
|
261 | 259 |
self.pb2_directory.ParseFromString(f.read())
|
... | ... | @@ -270,7 +268,7 @@ class CasBasedDirectory(Directory): |
270 | 268 |
if self._directory_read:
|
271 | 269 |
return
|
272 | 270 |
for entry in self.pb2_directory.directories:
|
273 |
- buildStreamDirectory = CasBasedDirectory(self.context, ref=entry.digest,
|
|
271 |
+ buildStreamDirectory = CasBasedDirectory(self.cas_cache, ref=entry.digest,
|
|
274 | 272 |
parent=self, filename=entry.name)
|
275 | 273 |
self.index[entry.name] = IndexEntry(entry, buildstream_object=buildStreamDirectory)
|
276 | 274 |
for entry in self.pb2_directory.files:
|
... | ... | @@ -333,7 +331,7 @@ class CasBasedDirectory(Directory): |
333 | 331 |
.format(name, str(self), type(newdir)))
|
334 | 332 |
dirnode = self._find_pb2_entry(name)
|
335 | 333 |
else:
|
336 |
- newdir = CasBasedDirectory(self.context, parent=self, filename=name)
|
|
334 |
+ newdir = CasBasedDirectory(self.cas_cache, parent=self, filename=name)
|
|
337 | 335 |
dirnode = self.pb2_directory.directories.add()
|
338 | 336 |
|
339 | 337 |
dirnode.name = name
|
... | ... | @@ -225,7 +225,7 @@ def _test_push_directory(user_config_file, project_dir, artifact_dir, artifact_d |
225 | 225 |
|
226 | 226 |
if cas.has_push_remotes():
|
227 | 227 |
# Create a CasBasedDirectory from local CAS cache content
|
228 |
- directory = CasBasedDirectory(context, ref=artifact_digest)
|
|
228 |
+ directory = CasBasedDirectory(context.artifactcache.cas, ref=artifact_digest)
|
|
229 | 229 |
|
230 | 230 |
# Push the CasBasedDirectory object
|
231 | 231 |
cas.push_directory(project, directory)
|
... | ... | @@ -14,9 +14,10 @@ DATA_DIR = os.path.join( |
14 | 14 |
|
15 | 15 |
def create_pipeline(tmpdir, basedir, target):
|
16 | 16 |
context = Context()
|
17 |
- project = Project(basedir, context)
|
|
17 |
+ context.load()
|
|
18 | 18 |
context.deploydir = os.path.join(str(tmpdir), 'deploy')
|
19 | 19 |
context.artifactdir = os.path.join(str(tmpdir), 'artifact')
|
20 |
+ project = Project(basedir, context)
|
|
20 | 21 |
|
21 | 22 |
def dummy_handler(message, context):
|
22 | 23 |
pass
|
... | ... | @@ -3,7 +3,7 @@ import pytest |
3 | 3 |
|
4 | 4 |
from buildstream._exceptions import ErrorDomain
|
5 | 5 |
|
6 |
-from buildstream._context import Context
|
|
6 |
+from buildstream._artifactcache.cascache import CASCache
|
|
7 | 7 |
from buildstream.storage._casbaseddirectory import CasBasedDirectory
|
8 | 8 |
from buildstream.storage._filebaseddirectory import FileBasedDirectory
|
9 | 9 |
|
... | ... | @@ -17,9 +17,8 @@ def setup_backend(backend_class, tmpdir): |
17 | 17 |
if backend_class == FileBasedDirectory:
|
18 | 18 |
return backend_class(os.path.join(tmpdir, "vdir"))
|
19 | 19 |
else:
|
20 |
- context = Context()
|
|
21 |
- context.artifactdir = os.path.join(tmpdir, "cas")
|
|
22 |
- return backend_class(context)
|
|
20 |
+ cas_cache = CASCache(tmpdir)
|
|
21 |
+ return backend_class(cas_cache)
|
|
23 | 22 |
|
24 | 23 |
|
25 | 24 |
@pytest.mark.parametrize("backend", [
|
... | ... | @@ -15,18 +15,6 @@ from buildstream import utils |
15 | 15 |
# These are comparitive tests that check that FileBasedDirectory and
|
16 | 16 |
# CasBasedDirectory act identically.
|
17 | 17 |
|
18 |
- |
|
19 |
-class FakeArtifactCache():
|
|
20 |
- def __init__(self):
|
|
21 |
- self.cas = None
|
|
22 |
- |
|
23 |
- |
|
24 |
-class FakeContext():
|
|
25 |
- def __init__(self):
|
|
26 |
- self.artifactdir = ''
|
|
27 |
- self.artifactcache = FakeArtifactCache()
|
|
28 |
- |
|
29 |
- |
|
30 | 18 |
# This is a set of example file system contents. It's a set of trees
|
31 | 19 |
# which are either expected to be problematic or were found to be
|
32 | 20 |
# problematic during random testing.
|
... | ... | @@ -120,8 +108,8 @@ def file_contents_are(path, contents): |
120 | 108 |
return file_contents(path) == contents
|
121 | 109 |
|
122 | 110 |
|
123 |
-def create_new_casdir(root_number, fake_context, tmpdir):
|
|
124 |
- d = CasBasedDirectory(fake_context)
|
|
111 |
+def create_new_casdir(root_number, cas_cache, tmpdir):
|
|
112 |
+ d = CasBasedDirectory(cas_cache)
|
|
125 | 113 |
d.import_files(os.path.join(tmpdir, "content", "root{}".format(root_number)))
|
126 | 114 |
assert d.ref.hash != empty_hash_ref
|
127 | 115 |
return d
|
... | ... | @@ -175,20 +163,19 @@ def directory_not_empty(path): |
175 | 163 |
|
176 | 164 |
|
177 | 165 |
def _import_test(tmpdir, original, overlay, generator_function, verify_contents=False):
|
178 |
- fake_context = FakeContext()
|
|
179 |
- fake_context.artifactcache.cas = CASCache(tmpdir)
|
|
166 |
+ cas_cache = CASCache(tmpdir)
|
|
180 | 167 |
# Create some fake content
|
181 | 168 |
generator_function(original, tmpdir)
|
182 | 169 |
if original != overlay:
|
183 | 170 |
generator_function(overlay, tmpdir)
|
184 | 171 |
|
185 |
- d = create_new_casdir(original, fake_context, tmpdir)
|
|
172 |
+ d = create_new_casdir(original, cas_cache, tmpdir)
|
|
186 | 173 |
|
187 |
- duplicate_cas = create_new_casdir(original, fake_context, tmpdir)
|
|
174 |
+ duplicate_cas = create_new_casdir(original, cas_cache, tmpdir)
|
|
188 | 175 |
|
189 | 176 |
assert duplicate_cas.ref.hash == d.ref.hash
|
190 | 177 |
|
191 |
- d2 = create_new_casdir(overlay, fake_context, tmpdir)
|
|
178 |
+ d2 = create_new_casdir(overlay, cas_cache, tmpdir)
|
|
192 | 179 |
d.import_files(d2)
|
193 | 180 |
export_dir = os.path.join(tmpdir, "output-{}-{}".format(original, overlay))
|
194 | 181 |
roundtrip_dir = os.path.join(tmpdir, "roundtrip-{}-{}".format(original, overlay))
|
... | ... | @@ -247,15 +234,14 @@ def test_random_cas_import(cli, tmpdir, original): |
247 | 234 |
|
248 | 235 |
|
249 | 236 |
def _listing_test(tmpdir, root, generator_function):
|
250 |
- fake_context = FakeContext()
|
|
251 |
- fake_context.artifactcache.cas = CASCache(tmpdir)
|
|
237 |
+ cas_cache = CASCache(tmpdir)
|
|
252 | 238 |
# Create some fake content
|
253 | 239 |
generator_function(root, tmpdir)
|
254 | 240 |
|
255 | 241 |
d = create_new_filedir(root, tmpdir)
|
256 | 242 |
filelist = list(d.list_relative_paths())
|
257 | 243 |
|
258 |
- d2 = create_new_casdir(root, fake_context, tmpdir)
|
|
244 |
+ d2 = create_new_casdir(root, cas_cache, tmpdir)
|
|
259 | 245 |
filelist2 = list(d2.list_relative_paths())
|
260 | 246 |
|
261 | 247 |
assert filelist == filelist2
|
... | ... | @@ -11,8 +11,8 @@ from multiprocessing import Process, Queue |
11 | 11 |
import pytest_cov
|
12 | 12 |
|
13 | 13 |
from buildstream import _yaml
|
14 |
+from buildstream._artifactcache.cascache import CASCache
|
|
14 | 15 |
from buildstream._artifactcache.casserver import create_server
|
15 |
-from buildstream._context import Context
|
|
16 | 16 |
from buildstream._exceptions import CASError
|
17 | 17 |
from buildstream._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
|
18 | 18 |
|
... | ... | @@ -45,10 +45,7 @@ class ArtifactShare(): |
45 | 45 |
|
46 | 46 |
os.makedirs(self.repodir)
|
47 | 47 |
|
48 |
- context = Context()
|
|
49 |
- context.artifactdir = self.repodir
|
|
50 |
- |
|
51 |
- self.cas = context.artifactcache.cas
|
|
48 |
+ self.cas = CASCache(self.repodir)
|
|
52 | 49 |
|
53 | 50 |
self.total_space = total_space
|
54 | 51 |
self.free_space = free_space
|