From b5e089d25ea59fc2a0cb96cafcd1caf5b1eab4a1 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 27 Jun 2023 09:38:19 +0200 Subject: [PATCH] User-visible warning when bro-pkg.meta is in use. Relates to #119 --- .../tests.install-bro-pkg-warning/stderr | 2 ++ testing/tests/install-bro-pkg-warning | 3 +++ zeekpkg/manager.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 testing/baselines/tests.install-bro-pkg-warning/stderr create mode 100644 testing/tests/install-bro-pkg-warning diff --git a/testing/baselines/tests.install-bro-pkg-warning/stderr b/testing/baselines/tests.install-bro-pkg-warning/stderr new file mode 100644 index 00000000..6cfda2a7 --- /dev/null +++ b/testing/baselines/tests.install-bro-pkg-warning/stderr @@ -0,0 +1,2 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +XXXX-XX-XX XX:XX:XX WARNING Package one/alice/foo is using the legacy bro-pkg.meta metadata file. It will soon stop working unless updated to use zkg.meta instead. Please report this to the package maintainers. diff --git a/testing/tests/install-bro-pkg-warning b/testing/tests/install-bro-pkg-warning new file mode 100644 index 00000000..bd94ede1 --- /dev/null +++ b/testing/tests/install-bro-pkg-warning @@ -0,0 +1,3 @@ +# @TEST-EXEC: (cd packages/foo; git mv zkg.meta bro-pkg.meta; git commit -m 'Use bro-pkg.meta') +# @TEST-EXEC: zkg install foo 2> stderr +# @TEST-EXEC: TEST_DIFF_CANONIFIER='sed -r "s/[0-9]{2}/XX/g"' btest-diff stderr diff --git a/zeekpkg/manager.py b/zeekpkg/manager.py index 2919a9f2..4832e799 100644 --- a/zeekpkg/manager.py +++ b/zeekpkg/manager.py @@ -3303,6 +3303,9 @@ def _parse_package_metadata(parser, metadata_file): return "" +_legacy_metadata_warnings = set() + + def _info_from_clone(clone, package, status, version): """Retrieves information about a package. @@ -3335,6 +3338,20 @@ def _info_from_clone(clone, package, status, version): default_branch=default_branch, ) + # Remove in v3.0 by either silently ignoring LEGACY_METADATA_FILENAME + # completely or error with helpful instructions about zkg.meta. + if ( + os.path.basename(metadata_file) == LEGACY_METADATA_FILENAME + and package.qualified_name() not in _legacy_metadata_warnings + ): + LOG.warning( + "Package %s is using the legacy bro-pkg.meta metadata file. " + "It will soon stop working unless updated to use zkg.meta instead. " + "Please report this to the package maintainers.", + package.qualified_name(), + ) + _legacy_metadata_warnings.add(package.qualified_name()) + metadata = _get_package_metadata(metadata_parser) return PackageInfo(