Skip to content

Commit

Permalink
Merge pull request #1858 from apache/tristan/adrian/1851-fix-tracking
Browse files Browse the repository at this point in the history
Fix bug in tracking w/ project.refs
  • Loading branch information
gtristan authored Aug 17, 2023
2 parents 952431c + 5b72032 commit d7e22af
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/buildstream/_projectrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def _lookup(self, toplevel, project, element, source_index, *, ensure=False):
if not ensure:
return None

element_list.append({})
while len(element_list) <= source_index:
element_list.append({})
node = element_list.mapping_at(source_index)

return node
22 changes: 22 additions & 0 deletions tests/format/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from buildstream import _yaml
from buildstream.exceptions import ErrorDomain, LoadErrorReason
from buildstream._testing import cli # pylint: disable=unused-import
from buildstream._testing import generate_project

from tests.testutils import filetypegenerator

Expand Down Expand Up @@ -231,6 +232,27 @@ def test_project_refs_options(cli, datafiles):
assert result1.output != result2.output


# Assert that we can correctly track an element that has multiple sources such
# that a remote source (i.e. `kind: tar`) comes after a `kind: local` source
# when using project.refs
#
# `kind: local` sources are supposed to leave a gap in the project.refs file. However,
# older versions of buildstream would incorrectly account for this gap. See issue for
# more details: https://github.com/apache/buildstream/issues/1851
@pytest.mark.datafiles(os.path.join(DATA_DIR, "project-refs-gap"))
def test_project_refs_gap(cli, tmpdir, datafiles):
project = str(datafiles)
generate_project(
project,
config={
"aliases": {"tmpdir": "file:///" + str(tmpdir)},
"ref-storage": "project.refs",
},
)
result = cli.run(project=project, args=["source", "track", "target.bst"])
result.assert_success()


@pytest.mark.datafiles(os.path.join(DATA_DIR, "element-path"))
def test_element_path_project_path_contains_symlinks(cli, datafiles, tmpdir):
real_project = str(datafiles)
Expand Down
1 change: 1 addition & 0 deletions tests/format/project/project-refs-gap/file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a file
8 changes: 8 additions & 0 deletions tests/format/project/project-refs-gap/target.bst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: import

sources:
- kind: local
path: file

- kind: remote
url: tmpdir:/file

0 comments on commit d7e22af

Please sign in to comment.