Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cdepillabout committed Feb 7, 2020
1 parent 5f9bdc5 commit f7dc472
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 25 deletions.
34 changes: 24 additions & 10 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ stdenv, buildPackages, ghc, lib, pkgconfig, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs, runCommand, libffi, gmp }:

{ componentId
{ allComponent
, componentId
, component
, package
, name
Expand All @@ -19,6 +20,7 @@
, preInstall ? component.preInstall , postInstall ? component.postInstall
, preHaddock ? component.preHaddock , postHaddock ? component.postHaddock
, shellHook ? ""
, isDoctest ? component.isDoctest

, dontPatchELF ? component.dontPatchELF
, dontStrip ? component.dontStrip
Expand Down Expand Up @@ -52,10 +54,19 @@ let
then "${name}-all"
else "${name}-${componentId.ctype}-${componentId.cname}";

configFiles = makeConfigFiles {
inherit (package) identifier;
inherit component fullName flags;
};
configFiles =
if isDoctest
then
makeConfigFiles {
inherit (package) identifier;
component = allComponent;
inherit fullName flags;
}
else
makeConfigFiles {
inherit (package) identifier;
inherit component fullName flags;
};

enableFeature = enable: feature:
(if enable then "--enable-" else "--disable-") + feature;
Expand All @@ -64,7 +75,7 @@ let

finalConfigureFlags = lib.concatStringsSep " " (
[ "--prefix=$out"
"${haskellLib.componentTarget componentId}"
"${haskellLib.componentSetupTarget componentId component}"
"$(cat ${configFiles}/configure-flags)"
# GHC
"--with-ghc=${ghc.targetPrefix}ghc"
Expand Down Expand Up @@ -188,10 +199,11 @@ stdenv.mkDerivation ({

SETUP_HS = setup + /bin/Setup;

outputs = ["out" ]
outputs = ["out"]
++ (lib.optional enableSeparateDataOutput "data")
++ (lib.optional doHaddock' "doc")
++ (lib.optional keepSource "source");
++ (lib.optional keepSource "source")
++ (lib.optional isDoctest "dist");

# Phases
preInstallPhases = lib.optional doHaddock' "haddockPhase";
Expand Down Expand Up @@ -219,7 +231,7 @@ stdenv.mkDerivation ({
buildPhase = ''
runHook preBuild
# https://gitlab.haskell.org/ghc/ghc/issues/9221
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " (component.setupBuildFlags ++ setupGhcOptions)}
$SETUP_HS build ${haskellLib.componentBuildTarget componentId component} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " (component.setupBuildFlags ++ setupGhcOptions)}
runHook postBuild
'';

Expand Down Expand Up @@ -325,7 +337,9 @@ stdenv.mkDerivation ({
'')
}
runHook postInstall
'' + (lib.optionalString keepSource ''
'' + (lib.optionalString isDoctest ''
cp -r dist/ $dist/
'') + (lib.optionalString keepSource ''
rm -rf dist
'');

Expand Down
6 changes: 3 additions & 3 deletions builder/hspkg-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ let
inherit (config) preUnpack postUnpack;
};

buildComp = componentId: component: comp-builder {
inherit componentId component package name src flags setup cabalFile cabal-generator patches revision
buildComp = allComponent: componentId: component: comp-builder {
inherit allComponent componentId component package name src flags setup cabalFile cabal-generator patches revision
shellHook
;
};

in rec {
components = haskellLib.applyComponents buildComp config;
components = haskellLib.applyComponents (buildComp config.components.all) config;
checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
(_: d: haskellLib.check d)
(lib.filterAttrs (_: d: d.config.doCheck) components.tests));
Expand Down
34 changes: 24 additions & 10 deletions lib/check.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
in stdenv.mkDerivation ({
name = (drv.name + "-check");

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

Expand All @@ -26,15 +26,29 @@ in stdenv.mkDerivation ({

# If doCheck or doCrossCheck are false we may still build this
# component and we want it to quietly succeed.
buildPhase = ''
touch $out
runHook preCheck
${toString component.testWrapper} ${drv}/bin/${drv.exeName} ${lib.concatStringsSep " " component.testFlags} | tee $out
runHook postCheck
'';
buildPhase =
(lib.optionalString component.isDoctest ''
# cabal-doctest assumes we are running tests in a directory with the same
# name as when we built the test.
this_dir_name=$(pwd)
src_basename="$(basename "${drv.cleanSrc}")"
cd ../
mv "$this_dir_name" "$src_basename"
cd "$src_basename"
# cabal-doctest needs the ./dist directory available to get auto-generated
# modules.
cp -r ${drv.dist} ./dist
chmod u+w -R ./dist
'') + ''
touch $out
runHook preCheck
${toString component.testWrapper} ${drv}/bin/${drv.exeName} ${lib.concatStringsSep " " component.testFlags} | tee $out
runHook postCheck
'';
} // haskellLib.optionalHooks {
inherit (component) preCheck postCheck;
}
Expand Down
16 changes: 14 additions & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,20 @@ with haskellLib;

# Format a componentId as it should appear as a target on the
# command line of the setup script.
componentTarget = componentId:
if componentId.ctype == "all" then ""
componentSetupTarget = componentId: component:
if componentId.ctype == "all"
then ""
else
if component.isDoctest
# TODO: Why is this needed???
then "--enable-tests"
else "${componentId.ctype}:${componentId.cname}";

# Format a componentId as it should appear as a target on the
# command line of the setup script.
componentBuildTarget = componentId: component:
if componentId.ctype == "all"
then ""
else "${componentId.ctype}:${componentId.cname}";

# Remove null or empty values from an attrset.
Expand Down
4 changes: 4 additions & 0 deletions modules/plan.nix
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ let
type = bool;
default = (def.enableShared or true);
};
isDoctest = mkOption {
type = bool;
default = false;
};
shellHook = mkOption {
description = "Hook to run when entering a shell";
type = unspecified; # Can be either a string or a function
Expand Down

0 comments on commit f7dc472

Please sign in to comment.