Skip to content

Commit

Permalink
Try moving envDep and exactDep into component lib
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Dec 11, 2019
1 parent f5d1f82 commit bc59366
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
26 changes: 25 additions & 1 deletion builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ stdenv.mkDerivation ({
#
# Note 3: if a package has no libs SETUP will not generate anything. This can
# happen when building the `all` component of a package.
installPhase = ''
installPhase = let
target-pkg-and-db = "${ghc.targetPrefix}ghc-pkg -v0 --package-db $out/package.conf.d";
in ''
runHook preInstall
$SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
${lib.optionalString (haskellLib.isLibrary componentId || haskellLib.isAll componentId) ''
Expand All @@ -272,6 +274,28 @@ stdenv.mkDerivation ({
elif [ -e "${name}.conf" ]; then
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
fi
mkdir -p $out/exactDep
touch $out/exactDep/configure-flags
touch $out/exactDep/cabal.config
if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
echo "--dependency=${package.identifier.name}=$id" >> $out/exactDep/configure-flags
elif id=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" id --simple-output); then
name=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" name --simple-output)
# so we are dealing with a sublib. As we build sublibs separately, the above
# query should be safe.
echo "--dependency=''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
fi
if ver=$(${target-pkg-and-db} field ${package.identifier.name} version --simple-output); then
echo "constraint: ${package.identifier.name} == $ver" >> $out/exactDep/cabal.config
echo "constraint: ${package.identifier.name} installed" >> $out/exactDep/cabal.config
fi
touch $out/envDep
if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
echo "package-id $id" >> $out/envDep
fi
''}
${(lib.optionalString (haskellLib.isTest componentId || haskellLib.isBenchmark componentId || haskellLib.isAll componentId) ''
mkdir -p $out/bin
Expand Down
6 changes: 3 additions & 3 deletions builder/make-config-files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let
'';

catPkgExactDep = p:
catExactDep (exactDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
catExactDep ((p.components.library or p) + "/exactDep");

catGhcPkgExactDep = p: catExactDep (exactDep "" p [ghc]);

Expand All @@ -63,7 +63,7 @@ let
'';

catPkgEnvDep = p:
catEnvDep (envDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
catEnvDep ((p.components.library or p) + "/envDep");

catGhcPkgEnvDep = p: catEnvDep (envDep "" p [ghc]);

Expand All @@ -87,7 +87,7 @@ in { identifier, component, fullName, flags ? {} }:
${lib.concatMapStringsSep "\n" (p: ''
cp -f "${p}/package.conf.d/"*.conf $out/package.conf.d
'') (haskellLib.flatLibDepends component)}
'') (builtins.trace (toString (builtins.length (haskellLib.flatLibDepends component)) + " " + toString (builtins.length component.depends)) haskellLib.flatLibDepends component)}
# Note: we pass `clear` first to ensure that we never consult the implicit global package db.
${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}
Expand Down

0 comments on commit bc59366

Please sign in to comment.