@@ -23,6 +23,14 @@ let self =
23, preInstall ? component.preInstall , postInstall ? component.postInstall
23, preInstall ? component.preInstall , postInstall ? component.postInstall
24, preHaddock ? component.preHaddock , postHaddock ? component.postHaddock
24, preHaddock ? component.preHaddock , postHaddock ? component.postHaddock
25, shellHook ? ""
25, shellHook ? ""
26+, configureAllComponents ? component.configureAllComponents ||
27+ # When set, configure all the components in the package
28+ # (not just the one we are building).
29+ # Enable for tests in packages that use cabal-doctest.
30+ ( haskellLib.isTest componentId &&
31+ lib.any (x: x.identifier.name or "" == "cabal-doctest") package.setup-depends
33+, allComponent # Used when `configureAllComponents` is set to get a suitable configuration.
27, build-tools ? component.build-tools
35, build-tools ? component.build-tools
28, pkgconfig ? component.pkgconfig
36, pkgconfig ? component.pkgconfig
@@ -47,7 +55,7 @@ let self =
47, doHoogle ? component.doHoogle # Also build a hoogle index
55, doHoogle ? component.doHoogle # Also build a hoogle index
48, hyperlinkSource ? component.doHyperlinkSource # Link documentation to the source code
56, hyperlinkSource ? component.doHyperlinkSource # Link documentation to the source code
49, quickjump ? component.doQuickjump # Generate an index for interactive documentation navigation
57, quickjump ? component.doQuickjump # Generate an index for interactive documentation navigation
50−, keepSource ? component.keepSource # Build from `source` output in the store then delete `dist`
58+, keepSource ? component.keepSource || configureAllComponents # Build from `source` output in the store then delete `dist`
51, setupHaddockFlags ? component.setupHaddockFlags
59, setupHaddockFlags ? component.setupHaddockFlags
53# Profiling
61# Profiling
@@ -77,6 +85,11 @@ let self =
89+ if configureAllComponents
80 # Ignore attempts to include DWARF info when it is not possible
93 # Ignore attempts to include DWARF info when it is not possible
81 enableDWARF = drvArgs.enableDWARF or false
94 enableDWARF = drvArgs.enableDWARF or false
82 && stdenv.hostPlatform.isLinux
95 && stdenv.hostPlatform.isLinux
@@ -96,7 +109,7 @@ let
96 # is the sub directory in that root path that contains the package.
109 # is the sub directory in that root path that contains the package.
97 # `cleanSrc.subDir` is used in `prePatch` and `lib/cover.nix`.
110 # `cleanSrc.subDir` is used in `prePatch` and `lib/cover.nix`.
98 cleanSrc = haskellLib.rootAndSubDir (if canCleanSource
111 cleanSrc = haskellLib.rootAndSubDir (if canCleanSource
99− then haskellLib.cleanCabalComponent package component "${componentId.ctype}-${componentId.cname}" src
112+ then haskellLib.cleanCabalComponent package componentForSetup "${componentId.ctype}-${componentId.cname}" src
101 # We can clean out the siblings though to at least avoid changes to other packages
114 # We can clean out the siblings though to at least avoid changes to other packages
102 # from triggering a rebuild of this one.
115 # from triggering a rebuild of this one.
@@ -118,8 +131,9 @@ let
118 needsProfiling = enableExecutableProfiling || enableLibraryProfiling;
131 needsProfiling = enableExecutableProfiling || enableLibraryProfiling;
120 configFiles = makeConfigFiles {
133 configFiles = makeConfigFiles {
134+ component = componentForSetup;
121 inherit (package) identifier;
135 inherit (package) identifier;
122− inherit component fullName flags needsProfiling enableDWARF;
136+ inherit fullName flags needsProfiling enableDWARF;
125 enableFeature = enable: feature:
139 enableFeature = enable: feature:
@@ -129,8 +143,13 @@ let
130 finalConfigureFlags = lib.concatStringsSep " " (
144 finalConfigureFlags = lib.concatStringsSep " " (
131 [ "--prefix=$out"
145 [ "--prefix=$out"
147+ # If configureAllComponents is set we should not specify the component
148+ # and Setup will attempt to configure them all.
149+ if configureAllComponents
150+ then ["--enable-tests" "--enable-benchmarks"]
132− "${haskellLib.componentTarget componentId}"
151+ else ["${haskellLib.componentTarget componentId}"]
133− "$(cat ${configFiles}/configure-flags)"
152+ ) ++ [ "$(cat ${configFiles}/configure-flags)"
134 ] ++ commonConfigureFlags);
153 ] ++ commonConfigureFlags);
136 # From nixpkgs 20.09, the pkg-config exe has a prefix matching the ghc one
155 # From nixpkgs 20.09, the pkg-config exe has a prefix matching the ghc one
@@ -328,7 +347,7 @@ let
328 ++ (lib.optional enableSeparateDataOutput "data")
347 ++ (lib.optional enableSeparateDataOutput "data")
329 ++ (lib.optional keepSource "source");
348 ++ (lib.optional keepSource "source");
331− configurePhase =
350+ prePatch =
332 # emcc is very slow if it cannot cache stuff in $HOME
351 # emcc is very slow if it cannot cache stuff in $HOME
333 (lib.optionalString (stdenv.hostPlatform.isGhcjs) ''
352 (lib.optionalString (stdenv.hostPlatform.isGhcjs) ''
334 export HOME=$(mktemp -d)
353 export HOME=$(mktemp -d)
@@ -340,7 +359,9 @@ let
340 cp -r . $source
359 cp -r . $source
341 cd $source
360 cd $source
342 chmod -R +w .
361 chmod -R +w .
343− '') + ''
362+ '') + commonAttrs.prePatch;
344 runHook preConfigure
365 runHook preConfigure
345 echo Configure flags:
366 echo Configure flags:
346 printf "%q " ${finalConfigureFlags}
367 printf "%q " ${finalConfigureFlags}
@@ -368,7 +389,11 @@ let
368 target-pkg-and-db = "${ghc.targetPrefix}ghc-pkg -v0 --package-db $out/package.conf.d";
389 target-pkg-and-db = "${ghc.targetPrefix}ghc-pkg -v0 --package-db $out/package.conf.d";
370 runHook preInstall
391 runHook preInstall
371− $SETUP_HS copy ${lib.concatStringsSep " " setupInstallFlags}
392+ $SETUP_HS copy ${lib.concatStringsSep " " (
394+ ++ lib.optional configureAllComponents
395+ (haskellLib.componentTarget componentId)
372 ${lib.optionalString (haskellLib.isLibrary componentId) ''
397 ${lib.optionalString (haskellLib.isLibrary componentId) ''
373 $SETUP_HS register --gen-pkg-config=${name}.conf
398 $SETUP_HS register --gen-pkg-config=${name}.conf
374 ${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
399 ${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
@@ -455,9 +480,24 @@ let
457 runHook postInstall
482 runHook postInstall
484+ # Keep just the autogen files and package.conf.inplace package
485+ # DB (probably empty unless this is a library component).
486+ # We also have to remove any refernces to $out to avoid
487+ # circular references.
488+ if configureAllComponents
490+ mv dist dist-tmp-dir
492+ mv dist-tmp-dir/build/${componentId.cname}/autogen dist/build/
493+ mv dist-tmp-dir/package.conf.inplace dist/
494+ remove-references-to -t $out dist/build/autogen/*
458− '' + (lib.optionalString keepSource ''
497+ else lib.optionalString keepSource ''
459− rm -rf dist
498+ rm -rf dist
460− '') + (lib.optionalString (haskellLib.isTest componentId) ''
500+ ) + (lib.optionalString (haskellLib.isTest componentId) ''
461 echo The test ${package.identifier.name}.components.tests.${componentId.cname} was built. To run the test build ${package.identifier.name}.checks.${componentId.cname}.
501 echo The test ${package.identifier.name}.components.tests.${componentId.cname} was built. To run the test build ${package.identifier.name}.checks.${componentId.cname}.