From 75932421da2cd8b5807a4ac52ed2a6f46d7c2120 Mon Sep 17 00:00:00 2001 From: Jiewei Qian Date: Thu, 8 Aug 2024 04:18:34 +0000 Subject: [PATCH] metadata: relax versioning info check if Chromium is the canonical repo of a dependency If Chromium is the canonical repository, the version of the dependency is essentially Chromium. Change-Id: Ifcb80dbeee0d36bf71234f8f48423e8f7aa9dcf0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5772151 Reviewed-by: Rachael Newitt Commit-Queue: Jiewei Qian --- metadata/dependency_metadata.py | 15 +++++---------- metadata/tests/dependency_metadata_test.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/metadata/dependency_metadata.py b/metadata/dependency_metadata.py index 6a196d190..979d4d72a 100644 --- a/metadata/dependency_metadata.py +++ b/metadata/dependency_metadata.py @@ -218,16 +218,11 @@ class DependencyMetadata: reason=f"Required field '{field_name}' is missing.") results.append(error) - # At least one of the fields Version, Date or Revision must be - # provided. - version_value = self._metadata.get(known_fields.VERSION) - date_value = self._metadata.get(known_fields.DATE) - revision_value = self._metadata.get(known_fields.REVISION) - if ((not version_value - or version_util.version_is_unknown(version_value)) and - (not date_value or version_util.version_is_unknown(date_value)) - and (not revision_value - or version_util.version_is_unknown(revision_value))): + # If the repository is hosted somewhere (i.e. Chromium isn't the + # canonical repositroy of the dependency), at least one of the fields + # Version, Date or Revision must be provided. + if (not (self.is_canonical or self.version or self.date + or self.revision)): versioning_fields = [ known_fields.VERSION, known_fields.DATE, known_fields.REVISION ] diff --git a/metadata/tests/dependency_metadata_test.py b/metadata/tests/dependency_metadata_test.py index 49cc9966f..b010c6618 100644 --- a/metadata/tests/dependency_metadata_test.py +++ b/metadata/tests/dependency_metadata_test.py @@ -325,6 +325,27 @@ class DependencyValidationTest(unittest.TestCase): ) self.assertEqual(len(results), 0) + def test_dep_is_canonical_skips_versioning_requirement(self): + """ + Check versioning information isn't required for dependencies where + Chromium is the canonical repository. + """ + dependency = dm.DependencyMetadata() + dependency.add_entry(known_fields.NAME.get_name(), + "Test valid metadata") + dependency.add_entry(known_fields.URL.get_name(), + "This is the canonical repository") + dependency.add_entry(known_fields.VERSION.get_name(), "N/A") + dependency.add_entry(known_fields.LICENSE.get_name(), "Public Domain") + dependency.add_entry(known_fields.LICENSE_FILE.get_name(), "LICENSE") + dependency.add_entry(known_fields.SECURITY_CRITICAL.get_name(), "yes") + dependency.add_entry(known_fields.SHIPPED.get_name(), "yes") + + results = dependency.validate( + source_file_dir=os.path.join(_THIS_DIR, "data"), + repo_root_dir=_THIS_DIR, + ) + self.assertEqual(len(results), 0) if __name__ == "__main__": unittest.main()