diff options
author | Jürg Billeter <j@bitron.ch> | 2018-12-03 16:27:03 +0000 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-12-03 16:27:03 +0000 |
commit | f75810265aa8cc898ef570fd3129ae31b1e326a8 (patch) | |
tree | b77a55f0f6a51407fc46a33bb1cf7769bf2a1ad5 | |
parent | 4462892e382ce11fa12fc46f52a9116e94b125df (diff) | |
parent | d0f9c7241fc0f22bf225ebf1e34e88b1e96ec5eb (diff) | |
download | buildstream-f75810265aa8cc898ef570fd3129ae31b1e326a8.tar.gz |
Merge branch 'jonathan/fix-identical-element' into 'master'
_yamlcache.py: Use a project's junction name if present
Closes #795
See merge request BuildStream/buildstream!980
18 files changed, 99 insertions, 6 deletions
diff --git a/buildstream/_yamlcache.py b/buildstream/_yamlcache.py index 6c3b4d639..89117007b 100644 --- a/buildstream/_yamlcache.py +++ b/buildstream/_yamlcache.py @@ -68,7 +68,7 @@ class YamlCache(): # (bool): Whether the file is cached. def is_cached(self, project, filepath): cache_path = self._get_filepath(project, filepath) - project_name = project.name if project else "" + project_name = self.get_project_name(project) try: project_cache = self._project_caches[project_name] if cache_path in project_cache.elements: @@ -167,7 +167,7 @@ class YamlCache(): # value (decorated dict): The data to put into the cache. def put_from_key(self, project, filepath, key, value): cache_path = self._get_filepath(project, filepath) - project_name = project.name if project else "" + project_name = self.get_project_name(project) try: project_cache = self._project_caches[project_name] except KeyError: @@ -237,7 +237,7 @@ class YamlCache(): # (decorated dict): The parsed yaml from the cache, or None if the file isn't in the cache. def _get(self, project, filepath, key): cache_path = self._get_filepath(project, filepath) - project_name = project.name if project else "" + project_name = self.get_project_name(project) try: project_cache = self._project_caches[project_name] try: @@ -253,6 +253,30 @@ class YamlCache(): pass return None + # get_project_name(): + # + # Gets a name appropriate for Project. Projects must use their junction's + # name if present, otherwise elements with the same contents under the + # same path with identically-named projects are considered the same yaml + # object, despite existing in different Projects. + # + # Args: + # project (Project): The project this file is in, or None. + # + # Returns: + # (str): The project's junction's name if present, the project's name, + # or an empty string if there is no project + @staticmethod + def get_project_name(project): + if project: + if project.junction: + project_name = project.junction.name + else: + project_name = project.name + else: + project_name = "" + return project_name + CachedProject = namedtuple('CachedProject', ['elements']) @@ -287,7 +311,7 @@ class BstPickler(pickle.Pickler): if isinstance(obj, _yaml.ProvenanceFile): if obj.project: # ProvenanceFile's project object cannot be stored as it is. - project_tag = obj.project.name + project_tag = YamlCache.get_project_name(obj.project) # ProvenanceFile's filename must be stored relative to the # project, as the project dir may move. name = os.path.relpath(obj.name, obj.project.directory) @@ -319,14 +343,14 @@ class BstUnpickler(pickle.Unpickler): if project_tag is not None: for p in self._context.get_projects(): - if project_tag == p.name: + if YamlCache.get_project_name(p) == project_tag: project = p break name = os.path.join(project.directory, tagged_name) if not project: - projects = [p.name for p in self._context.get_projects()] + projects = [YamlCache.get_project_name(p) for p in self._context.get_projects()] raise pickle.UnpicklingError("No project with name {} found in {}" .format(project_tag, projects)) else: diff --git a/tests/loader/junctions.py b/tests/loader/junctions.py index a02961fb5..d55d10b3d 100644 --- a/tests/loader/junctions.py +++ b/tests/loader/junctions.py @@ -48,6 +48,16 @@ def test_simple_build(cli, tmpdir, datafiles): @pytest.mark.datafiles(DATA_DIR) +def test_build_of_same_junction_used_twice(cli, tmpdir, datafiles): + project = os.path.join(str(datafiles), 'inconsistent-names') + + # Check we can build a project that contains the same junction + # that is used twice, but named differently + result = cli.run(project=project, args=['build', 'target.bst']) + assert result.exit_code == 0 + + +@pytest.mark.datafiles(DATA_DIR) def test_nested_simple(cli, tmpdir, datafiles): foo = os.path.join(str(datafiles), 'foo') copy_subprojects(foo, datafiles, ['base']) diff --git a/tests/loader/junctions/inconsistent-names/elements/junction-A.bst b/tests/loader/junctions/inconsistent-names/elements/junction-A.bst new file mode 100644 index 000000000..74079f990 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/elements/junction-A.bst @@ -0,0 +1,4 @@ +kind: junction +sources: +- kind: local + path: junctionA diff --git a/tests/loader/junctions/inconsistent-names/elements/junction-B-diff-name.bst b/tests/loader/junctions/inconsistent-names/elements/junction-B-diff-name.bst new file mode 100644 index 000000000..3b33406e5 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/elements/junction-B-diff-name.bst @@ -0,0 +1,4 @@ +kind: junction +sources: +- kind: local + path: junctionA/junctionB diff --git a/tests/loader/junctions/inconsistent-names/elements/target.bst b/tests/loader/junctions/inconsistent-names/elements/target.bst new file mode 100644 index 000000000..7eba141de --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/elements/target.bst @@ -0,0 +1,9 @@ +kind: import +sources: +- kind: local + path: files/foo +depends: +- filename: lib2.bst + junction: junction-B-diff-name.bst +- filename: lib.bst + junction: junction-A.bst diff --git a/tests/loader/junctions/inconsistent-names/files/foo b/tests/loader/junctions/inconsistent-names/files/foo new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/files/foo diff --git a/tests/loader/junctions/inconsistent-names/junctionA/elements/app.bst b/tests/loader/junctions/inconsistent-names/junctionA/elements/app.bst new file mode 100644 index 000000000..473aaee0b --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/elements/app.bst @@ -0,0 +1,6 @@ +kind: import +sources: +- kind: local + path: files/app +depends: +- lib.bst diff --git a/tests/loader/junctions/inconsistent-names/junctionA/elements/junction-B.bst b/tests/loader/junctions/inconsistent-names/junctionA/elements/junction-B.bst new file mode 100644 index 000000000..bc66d7851 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/elements/junction-B.bst @@ -0,0 +1,4 @@ +kind: junction +sources: +- kind: local + path: junctionB diff --git a/tests/loader/junctions/inconsistent-names/junctionA/elements/lib.bst b/tests/loader/junctions/inconsistent-names/junctionA/elements/lib.bst new file mode 100644 index 000000000..684a64315 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/elements/lib.bst @@ -0,0 +1,7 @@ +kind: import +sources: +- kind: local + path: files/lib +depends: +- filename: base.bst + junction: junction-B.bst diff --git a/tests/loader/junctions/inconsistent-names/junctionA/files/app b/tests/loader/junctions/inconsistent-names/junctionA/files/app new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/files/app diff --git a/tests/loader/junctions/inconsistent-names/junctionA/files/lib b/tests/loader/junctions/inconsistent-names/junctionA/files/lib new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/files/lib diff --git a/tests/loader/junctions/inconsistent-names/junctionA/junctionB/base/baseimg b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/base/baseimg new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/base/baseimg diff --git a/tests/loader/junctions/inconsistent-names/junctionA/junctionB/elements/base.bst b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/elements/base.bst new file mode 100644 index 000000000..ecdc57c79 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/elements/base.bst @@ -0,0 +1,4 @@ +kind: import +sources: +- kind: local + path: base diff --git a/tests/loader/junctions/inconsistent-names/junctionA/junctionB/elements/lib2.bst b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/elements/lib2.bst new file mode 100644 index 000000000..5a7c17b99 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/elements/lib2.bst @@ -0,0 +1,6 @@ +kind: import +sources: +- kind: local + path: files/lib2 +depends: +- base.bst diff --git a/tests/loader/junctions/inconsistent-names/junctionA/junctionB/files/lib2 b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/files/lib2 new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/files/lib2 diff --git a/tests/loader/junctions/inconsistent-names/junctionA/junctionB/project.conf b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/project.conf new file mode 100644 index 000000000..2e96170f8 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/junctionB/project.conf @@ -0,0 +1,5 @@ +# Unique project name +name: projectB + +# Subdirectory where elements are stored +element-path: elements diff --git a/tests/loader/junctions/inconsistent-names/junctionA/project.conf b/tests/loader/junctions/inconsistent-names/junctionA/project.conf new file mode 100644 index 000000000..166c4b78c --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/junctionA/project.conf @@ -0,0 +1,5 @@ +# Unique project name +name: projectA + +# Subdirectory where elements are stored +element-path: elements diff --git a/tests/loader/junctions/inconsistent-names/project.conf b/tests/loader/junctions/inconsistent-names/project.conf new file mode 100644 index 000000000..064bbc588 --- /dev/null +++ b/tests/loader/junctions/inconsistent-names/project.conf @@ -0,0 +1,5 @@ +# Unique project name +name: inconsistent-names + +# Subdirectory where elements are stored +element-path: elements |