From 29a14a9d01fe437440c2aed92c9a2f634f694820 Mon Sep 17 00:00:00 2001 From: Lukas Abelt Date: Fri, 15 Sep 2023 15:38:45 +0200 Subject: [PATCH] * Added support for SingleRevision for only_valid_in parameter of RevisionBinaryMap --- tests/utils/test_git_util.py | 13 ++++++++++++- varats-core/varats/utils/git_util.py | 10 +++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/utils/test_git_util.py b/tests/utils/test_git_util.py index 1450add2a..c11818665 100644 --- a/tests/utils/test_git_util.py +++ b/tests/utils/test_git_util.py @@ -2,7 +2,7 @@ import unittest from pathlib import Path -from benchbuild.utils.revision_ranges import RevisionRange +from benchbuild.utils.revision_ranges import RevisionRange, SingleRevision from varats.project.project_util import ( get_local_project_git, @@ -568,6 +568,17 @@ def test_specification_validity_range_multiple_binaries(self) -> None: self.assertIn("SingleLocalMultipleRegions", self.rv_map) self.assertIn("SingleLocalSimple", self.rv_map) + def test_specification_single_revision(self) -> None: + """Check if we can add binaries that are only valid with a single + revision.""" + self.rv_map.specify_binary( + "build/bin/SingleLocalMultipleRegions", + BinaryType.EXECUTABLE, + only_valid_in=SingleRevision("162db88346") + ) + + self.assertIn("SingleLocalMultipleRegions", self.rv_map) + def test_specification_binaries_with_special_name(self) -> None: """Check if we can add binaries that have a special name.""" self.rv_map.specify_binary( diff --git a/varats-core/varats/utils/git_util.py b/varats-core/varats/utils/git_util.py index 413ecd269..6f0cd1c1d 100644 --- a/varats-core/varats/utils/git_util.py +++ b/varats-core/varats/utils/git_util.py @@ -1063,7 +1063,9 @@ def specify_binary( override_entry_point = kwargs.get("override_entry_point", None) if override_entry_point: override_entry_point = Path(override_entry_point) - validity_range = kwargs.get("only_valid_in", None) + validity_range: AbstractRevisionRange = kwargs.get( + "only_valid_in", None + ) valid_exit_codes = kwargs.get("valid_exit_codes", None) wrapped_binary = ProjectBinaryWrapper( @@ -1072,6 +1074,7 @@ def specify_binary( ) if validity_range: + validity_range.init_cache(self.__repo_location) self.__revision_specific_mappings[validity_range].append( wrapped_binary ) @@ -1087,10 +1090,7 @@ def __getitem__(self, for validity_range, wrapped_binaries \ in self.__revision_specific_mappings.items(): - if revision in get_all_revisions_between( - validity_range.id_start, validity_range.id_end, ShortCommitHash, - self.__repo_location - ): + if revision in map(ShortCommitHash, validity_range): revision_specific_binaries.extend(wrapped_binaries) revision_specific_binaries.extend(self.__always_valid_mappings)