libvda: ignore pkg_config errors if chromeos feature is not set

pkg_config has introduced a new error type, Error::ProbeFailure, with
version 0.3.23 and returns this new error for the pattern we were trying
to match using Error::Failure. This causes the build script to fail if
the host is using version 0.3.23 or later.

Chrome OS is still using an older version, but trying to build with
cargo is likely to pull a newer one. The pkg_config crate explicitly
advises against matching these errors anyway, so change the strategy by
ignoring the errors if the chromeos feature is not set. That way we
still get clippy coverage while making sure a missing libvda package is
caught during builds that actually use it (libvda is not used outside of
Chrome OS).

BUG=None
TEST=cargo build --features "video-decoder,libvda"
TEST=emerge-zork-arc-r chromeos-base/crosvm

Change-Id: Ib2aad9f41541d3f4fe3cfb89f8b0f857d8033dcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3347307
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
This commit is contained in:
Alexandre Courbot 2021-12-22 12:25:13 +09:00 committed by Commit Bot
parent ea956bd908
commit 9bb22153ae

View file

@ -3,12 +3,14 @@
// found in the LICENSE file.
fn main() {
#[allow(clippy::single_match)]
match pkg_config::probe_library("libvda") {
Ok(_) => (),
// Ignore a pkg-config failure to allow cargo-clippy to run even when libvda.pc doesn't
// exist.
Err(pkg_config::Error::Failure { command, .. })
if command == r#""pkg-config" "--libs" "--cflags" "libvda""# => {}
// Ignore pkg-config failures on non-chromeos platforms to allow cargo-clippy to run even
// if libvda.pc doesn't exist.
#[cfg(not(feature = "chromeos"))]
Err(_) => (),
#[cfg(feature = "chromeos")]
Err(e) => panic!("{}", e),
};