Skip to content

Commit b435829

Browse files
authored
Merge branch 'apache:master' into master
2 parents b016d00 + 12b11f8 commit b435829

File tree

28 files changed

+345
-60
lines changed

28 files changed

+345
-60
lines changed

.github/compose/ci.buildgrid.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
#
44
# Spins-up a unnamed and unauthenticated grid:
55
# - Controller + CAS + AC at http://localhost:50051
6-
# - Ref. + CAS at: http://localhost:50052
76
#
87
# BuildStream configuration snippet:
98
#
10-
# artifacts:
11-
# url: http://localhost:50052
12-
# push: true
139
# remote-execution:
1410
# execution-service:
1511
# url: http://localhost:50051
@@ -25,6 +21,26 @@
2521
version: "3.2"
2622

2723
services:
24+
database:
25+
image: registry.gitlab.com/buildgrid/buildgrid.hub.docker.com/buildgrid-postgres:nightly
26+
environment:
27+
POSTGRES_USER: bgd
28+
POSTGRES_PASSWORD: insecure
29+
POSTGRES_DB: bgd
30+
volumes:
31+
- type: volume
32+
source: db
33+
target: /var/lib/postgresql
34+
networks:
35+
- grid
36+
ports:
37+
- "5432:5432"
38+
healthcheck:
39+
test: ["CMD", "pg_isready", "-U", "bgd"]
40+
interval: 1s
41+
timeout: 5s
42+
retries: 10
43+
2844
controller:
2945
image: registry.gitlab.com/buildgrid/buildgrid.hub.docker.com/buildgrid:nightly
3046
command: [
@@ -34,6 +50,9 @@ services:
3450
- 50051:50051
3551
networks:
3652
- grid
53+
depends_on:
54+
database:
55+
condition: service_healthy
3756

3857
bot:
3958
image: registry.gitlab.com/buildgrid/buildgrid.hub.docker.com/buildbox:nightly
@@ -49,19 +68,10 @@ services:
4968
networks:
5069
- grid
5170

52-
storage:
53-
image: registry.gitlab.com/buildgrid/buildgrid.hub.docker.com/buildgrid:nightly
54-
command: [
55-
"bgd", "server", "start", "-v",
56-
"/etc/buildgrid/artifacts.yml"]
57-
ports:
58-
- 50052:50052
59-
networks:
60-
- grid
61-
6271
networks:
6372
grid:
6473
driver: bridge
6574

6675
volumes:
6776
cache:
77+
db:

.github/compose/ci.docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ services:
5858
command: tox -vvvvv -- --color=yes --remote-execution
5959
environment:
6060
TOXENV: ${CI_TOXENV_MAIN}
61-
ARTIFACT_CACHE_SERVICE: http://localhost:50052
6261
REMOTE_EXECUTION_SERVICE: http://localhost:50051
63-
SOURCE_CACHE_SERVICE: http://localhost:50052
6462

6563
# We need to use host networking mode in order to be able to
6664
# properly resolve services exposed by adjacent containers.

src/buildstream/_artifact.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ def cache(
325325
for key, value in sorted(sandbox_env.items()):
326326
artifact.buildsandbox.environment.add(name=key, value=value)
327327

328+
for directory in buildsandbox._get_marked_directories():
329+
artifact.buildsandbox.marked_directories.append(directory)
330+
328331
artifact.buildsandbox.working_directory = buildsandbox._get_work_directory()
329332

330333
for subsandbox in buildsandbox._get_subsandboxes():
@@ -699,7 +702,7 @@ def pull(self, *, pull_buildtrees):
699702
def configure_sandbox(self, sandbox):
700703
artifact = self._get_proto()
701704

702-
if artifact.buildsandbox and artifact.buildsandbox.environment:
705+
if artifact.HasField("buildsandbox") and artifact.buildsandbox.environment:
703706
env = {}
704707
for env_var in artifact.buildsandbox.environment:
705708
env[env_var.name] = env_var.value
@@ -708,8 +711,12 @@ def configure_sandbox(self, sandbox):
708711

709712
sandbox.set_environment(env)
710713

711-
if artifact.buildsandbox and artifact.buildsandbox.working_directory:
712-
sandbox.set_work_directory(artifact.buildsandbox.working_directory)
714+
if artifact.HasField("buildsandbox"):
715+
for directory in artifact.buildsandbox.marked_directories:
716+
sandbox.mark_directory(directory)
717+
718+
if artifact.buildsandbox.working_directory:
719+
sandbox.set_work_directory(artifact.buildsandbox.working_directory)
713720

714721
# load_proto()
715722
#

src/buildstream/_artifactcache.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,28 +288,34 @@ def _push_artifact_blobs(self, artifact, artifact_digest, remote):
288288
artifact_proto = artifact._get_proto()
289289

290290
try:
291-
if str(artifact_proto.files):
291+
if artifact_proto.HasField("files"):
292292
self.cas._send_directory(remote, artifact_proto.files)
293293

294-
if str(artifact_proto.buildtree):
294+
if artifact_proto.HasField("buildtree"):
295295
try:
296296
self.cas._send_directory(remote, artifact_proto.buildtree)
297297
except FileNotFoundError:
298298
pass
299299

300-
if str(artifact_proto.buildroot):
300+
if artifact_proto.HasField("sources"):
301+
try:
302+
self.cas._send_directory(remote, artifact_proto.sources)
303+
except FileNotFoundError:
304+
pass
305+
306+
if artifact_proto.HasField("buildroot"):
301307
try:
302308
self.cas._send_directory(remote, artifact_proto.buildroot)
303309
except FileNotFoundError:
304310
pass
305311

306-
if artifact_proto.buildsandbox:
312+
if artifact_proto.HasField("buildsandbox"):
307313
for subsandbox_digest in artifact_proto.buildsandbox.subsandbox_digests:
308314
self.cas._send_directory(remote, subsandbox_digest)
309315

310316
digests = [artifact_digest, artifact_proto.low_diversity_meta, artifact_proto.high_diversity_meta]
311317

312-
if str(artifact_proto.public_data):
318+
if artifact_proto.HasField("public_data"):
313319
digests.append(artifact_proto.public_data)
314320

315321
for log_file in artifact_proto.logs:
@@ -357,22 +363,25 @@ def _push_artifact_proto(self, element, artifact, artifact_digest, remote):
357363
raise ArtifactError("{}".format(e), temporary=True) from e
358364

359365
referenced_directories = []
360-
if artifact_proto.files:
366+
if artifact_proto.HasField("files"):
361367
referenced_directories.append(artifact_proto.files)
362-
if artifact_proto.buildtree:
368+
if artifact_proto.HasField("buildtree"):
363369
referenced_directories.append(artifact_proto.buildtree)
364-
if artifact_proto.sources:
370+
if artifact_proto.HasField("sources"):
365371
referenced_directories.append(artifact_proto.sources)
366-
if artifact_proto.buildroot:
372+
if artifact_proto.HasField("buildroot"):
367373
referenced_directories.append(artifact_proto.buildroot)
368-
if artifact_proto.buildsandbox:
374+
if artifact_proto.HasField("buildsandbox"):
369375
for subsandbox_digest in artifact_proto.buildsandbox.subsandbox_digests:
370376
referenced_directories.append(subsandbox_digest)
371377

372378
referenced_blobs = [artifact_proto.low_diversity_meta, artifact_proto.high_diversity_meta] + [
373379
log_file.digest for log_file in artifact_proto.logs
374380
]
375381

382+
if artifact_proto.HasField("public_data"):
383+
referenced_blobs.append(artifact_proto.public_data)
384+
376385
try:
377386
remote.push_blob(
378387
uris,
@@ -418,20 +427,22 @@ def _pull_artifact_storage(self, element, key, artifact_digest, remote, pull_bui
418427
with utils.save_file_atomic(artifact_path, mode="wb") as f:
419428
f.write(artifact.SerializeToString())
420429

421-
if str(artifact.files):
430+
if artifact.HasField("files"):
422431
self.cas.fetch_directory(remote, artifact.files)
423432

424433
if pull_buildtrees:
425-
if str(artifact.buildtree):
434+
if artifact.HasField("buildtree"):
426435
self.cas.fetch_directory(remote, artifact.buildtree)
427-
if str(artifact.buildroot):
436+
if artifact.HasField("sources"):
437+
self.cas.fetch_directory(remote, artifact.sources)
438+
if artifact.HasField("buildroot"):
428439
self.cas.fetch_directory(remote, artifact.buildroot)
429-
if artifact.buildsandbox:
440+
if artifact.HasField("buildsandbox"):
430441
for subsandbox_digest in artifact.buildsandbox.subsandbox_digests:
431442
self.cas.fetch_directory(remote, subsandbox_digest)
432443

433444
digests = [artifact.low_diversity_meta, artifact.high_diversity_meta]
434-
if str(artifact.public_data):
445+
if artifact.HasField("public_data"):
435446
digests.append(artifact.public_data)
436447

437448
for log_digest in artifact.logs:

src/buildstream/_frontend/cli.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,12 +1302,29 @@ def artifact():
13021302
),
13031303
help="The dependencies we also want to show",
13041304
)
1305+
@click.option(
1306+
"--artifact-remote",
1307+
"artifact_remotes",
1308+
type=RemoteSpecType(RemoteSpecPurpose.PULL),
1309+
multiple=True,
1310+
help="A remote for downloading artifacts (Since: 2.7)",
1311+
)
1312+
@click.option(
1313+
"--ignore-project-artifact-remotes",
1314+
is_flag=True,
1315+
help="Ignore remote artifact cache servers recommended by projects (Since: 2.7)",
1316+
)
13051317
@click.argument("artifacts", type=click.Path(), nargs=-1)
13061318
@click.pass_obj
1307-
def artifact_show(app, deps, artifacts):
1308-
"""show the cached state of artifacts"""
1319+
def artifact_show(app, deps, artifact_remotes, ignore_project_artifact_remotes, artifacts):
1320+
"""Show the cached state of artifacts"""
13091321
with app.initialized():
1310-
targets = app.stream.artifact_show(artifacts, selection=deps)
1322+
targets = app.stream.artifact_show(
1323+
artifacts,
1324+
selection=deps,
1325+
artifact_remotes=artifact_remotes,
1326+
ignore_project_artifact_remotes=ignore_project_artifact_remotes,
1327+
)
13111328
click.echo(app.logger.show_state_of_artifacts(targets))
13121329
sys.exit(0)
13131330

src/buildstream/_loader/loadelement.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ cdef class Dependency:
202202
# Args:
203203
# other (Dependency): The dependency to merge into this one
204204
#
205-
cdef merge(self, Dependency other):
205+
cpdef merge(self, Dependency other):
206206
self.dep_type = self.dep_type | other.dep_type
207207
self.strict = self.strict or other.strict
208208

src/buildstream/_loader/loader.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ def _load_file(self, filename, provenance_node, *, load_subprojects=True):
495495
# The loader queue is a stack of tuples
496496
# [0] is the LoadElement instance
497497
# [1] is a stack of Dependency objects to load
498-
# [2] is a list of dependency names used to warn when all deps are loaded
499-
loader_queue = [(top_element, list(reversed(dependencies)), [])]
498+
# [2] is a Dict[LoadElement, Dependency] of loaded dependencies
499+
loader_queue = [(top_element, list(reversed(dependencies)), {})]
500500

501501
# Load all dependency files for the new LoadElement
502502
while loader_queue:
@@ -505,8 +505,6 @@ def _load_file(self, filename, provenance_node, *, load_subprojects=True):
505505

506506
# Process the first dependency of the last loaded element
507507
dep = current_element[1].pop()
508-
# And record its name for checking later
509-
current_element[2].append(dep.name)
510508

511509
if dep.junction:
512510
loader = self.get_loader(dep.junction, dep.node)
@@ -529,7 +527,7 @@ def _load_file(self, filename, provenance_node, *, load_subprojects=True):
529527
dep_element.mark_fully_loaded()
530528

531529
dep_deps = extract_depends_from_node(dep_element.node)
532-
loader_queue.append((dep_element, list(reversed(dep_deps)), []))
530+
loader_queue.append((dep_element, list(reversed(dep_deps)), {}))
533531

534532
# Pylint is not very happy about Cython and can't understand 'node' is a 'MappingNode'
535533
if dep_element.node.get_str(Symbol.KIND) == "junction": # pylint: disable=no-member
@@ -542,7 +540,15 @@ def _load_file(self, filename, provenance_node, *, load_subprojects=True):
542540
# LoadElement on the dependency and append the dependency to the owning
543541
# LoadElement dependency list.
544542
dep.set_element(dep_element)
545-
current_element[0].dependencies.append(dep) # pylint: disable=no-member
543+
544+
dep_dict = current_element[2]
545+
if dep.element in dep_dict:
546+
# Duplicate LoadElement in dependency list, this can happen if a dependency is
547+
# a link element that points to an element that is already a dependency.
548+
dep_dict[dep.element].merge(dep)
549+
else:
550+
current_element[0].dependencies.append(dep) # pylint: disable=no-member
551+
dep_dict[dep.element] = dep
546552
else:
547553
# And pop the element off the queue
548554
loader_queue.pop()

src/buildstream/_protos/buildstream/v2/artifact.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ message Artifact {
9090
repeated build.bazel.remote.execution.v2.Command.EnvironmentVariable environment = 1;
9191
string working_directory = 2;
9292
repeated build.bazel.remote.execution.v2.Digest subsandbox_digests = 3;
93+
repeated string marked_directories = 4;
9394
};
9495
SandboxState buildsandbox = 18; // optional
9596
}

src/buildstream/_protos/buildstream/v2/artifact_pb2.py

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/buildstream/_protos/buildstream/v2/artifact_pb2.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ class Artifact(_message.Message):
2828
digest: _remote_execution_pb2.Digest
2929
def __init__(self, name: _Optional[str] = ..., digest: _Optional[_Union[_remote_execution_pb2.Digest, _Mapping]] = ...) -> None: ...
3030
class SandboxState(_message.Message):
31-
__slots__ = ("environment", "working_directory", "subsandbox_digests")
31+
__slots__ = ("environment", "working_directory", "subsandbox_digests", "marked_directories")
3232
ENVIRONMENT_FIELD_NUMBER: _ClassVar[int]
3333
WORKING_DIRECTORY_FIELD_NUMBER: _ClassVar[int]
3434
SUBSANDBOX_DIGESTS_FIELD_NUMBER: _ClassVar[int]
35+
MARKED_DIRECTORIES_FIELD_NUMBER: _ClassVar[int]
3536
environment: _containers.RepeatedCompositeFieldContainer[_remote_execution_pb2.Command.EnvironmentVariable]
3637
working_directory: str
3738
subsandbox_digests: _containers.RepeatedCompositeFieldContainer[_remote_execution_pb2.Digest]
38-
def __init__(self, environment: _Optional[_Iterable[_Union[_remote_execution_pb2.Command.EnvironmentVariable, _Mapping]]] = ..., working_directory: _Optional[str] = ..., subsandbox_digests: _Optional[_Iterable[_Union[_remote_execution_pb2.Digest, _Mapping]]] = ...) -> None: ...
39+
marked_directories: _containers.RepeatedScalarFieldContainer[str]
40+
def __init__(self, environment: _Optional[_Iterable[_Union[_remote_execution_pb2.Command.EnvironmentVariable, _Mapping]]] = ..., working_directory: _Optional[str] = ..., subsandbox_digests: _Optional[_Iterable[_Union[_remote_execution_pb2.Digest, _Mapping]]] = ..., marked_directories: _Optional[_Iterable[str]] = ...) -> None: ...
3941
VERSION_FIELD_NUMBER: _ClassVar[int]
4042
BUILD_SUCCESS_FIELD_NUMBER: _ClassVar[int]
4143
BUILD_ERROR_FIELD_NUMBER: _ClassVar[int]

0 commit comments

Comments
 (0)