Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace collectRunComponents with haskellLib.check #316

Merged
merged 52 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8ae8b5a
Add collectRunComponents. Move checkPhase to .run
hamishmack Nov 14, 2019
349abfa
Reduce duplicate code
hamishmack Nov 14, 2019
cfb1699
Add comment for passthru.run
hamishmack Nov 14, 2019
de8c4ad
Update docs for collectRunComponents
hamishmack Nov 14, 2019
b29de00
Update builder/comp-builder.nix
hamishmack Nov 14, 2019
47e0bb7
`collectBuildComponents` to `collectComponents`
hamishmack Nov 14, 2019
cee580c
Relocate binary for benchmarks/tests (not in all)
hamishmack Nov 18, 2019
42c7cce
Add package.run.(exes/tests/benchmaks).${name}
hamishmack Nov 18, 2019
a51248c
Try ln -s instead of cp for DLLs
hamishmack Nov 18, 2019
848c395
improve speed of make-config-files (#318)
Nov 20, 2019
b68c60e
use ld.gold by default on linux
Nov 20, 2019
e6505d5
Merge remote-tracking branch 'origin/master' into hkm/passthru-run-2
hamishmack Nov 21, 2019
4d619a7
Just include checks for compontent.tests
hamishmack Nov 21, 2019
9b9fa13
Add ifdInputsOnly and set it to true in relase.nix
hamishmack Nov 20, 2019
a43d302
Reduce CI times by excluding older ghc versions
hamishmack Nov 21, 2019
a9d867d
Enable all tests again
hamishmack Nov 20, 2019
c54a039
Test IFD inputs only
hamishmack Nov 21, 2019
d8314a7
haskellLib.check instead of passthru.run
hamishmack Nov 21, 2019
b6975b5
Enable all tests again
hamishmack Nov 21, 2019
cf15c36
Default doCheck=true. Filter checks on doCheck
hamishmack Nov 22, 2019
77e0098
Merge remote-tracking branch 'Simspace/faster-make-config-files' into…
hamishmack Nov 22, 2019
8323b9c
Merge remote-tracking branch 'Simspace/ld.gold' into hkm/performance-…
hamishmack Nov 22, 2019
d07ffb0
Add ifdInputsOnly and set it to true in relase.nix
hamishmack Nov 20, 2019
013c0fd
Reduce CI times by excluding older ghc versions
hamishmack Nov 21, 2019
896854b
Enable all tests again
hamishmack Nov 21, 2019
64afed9
Improve ifdInputsOnly to include more ifd inputs
hamishmack Nov 23, 2019
3ce1b29
Improve ifdInputsOnly to include more ifd inputs
hamishmack Nov 23, 2019
64689a4
Improve ifdInputsOnly to include more ifd inputs
hamishmack Nov 23, 2019
bf5dc77
Improve ifdInputsOnly to include more ifd inputs
hamishmack Nov 23, 2019
79a7f9f
Improve ifdInputsOnly to include more ifd inputs
hamishmack Nov 23, 2019
bb5daae
Merge remote-tracking branch 'origin/master' into hkm/passthru-run-2
hamishmack Nov 23, 2019
37b9e11
Improve ifdInputsOnly to include more ifd inputs
hamishmack Nov 23, 2019
ec4a4eb
Enable all tests again
hamishmack Nov 23, 2019
e8fae60
ifdInputs only
hamishmack Nov 23, 2019
c6ab443
Include build inputs of ifd nix derivations
hamishmack Nov 23, 2019
1dc1708
Try using ifd level to better control hydra eval
hamishmack Nov 24, 2019
a1e0b92
Set `preferLocalBuild=false` instead of withInputs
hamishmack Nov 24, 2019
a8a044f
Only build tests when ifdLevel>1
hamishmack Nov 24, 2019
e861f35
ifdLevel = 1
hamishmack Nov 24, 2019
fff24e4
ifdLevel = 2
hamishmack Nov 24, 2019
d8199c4
Run check-hydra on all the IFD levels
hamishmack Nov 24, 2019
5a321d3
Run check-hydra on all the IFD levels
hamishmack Nov 24, 2019
6021f5d
Only build ghc-extra-packages for ghc865
hamishmack Nov 24, 2019
b79da5f
Only build ghc-extra-packages for ghc865
hamishmack Nov 24, 2019
4cf064f
Fix maintainer scripts
hamishmack Nov 24, 2019
192737c
Skip check-hydra on windows
hamishmack Nov 24, 2019
27ce94c
Skip check-hydra on windows
hamishmack Nov 24, 2019
c2be4ab
ifdLevel = 3
hamishmack Nov 24, 2019
344abd7
Fix `data-dir:` when cleaning components
hamishmack Nov 27, 2019
fa15c3a
Make test component source available in check
hamishmack Nov 29, 2019
46cd1a8
Remove collectRunComponents. Doc haskellLib.check
hamishmack Nov 29, 2019
d635a22
Merge remote-tracking branch 'origin/master' into hkm/passthru-run-2
hamishmack Nov 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ steps:
- label: 'Check that jobset will evaluate in Hydra'
command:
- nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh
- ./check-hydra.sh
- ./check-hydra.sh 0
- ./check-hydra.sh 1
- ./check-hydra.sh 2
- ./check-hydra.sh 3
agents:
system: x86_64-linux

Expand Down
42 changes: 22 additions & 20 deletions build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,19 @@
, crossSystem ? null
, config ? {}
, nixpkgsArgs ? { inherit system crossSystem; }
, ifdLevel ? 1000
}:

let
haskellNixArgs = import ./default.nix;
pkgs = import nixpkgs ({
config = haskellNixArgs.config // config;
overlays = haskellNixArgs.overlays ++
[(self: super: {
darcs = (self.haskell-nix.hackage-package {
name = "darcs";
version = "2.14.2";
index-state = "2019-10-28T00:00:00Z";
plan-sha256 = "1h8dxib0wz6mg8md6ldwa54dsr1dn7vxfij8cfhdawl4y3wr51k0";
# Apply the latest darcs.net Setup.hs patches
modules = [{packages.darcs.patches = [ ./patches/darcs-setup.patch ];}];
}).components.exes.darcs;
})]; } // nixpkgsArgs);
config = haskellNixArgs.config // config;
inherit (haskellNixArgs) overlays;
} // nixpkgsArgs);
haskell = pkgs.haskell-nix;

in rec {
tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs; };
tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs ifdLevel; };

# Scripts for keeping Hackage and Stackage up to date, and CI tasks.
# The dontRecurseIntoAttrs prevents these from building on hydra
Expand All @@ -52,6 +44,11 @@ in rec {
}) {};
};
};
# Because this is going to be used to test caching on hydra, it must not
# use the darcs package from the haskell.nix we are testing. For that reason
# it uses `pkgs.buildPackages.callPackage` not `haskell.callPackage`
# (We could pull in darcs from a known good haskell.nix for hydra to
# use)
check-hydra = pkgs.buildPackages.callPackage ./scripts/check-hydra.nix {};
check-closure-size = pkgs.buildPackages.callPackage ./scripts/check-closure-size.nix {
inherit (haskell) nix-tools;
Expand All @@ -60,11 +57,16 @@ in rec {

# These are pure parts of maintainer-script so they can be built by hydra
# and added to the cache to speed up buildkite.
maintainer-script-cache = pkgs.recurseIntoAttrs {
inherit (maintainer-scripts) update-docs check-hydra check-closure-size;
# Some of the dependencies of the impure scripts so that they will
# will be in the cache too for buildkite.
inherit (pkgs.buildPackages) glibc coreutils git openssh cabal-install nix-prefetch-git;
inherit (haskell) nix-tools;
};
maintainer-script-cache = pkgs.recurseIntoAttrs (
(pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isWindows {
inherit (maintainer-scripts) check-hydra;
})
// (pkgs.lib.optionalAttrs (ifdLevel > 2) {
inherit (maintainer-scripts) update-docs check-closure-size;
# Some of the dependencies of the impure scripts so that they will
# will be in the cache too for buildkite.
inherit (pkgs.buildPackages) glibc coreutils git openssh cabal-install nix-prefetch-git;
inherit (haskell) nix-tools;
})
);
}
46 changes: 16 additions & 30 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
, preHaddock ? component.preHaddock , postHaddock ? component.postHaddock
, shellHook ? ""

, doCheck ? component.doCheck || haskellLib.isTest componentId
, doCrossCheck ? component.doCrossCheck || false
, dontPatchELF ? true
, dontStrip ? true

Expand Down Expand Up @@ -128,13 +126,7 @@ let

exeExt = lib.optionalString stdenv.hostPlatform.isWindows ".exe";
testExecutable = "dist/build/${componentId.cname}/${componentId.cname}${exeExt}";
# exe components are in /bin, but test and benchmarks are not. Perhaps to avoid
# them being from being added to the PATH when the all component added to an env.
# TODO revist this to find out why and document or maybe change this.
installedExeDir = if haskellLib.isTest componentId || haskellLib.isBenchmark componentId
then name
else "bin";
installedExe = "${installedExeDir}/${componentId.cname}${exeExt}";
installedExe = "bin/${componentId.cname}${exeExt}";

in stdenv.lib.fix (drv:

Expand All @@ -143,20 +135,20 @@ stdenv.mkDerivation ({

src = cleanSrc;

inherit doCheck doCrossCheck dontPatchELF dontStrip;
doCheck = false;
doCrossCheck = false;

inherit dontPatchELF dontStrip;

passthru = {
inherit (package) identifier;
config = component;
inherit configFiles executableToolDepends cleanSrc;
inherit configFiles executableToolDepends cleanSrc installedExe;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be helpful

env = shellWrappers;

# The directory containing the haddock documentation.
# `null' if no haddock documentation was built.
haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null;
run = runCommand (fullName + "-run") {} ''
${toString component.testWrapper} ${drv}/${installedExe} | tee $out
'';
};

meta = {
Expand Down Expand Up @@ -217,13 +209,7 @@ stdenv.mkDerivation ({
runHook postBuild
'';

checkPhase = ''
runHook preCheck

${toString component.testWrapper} ${testExecutable} ${lib.concatStringsSep " " component.testFlags}

runHook postCheck
'';
checkPhase = "notice: Tests are only executed by building the .run sub-derivation of this component.";

haddockPhase = ''
runHook preHaddock
Expand Down Expand Up @@ -281,25 +267,25 @@ stdenv.mkDerivation ({
fi
''}
${(lib.optionalString (haskellLib.isTest componentId || haskellLib.isBenchmark componentId || haskellLib.isAll componentId) ''
mkdir -p $out/${name}
mkdir -p $out/bin
if [ -f ${testExecutable} ]; then
cp ${testExecutable} $out/${name}/
cp ${testExecutable} $out/bin/
fi
'')
# In case `setup copy` did not creat this
+ (lib.optionalString enableSeparateDataOutput "mkdir -p $data")
+ (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) ''
echo "Copying libffi and gmp .dlls ..."
echo "Symlink libffi and gmp .dlls ..."
for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do
find "$p" -iname '*.dll' -exec cp {} $out/${installedExeDir} \;
find "$p" -iname '*.dll' -exec ln -s {} $out/bin \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's better/possible to do this symlinking of DLLs only when running the check phase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to do it here or running without using haskellLib.check fail.

done
# copy all .dlls into the local directory.
# symlink all .dlls into the local directory.
# we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set
# to copy over dlls as needed.
echo "Copying library dependencies..."
# to symlink over dlls as needed.
echo "Symlink library dependencies..."
for libdir in $(x86_64-pc-mingw32-ghc-pkg --package-db=$packageConfDir field "*" dynamic-library-dirs --simple-output|xargs|sed 's/ /\n/g'|sort -u); do
if [ -d "$libdir" ]; then
find "$libdir" -iname '*.dll' -exec cp {} $out/${installedExeDir} \;
find "$libdir" -iname '*.dll' -exec ln -s {} $out/bin \;
fi
done
'')
Expand All @@ -316,7 +302,7 @@ stdenv.mkDerivation ({
// lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; }
// haskellLib.optionalHooks {
inherit preUnpack postUnpack preConfigure postConfigure
preBuild postBuild preCheck postCheck
preBuild postBuild
preInstall postInstall preHaddock postHaddock;
}
// lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${buildPackages.glibcLocales}/lib/locale/locale-archive"; }
Expand Down
5 changes: 4 additions & 1 deletion builder/hspkg-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ let
;
};

in {
in rec {
components = haskellLib.applyComponents buildComp config;
checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
(_: d: haskellLib.check d)
(lib.filterAttrs (_: d: d.config.doCheck) components.tests));
inherit (package) identifier detailLevel isLocal;
inherit setup cabalFile;
isHaskell = true;
Expand Down
18 changes: 17 additions & 1 deletion docs/reference/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ Infrastructure.
Extracts a selection of components from a Haskell [package set](#package-set).

This can be used to filter out all test suites or benchmarks of
your project, so that they can be built in Hydra.
your project, so that they can be built in Hydra (see check if you
waht to run the tests as well as build them).

```
collectComponents =
Expand All @@ -311,6 +312,21 @@ tests = collectComponents "tests" (package: package.identifier.name == "mypackag
Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests`
to `tests.mypackage.unit-tests`.

#### check

This function turns a derivation that builds a test into one to run it.

| Argument | Type | Description |
|-------------------|--------|---------------------|
| `drv` | Derivation | One of `$pkg.components.tests.$test`. |

For convenience `$pkg.components.tests` are mapped with this function
to `$pkg.components.checks`.

This function is intended for use with `tests` but it should also work
for `exes` and `benchmarks` if you just want to run them to make sure
they execute.

#### subComponentTypes

Sub-component types identify [components](#component) and are one of:
Expand Down
3 changes: 2 additions & 1 deletion lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ let
}
else replaceSoureRepos rawCabalProject;

plan-nix = runCommand "plan-to-nix-pkgs" ({
plan-nix = runCommand (if name == null then "plan-to-nix-pkgs" else name + "-plan-to-nix-pkgs") ({
nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ];
# Needed or stack-to-nix will die on unicode inputs
LANG = "en_US.UTF-8";
preferLocalBuild = false;
} // (if plan-sha256 == null
then {}
else {
Expand Down
1 change: 1 addition & 0 deletions lib/call-stack-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let
LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive";
LANG = "en_US.UTF-8";
LC_ALL = "en_US.UTF-8";
preferLocalBuild = false;
} (''
mkdir -p $out
'' + pkgs.lib.optionalString (cache != null) ''
Expand Down
42 changes: 42 additions & 0 deletions lib/check.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{ stdenv, lib, haskellLib, srcOnly }:
drv:

let
component = drv.config;

# This derivation can be used to execute test component.
# The $out of the derivation is a file containing the resulting
# stdout output.
in stdenv.mkDerivation ({
name = (drv.name + "-check");

# Useing `srcOnly` (rather than getting the `src` via a `drv.passthru`)
# should correctly apply the patches from `drv` (if any).
src = srcOnly drv;

passthru = {
inherit (drv) identifier config configFiles executableToolDepends cleanSrc env;
};

inherit (drv) meta LANG LC_ALL;

inherit (component) doCheck doCrossCheck;

phases = ["buildPhase" "checkPhase"];

# If doCheck or doCrossCheck are false we may still build this
# component and we want it to quietly succeed.
buildPhase = ''
touch $out
'';

checkPhase = ''
runHook preCheck

${toString component.testWrapper} ${drv}/${drv.installedExe} ${lib.concatStringsSep " " component.testFlags} | tee $out

runHook postCheck
'';
} // haskellLib.optionalHooks {
inherit (component) preCheck postCheck;
})
7 changes: 6 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, haskellLib, runCommand, git }:
{ stdenv, lib, haskellLib, runCommand, git, srcOnly }:

with haskellLib;

Expand Down Expand Up @@ -149,4 +149,9 @@ with haskellLib;
cleanGit = import ./clean-git.nix {
inherit lib runCommand git cleanSourceWith;
};

# Check a test component
check = import ./check.nix {
inherit stdenv lib haskellLib srcOnly;
};
}
2 changes: 1 addition & 1 deletion modules/plan.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let
};
doCheck = mkOption {
type = bool;
default = (def.doCheck or false);
default = (def.doCheck or true);
};
doCrossCheck = mkOption {
description = "Run doCheck also in cross compilation settings. This can be tricky as the test logic must know how to run the tests on the target.";
Expand Down
6 changes: 3 additions & 3 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ self: super: {
index-state = "2019-10-20T00:00:00Z";
plan-sha256 = "086kd6aa5bir3y4aqb1wl5zkj6agz5q4wp4snvdnf6cidz5wra06";
};
alex = bootstrap.packages.alex-project.alex.components.exes.alex;
alex = bootstrap.packages.alex-project.hsPkgs.alex.components.exes.alex;
happy-project = hackage-project {
# Only a boot compiler is suitable here
ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
Expand All @@ -276,7 +276,7 @@ self: super: {
index-state = "2019-10-20T00:00:00Z";
plan-sha256 = "011bxlxdv239psgi80j00km2wcgb68j16sz3fng67d03sqf5i37w";
};
happy = bootstrap.packages.happy-project.happy.components.exes.happy;
happy = bootstrap.packages.happy-project.hsPkgs.happy.components.exes.happy;
hscolour-project = hackage-project {
# Only a boot compiler is suitable here
ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
Expand All @@ -285,7 +285,7 @@ self: super: {
index-state = "2019-10-20T00:00:00Z";
plan-sha256 = "021rwcmkshibc3mfr833ay5hfr19kq6k32lxyrrb6vp9vmihgw4b";
};
hscolour = bootstrap.packages.hscolour-project.hscolour.components.exes.HsColour;
hscolour = bootstrap.packages.hscolour-project.hsPkgs.hscolour.components.exes.HsColour;
};
};
};
Expand Down
Loading