Skip to content

Commit cc58520

Browse files
committed
More fixes for cabal-doctest
1 parent da71b82 commit cc58520

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

builder/comp-builder.nix

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8585
let
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
@@ -92,7 +97,7 @@ let
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.
@@ -114,10 +119,7 @@ let
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}
@@ -369,7 +373,11 @@ let
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
@@ -456,9 +464,24 @@ let
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

test/cabal-doctests/cabal-doctests-test.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ custom-setup
1111
cabal-doctest >= 1 && <1.1
1212

1313
library
14+
hs-source-dirs: src
1415
exposed-modules: Lib
1516
other-modules: Paths_cabal_doctests_test
1617
build-depends:
@@ -19,12 +20,12 @@ library
1920
default-language: Haskell2010
2021

2122
test-suite doctests
23+
hs-source-dirs: doctests
2224
x-doctest-options: --no-magic
2325
type: exitcode-stdio-1.0
2426
main-is: Doctests.hs
2527
ghc-options: -threaded -rtsopts -with-rtsopts=-N
2628
build-depends:
2729
base >=4.7 && <5
2830
, doctest
29-
, cabal-doctests-test
3031
default-language: Haskell2010

test/cabal-doctests/default.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ in recurseIntoAttrs ({
2828

2929
buildCommand = ''
3030
printf "Checking that doctest tests have run ... " >& 2
31-
doctest_output="${packages.cabal-doctests-test.checks.doctests}"
32-
test -f "$doctest_output"
33-
cat "$doctest_output" >& 2
31+
cat ${packages.cabal-doctests-test.checks.doctests}/test-stdout >& 2
3432
3533
touch $out
3634
'';
File renamed without changes.

0 commit comments

Comments
 (0)