nixpkgs-suyu/pkgs/test/cross/default.nix

91 lines
2.5 KiB
Nix
Raw Normal View History

{ pkgs, lib }:
2018-07-21 04:43:55 +02:00
let
testedSystems = lib.filterAttrs (name: value: let
platform = lib.systems.elaborate value;
in platform.isLinux || platform.isWindows
) lib.systems.examples;
2018-07-21 04:43:55 +02:00
getExecutable = pkgs: pkgFun: exec:
"${pkgFun pkgs}${exec}${pkgs.hostPlatform.extensions.executable}";
compareTest = { emulator, pkgFun, hostPkgs, crossPkgs, exec, args ? [] }: let
pkgName = (pkgFun hostPkgs).name;
args' = lib.concatStringsSep " " args;
in pkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" {
nativeBuildInputs = [ pkgs.dos2unix ];
} ''
# Just in case we are using wine, get rid of that annoying extra
# stuff.
export WINEDEBUG=-all
2018-07-21 04:43:55 +02:00
HOME=$(pwd)
mkdir -p $out
# We need to remove whitespace, unfortunately
# Windows programs use \r but Unix programs use \n
# find expected value natively
${getExecutable hostPkgs pkgFun exec} ${args'} \
| dos2unix > $out/expected
# run emulator to get actual value
${emulator} ${getExecutable crossPkgs pkgFun exec} ${args'} \
| dos2unix > $out/actual
if [ "$(cat $out/actual)" != "$(cat $out/expected)" ]; then
echo "${pkgName} did not output expected value:"
cat $out/expected
echo "instead it output:"
cat $out/actual
exit 1
else
echo "${pkgName} test passed"
echo "both produced output:"
cat $out/actual
fi
'';
mapMultiPlatformTest = test: lib.mapAttrs (name: system: test rec {
crossPkgs = import pkgs.path {
localSystem = { inherit (pkgs.hostPlatform) config; };
crossSystem = system;
};
2018-07-21 04:43:55 +02:00
emulator = crossPkgs.hostPlatform.emulator pkgs;
2018-07-21 04:43:55 +02:00
# Apply some transformation on windows to get dlls in the right
# place. Unfortunately mingw doesnt seem to be able to do linking
# properly.
platformFun = pkg: if crossPkgs.hostPlatform.isWindows then
pkgs.buildEnv {
name = "${pkg.name}-winlinks";
paths = [pkg] ++ pkg.buildInputs;
} else pkg;
}) testedSystems;
2018-07-21 04:43:55 +02:00
in
lib.mapAttrs (_: mapMultiPlatformTest) {
2018-07-21 04:43:55 +02:00
file = {platformFun, crossPkgs, emulator}: compareTest {
2018-07-21 04:43:55 +02:00
inherit emulator crossPkgs;
hostPkgs = pkgs;
exec = "/bin/file";
args = [
"${pkgs.file}/share/man/man1/file.1.gz"
"${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuMathTeXGyre.ttf"
];
pkgFun = pkgs: platformFun pkgs.file;
};
hello = {platformFun, crossPkgs, emulator}: compareTest {
inherit emulator crossPkgs;
hostPkgs = pkgs;
exec = "/bin/hello";
pkgFun = pkgs: pkgs.hello;
};
}