@@ -53,7 +53,7 @@ let self =
5353, doHoogle ? component . doHoogle # Also build a hoogle index
5454, hyperlinkSource ? component . doHyperlinkSource # Link documentation to the source code
5555, quickjump ? component . doQuickjump # Generate an index for interactive documentation navigation
56- , keepSource ? component . keepSource # Build from `source` output in the store then delete `dist`
56+ , keepSource ? component . keepSource || configureAllComponents # Build from `source` output in the store then delete `dist`
5757, setupHaddockFlags ? component . setupHaddockFlags
5858
5959# Profiling
@@ -83,6 +83,11 @@ let self =
8383} @drvArgs :
8484
8585let
86+ componentForSetup =
87+ if configureAllComponents
88+ then allComponent
89+ else component ;
90+
8691 # TODO fix cabal wildcard support so hpack wildcards can be mapped to cabal wildcards
8792 canCleanSource = ! ( cabal-generator == "hpack" && ! ( package . cleanHpack or false ) ) ;
8893 # In order to support relative references to other packages we need to use
9297 # is the sub directory in that root path that contains the package.
9398 # `cleanSrc.subDir` is used in `prePatch` and `lib/cover.nix`.
9499 cleanSrc = haskellLib . rootAndSubDir ( if canCleanSource
95- then haskellLib . cleanCabalComponent package component "${ componentId . ctype } -${ componentId . cname } " src
100+ then haskellLib . cleanCabalComponent package componentForSetup "${ componentId . ctype } -${ componentId . cname } " src
96101 else
97102 # We can clean out the siblings though to at least avoid changes to other packages
98103 # from triggering a rebuild of this one.
114119 needsProfiling = enableExecutableProfiling || enableLibraryProfiling ;
115120
116121 configFiles = makeConfigFiles {
117- component =
118- if configureAllComponents
119- then allComponent
120- else component ;
122+ component = componentForSetup ;
121123 inherit ( package ) identifier ;
122124 inherit fullName flags needsProfiling ;
123125 } ;
@@ -333,15 +335,17 @@ let
333335 ++ ( lib . optional enableSeparateDataOutput "data" )
334336 ++ ( lib . optional keepSource "source" ) ;
335337
336- configurePhase =
338+ prePatch =
337339 ( lib . optionalString ( ! canCleanSource ) ''
338340 echo "Cleaning component source not supported, leaving it un-cleaned"
339341 '' ) +
340342 ( lib . optionalString keepSource ''
341343 cp -r . $source
342344 cd $source
343345 chmod -R +w .
344- '' ) + ''
346+ '' ) + commonAttrs . prePatch ;
347+
348+ configurePhase = ''
345349 runHook preConfigure
346350 echo Configure flags:
347351 printf "%q " ${ finalConfigureFlags }
369373 target-pkg-and-db = "${ ghc . targetPrefix } ghc-pkg -v0 --package-db $out/package.conf.d" ;
370374 in ''
371375 runHook preInstall
372- $SETUP_HS copy ${ lib . concatStringsSep " " setupInstallFlags }
376+ $SETUP_HS copy ${ lib . concatStringsSep " " (
377+ setupInstallFlags
378+ ++ lib . optional configureAllComponents
379+ ( haskellLib . componentTarget componentId )
380+ ) }
373381 ${ lib . optionalString ( haskellLib . isLibrary componentId ) ''
374382 $SETUP_HS register --gen-pkg-config=${ name } .conf
375383 ${ ghc . targetPrefix } ghc-pkg -v0 init $out/package.conf.d
456464 '' )
457465 }
458466 runHook postInstall
459- '' + ( lib . optionalString keepSource ''
460- rm -rf dist
461- '' ) + ( lib . optionalString ( haskellLib . isTest componentId ) ''
467+ '' + (
468+ # Keep just the autogen files and package.conf.inplace package
469+ # DB (probably empty unless this is a library component).
470+ # We also have to remove any refernces to $out to avoid
471+ # circular references.
472+ if configureAllComponents
473+ then ''
474+ mv dist dist-tmp-dir
475+ mkdir -p dist/build
476+ mv dist-tmp-dir/build/${ componentId . cname } /autogen dist/build/
477+ mv dist-tmp-dir/package.conf.inplace dist/
478+ remove-references-to -t $out dist/build/autogen/*
479+ rm -rf dist-tmp-dir
480+ ''
481+ else lib . optionalString keepSource ''
482+ rm -rf dist
483+ ''
484+ ) + ( lib . optionalString ( haskellLib . isTest componentId ) ''
462485 echo The test ${ package . identifier . name } .components.tests.${ componentId . cname } was built. To run the test build ${ package . identifier . name } .checks.${ componentId . cname } .
463486 '' ) ;
464487
0 commit comments