3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #212282 from hercules-ci/pkg-config-packages

defaultPkgConfigPackages: init
This commit is contained in:
Robert Hensing 2023-01-30 09:48:53 +01:00 committed by GitHub
commit 663c41affd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1195 additions and 1 deletions

View file

@ -1,6 +1,19 @@
# Testers {#chap-testers}
This chapter describes several testing builders which are available in the <literal>testers</literal> namespace.
## `hasPkgConfigModule` {#tester-hasPkgConfigModule}
Checks whether a package exposes a certain `pkg-config` module.
Example:
```nix
passthru.tests.pkg-config = testers.hasPkgConfigModule {
package = finalAttrs.finalPackage;
moduleName = "libfoo";
}
```
## `testVersion` {#tester-testVersion}
Checks the command output contains the specified version

View file

@ -32,6 +32,7 @@
<xi:include href="octave.section.xml" />
<xi:include href="perl.section.xml" />
<xi:include href="php.section.xml" />
<xi:include href="pkg-config.section.xml" />
<xi:include href="python.section.xml" />
<xi:include href="qt.section.xml" />
<xi:include href="r.section.xml" />

View file

@ -0,0 +1,9 @@
# pkg-config {#sec-pkg-config}
*pkg-config* is a unified interface for declaring and querying built C/C++ libraries.
Nixpkgs provides a couple of facilities for working with this tool.
- A [setup hook](#setup-hook-pkg-config) bundled with in the `pkg-config` package, to bring a derivation's declared build inputs into the environment.
- The [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), for packages that provide pkg-config modules.
- The `defaultPkgConfigPackages` package set: a set of aliases, named after the modules they provide. This is meant to be used by language-to-nix integrations. Hand-written packages should use the normal Nixpkgs attribute name instead.

View file

@ -252,7 +252,8 @@ rec {
outputsList = map makeOutput outputs;
drv' = (lib.head outputsList).value;
in lib.deepSeq drv' drv';
in if drv == null then null else
lib.deepSeq drv' drv';
/* Make a set of packages with a common scope. All packages called
with the provided `callPackage` will be evaluated with the same

View file

@ -121,4 +121,6 @@
in
nixosTesting.simpleTest calledTest;
hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { };
}

View file

@ -0,0 +1,47 @@
# Static arguments
{ runCommand, pkg-config }:
# Tester arguments
{ package,
moduleName,
testName ? "check-pkg-config-${moduleName}",
}:
runCommand testName {
nativeBuildInputs = [ pkg-config ];
buildInputs = [ package ];
inherit moduleName;
meta = {
description = "Test whether ${package.name} exposes pkg-config module ${moduleName}";
}
# Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org,
# as hydra can't check this meta info in dependencies.
# The test itself is just Nixpkgs, with MIT license.
// builtins.intersectAttrs
{
available = throw "unused";
broken = throw "unused";
insecure = throw "unused";
license = throw "unused";
maintainers = throw "unused";
platforms = throw "unused";
unfree = throw "unused";
unsupported = throw "unused";
}
package.meta;
} ''
echo "checking pkg-config module $moduleName in $buildInputs"
set +e
version="$(pkg-config --modversion $moduleName)"
r=$?
set -e
if [[ $r = 0 ]]; then
echo " pkg-config module $moduleName exists and has version $version"
echo "$version" > $out
else
echo "These modules were available in the input propagation closure:"
pkg-config --list-all
echo " pkg-config module $moduleName was not found"
false
fi
''

View file

@ -0,0 +1,36 @@
# cd nixpkgs
# nix-build -A tests.testers.hasPkgConfigModule
{ lib, testers, zlib, runCommand }:
lib.recurseIntoAttrs {
zlib-has-zlib = testers.hasPkgConfigModule {
package = zlib;
moduleName = "zlib";
};
zlib-does-not-have-ylib = runCommand "zlib-does-not-have-ylib" {
failed = testers.testBuildFailure (
testers.hasPkgConfigModule {
package = zlib;
moduleName = "ylib";
}
);
} ''
echo 'it logs a relevant error message'
{
grep -F "pkg-config module ylib was not found" $failed/testBuildFailure.log
}
echo 'it logs which pkg-config modules are available, to be helpful'
{
# grep -v: the string zlib does also occur in a store path in an earlier message, which isn't particularly helpful
grep -v "checking pkg-config module" < $failed/testBuildFailure.log \
| grep -F "zlib"
}
# done
touch $out
'';
}

View file

@ -12,6 +12,8 @@ let
in
lib.recurseIntoAttrs {
hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { };
# Check that the wiring of nixosTest is correct.
# Correct operation of the NixOS test driver should be asserted elsewhere.
nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, pkgs, figlet, ... }: {

View file

@ -51,6 +51,8 @@ with pkgs;
php = recurseIntoAttrs (callPackages ./php {});
pkg-config = recurseIntoAttrs (callPackage ../top-level/pkg-config/tests.nix { });
rustCustomSysroot = callPackage ./rust-sysroot {};
buildRustCrate = callPackage ../build-support/rust/build-rust-crate/test { };
importCargoLock = callPackage ../build-support/rust/test/import-cargo-lock { };

View file

@ -112,6 +112,12 @@ with pkgs;
tests = callPackages ../test {};
defaultPkgConfigPackages =
# We don't want nix-env -q to enter this, because all of these are aliases.
dontRecurseIntoAttrs (
import ./pkg-config/defaultPkgConfigPackages.nix pkgs
);
### Nixpkgs maintainer tools
nix-generate-from-cpan = callPackage ../../maintainers/scripts/nix-generate-from-cpan.nix { };

View file

@ -0,0 +1,45 @@
/* A set of aliases to be used in generated expressions.
In case of ambiguity, this will pick a sensible default.
This was initially based on cabal2nix's mapping.
It'd be nice to generate this mapping, based on a set of derivations.
It can not be fully automated, so it should be a expression or tool
that makes suggestions about which pkg-config module names can be added.
*/
pkgs:
let
inherit (pkgs) lib;
inherit (lib)
all
flip
mapAttrs
mapAttrsToList
getAttrFromPath
importJSON
;
data = importJSON ./pkg-config-data.json;
inherit (data) modules;
platform = pkgs.stdenv.hostPlatform;
isSupported = moduleData:
moduleData?supportedWhenPlatformAttrsEqual ->
all (x: x) (
mapAttrsToList
(k: v: platform?${k} && platform.${k} == v)
moduleData.supportedWhenPlatformAttrsEqual
);
modulePkgs = flip mapAttrs modules (_moduleName: moduleData:
if moduleData?attrPath && isSupported moduleData then
getAttrFromPath moduleData.attrPath pkgs
else
null
);
in
modulePkgs

View file

@ -0,0 +1,964 @@
{
"version": {
"major": 0,
"minor": 1
},
"modules": {
"IL": {
"attrPath": [
"libdevil"
]
},
"ImageMagick": {
"attrPath": [
"imagemagick"
]
},
"MagickWand": {
"attrPath": [
"imagemagick"
]
},
"Qt5Concurrent": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5Core": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5DBus": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5Gui": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5Network": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5OpenGL": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5OpenGLExtensions": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5PrintSupport": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5Qml": {
"attrPath": [
"qt5",
"qtdeclarative"
]
},
"Qt5QmlModels": {
"attrPath": [
"qt5",
"qtdeclarative"
]
},
"Qt5Quick": {
"attrPath": [
"qt5",
"qtdeclarative"
]
},
"Qt5QuickTest": {
"attrPath": [
"qt5",
"qtdeclarative"
]
},
"Qt5QuickWidgets": {
"attrPath": [
"qt5",
"qtdeclarative"
]
},
"Qt5Sql": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5Test": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5Widgets": {
"attrPath": [
"qt5",
"qtbase"
]
},
"Qt5Xml": {
"attrPath": [
"qt5",
"qtbase"
]
},
"SoapySDR": {
"attrPath": [
"soapysdr"
]
},
"alsa": {
"attrPath": [
"alsa-lib"
]
},
"alsa-topology": {
"attrPath": [
"alsa-lib"
]
},
"appindicator-0.1": {
"attrPath": [
"libappindicator-gtk2"
]
},
"appindicator3-0.1": {
"attrPath": [
"libappindicator-gtk3"
]
},
"bzip2": {
"attrPath": [
"bzip2"
]
},
"cairo-gobject": {
"attrPath": [
"cairo"
]
},
"cairo-pdf": {
"attrPath": [
"cairo"
]
},
"cairo-ps": {
"attrPath": [
"cairo"
]
},
"cairo-svg": {
"attrPath": [
"cairo"
]
},
"dbusmenu-glib-0.4": {
"attrPath": [
"libdbusmenu"
]
},
"dbusmenu-gtk3-0.4": {
"attrPath": [
"libdbusmenu-gtk3"
]
},
"egl": {
"attrPath": [
"libGL"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": false
}
},
"fftw3": {
"attrPath": [
"fftw"
]
},
"fftw3f": {
"attrPath": [
"fftwFloat"
]
},
"form": {
"attrPath": [
"ncurses"
]
},
"formw": {
"attrPath": [
"ncurses"
]
},
"freealut": {
"attrPath": [
"freealut"
]
},
"freetype2": {
"attrPath": [
"freetype"
]
},
"gdk-2.0": {
"attrPath": [
"gtk2"
]
},
"gdk-3.0": {
"attrPath": [
"gtk3"
]
},
"gdk-pixbuf-2.0": {
"attrPath": [
"gdk-pixbuf"
]
},
"gdk-x11-2.0": {
"attrPath": [
"gtk2-x11"
]
},
"gdk-x11-3.0": {
"attrPath": [
"gtk3-x11"
]
},
"geos": {
"attrPath": [
"geos"
]
},
"gio-2.0": {
"attrPath": [
"glib"
]
},
"gl": {
"attrPath": [
"libGL"
]
},
"glew": {
"attrPath": [
"glew"
]
},
"glu": {
"attrPath": [
"libGLU"
]
},
"glut": {
"attrPath": [
"freeglut"
]
},
"gnome-keyring-1": {
"attrPath": [
"libgnome-keyring"
]
},
"gnome-vfs-2.0": {
"attrPath": [
"gnome2",
"gnome_vfs"
]
},
"gnome-vfs-module-2.0": {
"attrPath": [
"gnome2",
"gnome_vfs"
]
},
"gobject-2.0": {
"attrPath": [
"glib"
]
},
"gobject-introspection-1.0": {
"attrPath": [
"gobject-introspection"
]
},
"gstreamer-audio-1.0": {
"attrPath": [
"gst_all_1",
"gst-plugins-base"
]
},
"gstreamer-base-1.0": {
"attrPath": [
"gst_all_1",
"gst-plugins-base"
]
},
"gstreamer-controller-1.0": {
"attrPath": [
"gst_all_1",
"gstreamer"
]
},
"gstreamer-net-1.0": {
"attrPath": [
"gst_all_1",
"gst-plugins-base"
]
},
"gstreamer-video-1.0": {
"attrPath": [
"gst_all_1",
"gst-plugins-base"
]
},
"gthread-2.0": {
"attrPath": [
"glib"
]
},
"gtk+-2.0": {
"attrPath": [
"gtk2"
]
},
"gtk+-3.0": {
"attrPath": [
"gtk3"
]
},
"gtk+-x11-2.0": {
"attrPath": [
"gtk2-x11"
]
},
"gtksourceview-3.0": {
"attrPath": [
"gtksourceview3"
]
},
"hidapi": {
"attrPath": [
"hidapi"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": true
}
},
"hidapi-hidraw": {
"attrPath": [
"hidapi"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": false
}
},
"hidapi-libusb": {
"attrPath": [
"hidapi"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": false
}
},
"icu-i18n": {
"attrPath": [
"icu"
]
},
"icu-io": {
"attrPath": [
"icu"
]
},
"icu-uc": {
"attrPath": [
"icu"
]
},
"imlib2": {
"attrPath": [
"imlib2"
]
},
"jack": {
"attrPath": [
"libjack2"
]
},
"javascriptcoregtk-4.0": {
"attrPath": [
"webkitgtk"
]
},
"lapack": {
"attrPath": [
"liblapack"
]
},
"libR": {
"attrPath": [
"R"
]
},
"libavutil": {
"attrPath": [
"ffmpeg"
]
},
"libb2": {
"attrPath": [
"libb2"
]
},
"libbrotlidec": {
"attrPath": [
"brotli"
]
},
"libbrotlienc": {
"attrPath": [
"brotli"
]
},
"libcrypto": {
"attrPath": [
"openssl"
]
},
"libecpg": {
"attrPath": [
"postgresql"
]
},
"libecpg_compat": {
"attrPath": [
"postgresql"
]
},
"libgsasl": {
"attrPath": [
"gsasl"
]
},
"libidn": {
"attrPath": [
"libidn"
]
},
"libjpeg": {
"attrPath": [
"libjpeg"
]
},
"liblzma": {
"attrPath": [
"xz"
]
},
"libmagic": {
"attrPath": [
"file"
]
},
"libmnl": {
"attrPath": [
"libmnl"
]
},
"libnotify": {
"attrPath": [
"libnotify"
]
},
"libpcap": {
"attrPath": [
"libpcap"
]
},
"libpcre": {
"attrPath": [
"pcre"
]
},
"libpcre2-16": {
"attrPath": [
"pcre2"
]
},
"libpcre2-32": {
"attrPath": [
"pcre2"
]
},
"libpcre2-8": {
"attrPath": [
"pcre2"
]
},
"libpcre2-posix": {
"attrPath": [
"pcre2"
]
},
"libpgtypes": {
"attrPath": [
"postgresql"
]
},
"libpng": {
"attrPath": [
"libpng"
]
},
"libpq": {
"attrPath": [
"postgresql"
]
},
"libpulse": {
"attrPath": [
"libpulseaudio"
]
},
"libpulse-mainloop-glib": {
"attrPath": [
"libpulseaudio"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": false
}
},
"libpulse-simple": {
"attrPath": [
"libpulseaudio"
]
},
"libqrencode": {
"attrPath": [
"qrencode"
]
},
"librtlsdr": {
"attrPath": [
"rtl-sdr"
]
},
"libsass": {
"attrPath": [
"libsass"
]
},
"libsctp": {
"attrPath": [
"lksctp-tools"
]
},
"libsecp256k1": {
"attrPath": [
"secp256k1"
]
},
"libsodium": {
"attrPath": [
"libsodium"
]
},
"libsoup-gnome-2.4": {
"attrPath": [
"libsoup"
]
},
"libssh2": {
"attrPath": [
"libssh2"
]
},
"libssl": {
"attrPath": [
"openssl"
]
},
"libstatgrab": {
"attrPath": [
"libstatgrab"
]
},
"libsystemd": {
"attrPath": [
"systemd"
]
},
"libturbojpeg": {
"attrPath": [
"libjpeg"
]
},
"libudev": {
"attrPath": [
"systemd"
]
},
"libxml-2.0": {
"attrPath": [
"libxml2"
]
},
"libzip": {
"attrPath": [
"libzip"
]
},
"libzmq": {
"attrPath": [
"zeromq"
]
},
"menu": {
"attrPath": [
"ncurses"
]
},
"menuw": {
"attrPath": [
"ncurses"
]
},
"ncurses": {
"attrPath": [
"ncurses"
]
},
"ncurses++": {
"attrPath": [
"ncurses"
]
},
"ncurses++w": {
"attrPath": [
"ncurses"
]
},
"ncursesw": {
"attrPath": [
"ncurses"
]
},
"netsnmp": {
"attrPath": [
"net_snmp"
]
},
"nix-cmd": {
"attrPath": [
"nix"
]
},
"nix-expr": {
"attrPath": [
"nix"
]
},
"nix-main": {
"attrPath": [
"nix"
]
},
"nix-store": {
"attrPath": [
"nix"
]
},
"odbc": {
"attrPath": [
"unixODBC"
]
},
"ompi": {
"attrPath": [
"openmpi"
]
},
"ompi-c": {
"attrPath": [
"openmpi"
]
},
"ompi-cxx": {
"attrPath": [
"openmpi"
]
},
"ompi-f77": {
"attrPath": [
"openmpi"
]
},
"ompi-f90": {
"attrPath": [
"openmpi"
]
},
"ompi-fort": {
"attrPath": [
"openmpi"
]
},
"openblas": {
"attrPath": [
"openblasCompat"
]
},
"openssl": {
"attrPath": [
"openssl"
]
},
"orte": {
"attrPath": [
"openmpi"
]
},
"panel": {
"attrPath": [
"ncurses"
]
},
"panelw": {
"attrPath": [
"ncurses"
]
},
"pangocairo": {
"attrPath": [
"pango"
]
},
"poppler-glib": {
"attrPath": [
"poppler_gi"
]
},
"python": {
"attrPath": [
"python3"
]
},
"ruby-2.7": {
"attrPath": [
"ruby_2_7"
]
},
"ruby-3.0": {
"attrPath": [
"ruby_3_0"
]
},
"ruby-3.1": {
"attrPath": [
"ruby_3_1"
]
},
"sdl2": {
"attrPath": [
"SDL2"
]
},
"sndfile": {
"attrPath": [
"libsndfile"
]
},
"sqlite3": {
"attrPath": [
"sqlite"
]
},
"taglib": {
"attrPath": [
"taglib"
]
},
"taglib_c": {
"attrPath": [
"taglib"
]
},
"tdjson": {
"attrPath": [
"tdlib"
]
},
"tensorflow": {
"attrPath": [
"libtensorflow"
]
},
"uuid": {
"attrPath": [
"libossp_uuid"
]
},
"vte-2.91": {
"attrPath": [
"vte"
]
},
"wayland-client": {
"attrPath": [
"wayland"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": false
}
},
"wayland-cursor": {
"attrPath": [
"wayland"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": false
}
},
"wayland-scanner": {
"attrPath": [
"wayland"
]
},
"wayland-server": {
"attrPath": [
"wayland"
],
"supportedWhenPlatformAttrsEqual": {
"isDarwin": false
}
},
"webkit2gtk-4.0": {
"attrPath": [
"webkitgtk"
]
},
"webkit2gtk-web-extension-4.0": {
"attrPath": [
"webkitgtk"
]
},
"x11": {
"attrPath": [
"xorg",
"libX11"
]
},
"xau": {
"attrPath": [
"xorg",
"libXau"
]
},
"xcursor": {
"attrPath": [
"xorg",
"libXcursor"
]
},
"xerces-c": {
"attrPath": [
"xercesc"
]
},
"xext": {
"attrPath": [
"xorg",
"libXext"
]
},
"xft": {
"attrPath": [
"xorg",
"libXft"
]
},
"xi": {
"attrPath": [
"xorg",
"libXi"
]
},
"xinerama": {
"attrPath": [
"xorg",
"libXinerama"
]
},
"xkbcommon": {
"attrPath": [
"libxkbcommon"
]
},
"xpm": {
"attrPath": [
"xorg",
"libXpm"
]
},
"xrandr": {
"attrPath": [
"xorg",
"libXrandr"
]
},
"xrender": {
"attrPath": [
"xorg",
"libXrender"
]
},
"xscrnsaver": {
"attrPath": [
"xorg",
"libXScrnSaver"
]
},
"xtst": {
"attrPath": [
"xorg",
"libXtst"
]
},
"xxf86vm": {
"attrPath": [
"xorg",
"libXxf86vm"
]
},
"yaml-0.1": {
"attrPath": [
"libyaml"
]
},
"zlib": {
"attrPath": [
"zlib"
]
}
}
}

View file

@ -0,0 +1,45 @@
# cd nixpkgs
# nix-build -A tests.pkg-config.defaultPkgConfigPackages
{ lib, pkg-config, defaultPkgConfigPackages, runCommand, testers }:
let
inherit (lib.strings) escapeNixIdentifier;
allTests = lib.mapAttrs (k: v: if v == null then null else makePkgConfigTestMaybe k v) defaultPkgConfigPackages;
# nix-build rejects attribute names with periods
# This will build those regardless.
tests-combined = runCommand "pkg-config-checks" {
allTests = lib.attrValues allTests;
} ''
touch $out
'';
makePkgConfigTestMaybe = moduleName: pkg:
if ! lib.isDerivation pkg
then
throw "pkg-config module `${escapeNixIdentifier moduleName}` is not defined to be a derivation. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config-packages.nix` in Nixpkgs."
else if ! pkg?meta.unsupported
then
throw "pkg-config module `${escapeNixIdentifier moduleName}` does not have a `meta.unsupported` attribute. This can't be right. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config-packages.nix` in Nixpkgs."
else if pkg.meta.unsupported
then
# We return `null` instead of doing a `filterAttrs`, because with
# `filterAttrs` the evaluator would not be able to return the attribute
# set without first evaluating all of the attribute _values_. This would
# be rather expensive, and severly slow down the use case of getting a
# single test, which we want to do in `passthru.tests`, or interactively.
null
else if ! pkg?meta.broken
then
throw "pkg-config module `${escapeNixIdentifier moduleName}` does not have a `meta.broken` attribute. This can't be right. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config.packages.nix` in Nixpkgs."
else if pkg.meta.broken
then null
else testers.hasPkgConfigModule { inherit moduleName; package = pkg; };
in
lib.recurseIntoAttrs allTests // { inherit tests-combined; }

View file

@ -0,0 +1,21 @@
# cd nixpkgs
# nix-build -A tests.pkg-config
{ lib, stdenv, ... }:
let
# defaultPkgConfigPackages test needs a Nixpkgs with allowUnsupportedPlatform
# in order to filter out the unsupported packages without throwing any errors
# tryEval would be too fragile, masking different problems as if they're
# unsupported platform problems.
allPkgs = import ../default.nix {
system = stdenv.hostPlatform.system;
localSystem = stdenv.hostPlatform.system;
config = {
allowUnsupportedSystem = true;
};
overlays = [];
};
in
lib.recurseIntoAttrs {
defaultPkgConfigPackages = allPkgs.callPackage ./test-defaultPkgConfigPackages.nix { };
}