@@ -325,31 +325,43 @@ let
325 ${lib.optionalString (haskellLib.isLibrary componentId) ''
325 ${lib.optionalString (haskellLib.isLibrary componentId) ''
326 $SETUP_HS register --gen-pkg-config=${name}.conf
326 $SETUP_HS register --gen-pkg-config=${name}.conf
327 ${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
327 ${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
328− if [ -d "${name}.conf" ]; then
329− for pkg in ${name}.conf/*; do
330− ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register "$pkg"
332− elif [ -e "${name}.conf" ]; then
333− ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register ${name}.conf
328+ ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register ${name}.conf
336 mkdir -p $out/exactDep
330 mkdir -p $out/exactDep
337 touch $out/exactDep/configure-flags
331 touch $out/exactDep/configure-flags
338 touch $out/exactDep/cabal.config
332 touch $out/exactDep/cabal.config
339 touch $out/envDep
333 touch $out/envDep
335+ ${ # The main library in a package has the same name as the package
336+ if package.identifier.name == componentId.cname
341− if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
338+ if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
342− echo "--dependency=${package.identifier.name}=$id" >> $out/exactDep/configure-flags
339+ echo "--dependency=${package.identifier.name}=$id" >> $out/exactDep/configure-flags
343− echo "package-id $id" >> $out/envDep
340+ echo "package-id $id" >> $out/envDep
344− elif id=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" id --simple-output); then
341+ else
345− name=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" name --simple-output)
342+ echo 'ERROR: ${package.identifier.name} id could not be found with ${target-pkg-and-db}'
347+ # If the component name is not the package name this must be a sublib.
346− # so we are dealing with a sublib. As we build sublibs separately, the above
348+ # As we build sublibs separately, the following query should be safe.
347− # query should be safe.
349+ (''
350+ if id=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" id --simple-output); then
351+ name=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" name --simple-output)
352+ echo "--dependency=''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
354+ # Allow `package-name:sublib-name` to work in `build-depends`
355+ # by adding the same `--dependency` again, but with the package
348− echo "--dependency=''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
358+ echo "--dependency=${package.identifier.name}:''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
350− echo 'ERROR: ${package.identifier.name} id could not be found with ${target-pkg-and-db}'
360+ echo 'ERROR: ${package.identifier.name} id could not be found with ${target-pkg-and-db}'
353 if ver=$(${target-pkg-and-db} field ${package.identifier.name} version --simple-output); then
365 if ver=$(${target-pkg-and-db} field ${package.identifier.name} version --simple-output); then
354 echo "constraint: ${package.identifier.name} == $ver" >> $out/exactDep/cabal.config
366 echo "constraint: ${package.identifier.name} == $ver" >> $out/exactDep/cabal.config
355 echo "constraint: ${package.identifier.name} installed" >> $out/exactDep/cabal.config
367 echo "constraint: ${package.identifier.name} installed" >> $out/exactDep/cabal.config
@@ -372,21 +384,23 @@ let
373 # In case `setup copy` did not create this
385 # In case `setup copy` did not create this
374 + (lib.optionalString enableSeparateDataOutput "mkdir -p $data")
386 + (lib.optionalString enableSeparateDataOutput "mkdir -p $data")
375− + (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) ''
387+ + (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) (''
376 echo "Symlink libffi and gmp .dlls ..."
388 echo "Symlink libffi and gmp .dlls ..."
377 for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do
389 for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do
378 find "$p" -iname '*.dll' -exec ln -s {} $out/bin \;
390 find "$p" -iname '*.dll' -exec ln -s {} $out/bin \;
380 # symlink all .dlls into the local directory.
393 # symlink all .dlls into the local directory.
381 # we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set
394 # we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set
382 # to symlink over dlls as needed.
395 # to symlink over dlls as needed.
383 echo "Symlink library dependencies..."
397 echo "Symlink library dependencies..."
384 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
398 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
385 if [ -d "$libdir" ]; then
399 if [ -d "$libdir" ]; then
386 find "$libdir" -iname '*.dll' -exec ln -s {} $out/bin \;
400 find "$libdir" -iname '*.dll' -exec ln -s {} $out/bin \;
390 + (lib.optionalString doCoverage ''
404 + (lib.optionalString doCoverage ''
391 mkdir -p $out/share
405 mkdir -p $out/share
392 cp -r dist/hpc $out/share
406 cp -r dist/hpc $out/share