Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/buildstream/_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def load(self, targets):

for target in targets:
with PROFILER.profile(Topics.LOAD_PROJECT, target):

# As we are attempting to load a subproject element via the
# command line ensure fully loaded.
#
# Other callers of `_parse_name` or `_load_file` that reference
# files through a project element or otherwise do not need to
# ensure fully loaded.
self.project.ensure_fully_loaded()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this loading is too eager, resulting in a regression of #1686.

I'm trying to find an alternative fix that avoids that regression.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #2114, which fixes this issue in a different way. It includes and passes your tests from this branch (adjusted to keep the previous tests without changes).


_junction, name, loader = self._parse_name(target, None)
element = loader._load_file(name, None)
target_elements.append(element)
Expand Down Expand Up @@ -190,14 +199,6 @@ def get_loader(self, name, provenance_node, *, load_subprojects=True):
junction_path = name.split(":")
loader = self

#
# In this case we are attempting to load a subproject element via the
# command line instead of referencing the subproject through a project
# element or otherwise.
#
if provenance_node is None and load_subprojects:
self.project.ensure_fully_loaded()

circular_provenance_node = self._loader_search_provenances.get(name, None)
if circular_provenance_node and load_subprojects:

Expand Down Expand Up @@ -796,15 +797,12 @@ def provenance_str():
# immediately and move on to the target.
#
if load_element.link_target:
_, filename, loader = self._parse_name(
load_element.link_target.as_str(), load_element.link_target, load_subprojects=load_subprojects
return self.get_loader(
load_element.link_target.as_str(),
load_element.link_target,
load_subprojects=load_subprojects,
)
if not loader:
# `loader` should never be None if `load_subprojects` is True
assert not load_subprojects
return None

return loader.get_loader(filename, load_element.link_target, load_subprojects=load_subprojects)

# If we're only performing a lookup, we're done here.
#
Expand Down
15 changes: 11 additions & 4 deletions tests/format/junctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,17 @@ def test_override_twice(cli, tmpdir, datafiles):
@pytest.mark.parametrize(
"target,expected_result",
[
("target.bst", "pony"),
("self-junction.bst:target.bst", "horsy"),
("subproject.bst:target.bst", "pony"),
("subproject.bst:self-junction.bst:target.bst", "horsy"),
("link.bst", "pony"),
("nested-link.bst", "horsy"),
],
ids=[
"direct-target",
"override-target",
"link-target",
"link-override-target",
],
ids=["direct-target", "override-target"],
)
def test_override_self(cli, datafiles, target, expected_result):
project = os.path.join(str(datafiles), "override-self")
Expand Down Expand Up @@ -922,7 +929,7 @@ def test_include_vars_optional(cli, datafiles, use_species, expected_result):
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize(
"target",
["target.bst", "subproject.bst:target.bst"],
["target.bst", "subproject.bst:target.bst", "intermediate-project.bst:subproject.bst:target.bst"],
ids=["toplevel-target", "subproject-target"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New ID is missing, blocking pytest.

Suggested change
ids=["toplevel-target", "subproject-target"],
ids=["toplevel-target", "subproject-target", "nested-link-target"],

)
@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kind: stack
12 changes: 12 additions & 0 deletions tests/format/junctions/include-complex/intermediate-project.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: junction

sources:
- kind: local
path: intermediate-project

config:
overrides:
subproject.bst:placeholder.bst: alternative-placeholder.bst

options:
animal: '%{animal}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: intermediate-project
min-version: 2.0

(@):
- subproject.bst:include.yml

options:
animal:
type: enum
description: the animal
values:
- pony
- horsy
default: pony
variable: animal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: junction
sources:
- kind: local
path: subproject

config:

options:
target_animal: '%{animal}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kind: stack
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ options:
- pony
- horsy
default: pony
variable: target_animal
8 changes: 2 additions & 6 deletions tests/format/junctions/include-complex/subproject.bst
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
kind: junction
sources:
- kind: local
path: subproject
kind: link

config:
options:
target_animal: '%{animal}'
target: intermediate-project.bst:subproject.bst
4 changes: 4 additions & 0 deletions tests/format/junctions/override-self/link.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: link

config:
target: subproject.bst:target.bst
4 changes: 4 additions & 0 deletions tests/format/junctions/override-self/nested-link.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: link

config:
target: subproject.bst:self-junction.bst:target.bst
6 changes: 3 additions & 3 deletions tests/format/junctions/override-self/project.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: test
min-version: 2.0

junctions:
internal:
- self-junction.bst

(@):
- subproject.bst:self-junction.bst:include.yml
4 changes: 4 additions & 0 deletions tests/format/junctions/override-self/subproject.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: junction
sources:
- kind: local
path: subproject
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: subproject
min-version: 2.0

junctions:
internal:
- self-junction.bst

# (@):
# - self-junction.bst:include.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sources:
- kind: local
path: .


config:
overrides:
target.bst: alternative.bst
Loading