You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2023/08/17 04:48:47 UTC
[buildstream] 01/01: Fix bug in tracking w/ project.refs
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tristan/adrian/1851-fix-tracking
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 5b720322da5612e103141f01015764fcb3b11bf8
Author: Adrian Vovk <ad...@gmail.com>
AuthorDate: Mon Aug 7 15:20:18 2023 -0400
Fix bug in tracking w/ project.refs
Fixes https://github.com/apache/buildstream/issues/1851
---
src/buildstream/_projectrefs.py | 3 ++-
tests/format/project.py | 22 ++++++++++++++++++++++
tests/format/project/project-refs-gap/file | 1 +
tests/format/project/project-refs-gap/target.bst | 8 ++++++++
4 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/src/buildstream/_projectrefs.py b/src/buildstream/_projectrefs.py
index 5095f1f83..931dc436d 100644
--- a/src/buildstream/_projectrefs.py
+++ b/src/buildstream/_projectrefs.py
@@ -146,7 +146,8 @@ class ProjectRefs:
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
diff --git a/tests/format/project.py b/tests/format/project.py
index 227bd8c91..1e8d20c4f 100644
--- a/tests/format/project.py
+++ b/tests/format/project.py
@@ -20,6 +20,7 @@ import pytest
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
@@ -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)
diff --git a/tests/format/project/project-refs-gap/file b/tests/format/project/project-refs-gap/file
new file mode 100644
index 000000000..0637880d7
--- /dev/null
+++ b/tests/format/project/project-refs-gap/file
@@ -0,0 +1 @@
+This is a file
diff --git a/tests/format/project/project-refs-gap/target.bst b/tests/format/project/project-refs-gap/target.bst
new file mode 100644
index 000000000..ad8c2aeda
--- /dev/null
+++ b/tests/format/project/project-refs-gap/target.bst
@@ -0,0 +1,8 @@
+kind: import
+
+sources:
+- kind: local
+ path: file
+
+- kind: remote
+ url: tmpdir:/file