From 13083b1a012990dbb8f87bbc92c9c2be962b4878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Fri, 15 May 2020 08:32:24 +0200 Subject: [PATCH] validatePkgConfig: init This adds the `validatePkgConfig` hook, which can be used to validate pkg-config files in the output(s). Currently, this will just run `pkg-config --validate` on all `.pc` files, capturing errors such as the issue that was fixed in #87789. The hook could be extended in the future with more fine-grained checks. --- doc/stdenv/stdenv.xml | 10 ++++++++++ .../setup-hooks/validate-pkg-config.sh | 19 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 4 ++++ 3 files changed, 33 insertions(+) create mode 100644 pkgs/build-support/setup-hooks/validate-pkg-config.sh diff --git a/doc/stdenv/stdenv.xml b/doc/stdenv/stdenv.xml index 65a343d7edd..64fc91fabca 100644 --- a/doc/stdenv/stdenv.xml +++ b/doc/stdenv/stdenv.xml @@ -2083,6 +2083,16 @@ postInstall = '' + + + validatePkgConfig + + + + The validatePkgConfig hook validates all pkg-config (.pc) files in a package. This helps catching some common errors in pkg-config files, such as undefined variables. + + + cmake diff --git a/pkgs/build-support/setup-hooks/validate-pkg-config.sh b/pkgs/build-support/setup-hooks/validate-pkg-config.sh new file mode 100644 index 00000000000..54fc9cc122c --- /dev/null +++ b/pkgs/build-support/setup-hooks/validate-pkg-config.sh @@ -0,0 +1,19 @@ +# This setup hook validates each pkgconfig file in each output. + +fixupOutputHooks+=(_validatePkgConfig) + +_validatePkgConfig() { + for pc in $(find "$prefix" -name '*.pc'); do + local bail=0 + + # Do not fail immediately. It's nice to see all errors when + # there are multiple pkgconfig files. + if ! pkg-config --validate "$pc"; then + bail=1 + fi + done + + if [ $bail -eq 1 ]; then + exit 1 + fi +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0db4b476682..6fe9ebd3999 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -501,6 +501,10 @@ in iconConvTools = callPackage ../build-support/icon-conv-tools {}; + validatePkgConfig = makeSetupHook + { name = "validate-pkg-config"; deps = [ findutils pkgconfig ]; } + ../build-support/setup-hooks/validate-pkg-config.sh; + #package writers writers = callPackage ../build-support/writers {};