Skip to content

Commit 5341ac4

Browse files
authored
Avoid using srcOnly (input-output-hk#1563)
New versions of `srcOnly` pass the `prePatch` hook in and we `cd` into the sub directory for the package in that hook. This means that the output includes only the package subdirectory. We worked around this, but the work around breaks for older nixpkgs where `prePatch` is not passed. This change replaces the use of `srcOnly` and instead uses the same trick as source so that the `buildPhase` is replaced and runs in the expected source directory (including and it should still include any sibling directories that have not been filtered).
1 parent 3025de7 commit 5341ac4

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

lib/check.nix

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
{ stdenv, lib, haskellLib, srcOnly }:
1+
{ stdenv, lib, haskellLib }:
22
drv:
33

44
let
55
component = drv.config;
66

7-
subdir =
8-
if drv?source
9-
then
10-
drv.srcSubDir or ""
11-
else
12-
# srcOnly returns just the subdir, so we're already in it.
13-
"";
14-
157
# This derivation can be used to execute test component.
168
# The $out of the derivation is a file containing the resulting
179
# stdout output.
18-
in stdenv.mkDerivation ({
10+
in stdenv.mkDerivation ((
11+
if drv ? source
12+
then {
13+
src = drv.source;
14+
patchPhase =
15+
# This `cd` is normally done in the `prePatch` of the drv
16+
lib.optionalString (drv.srcSubDir != "") ''
17+
cd ${lib.removePrefix "/" drv.srcSubDir}
18+
'';
19+
}
20+
else
21+
# This makes the derivation work a bit like `srcOnly`,
22+
# using the original derivation, but replacing the `buildPhase`.
23+
(drv.drvAttrs or drv) // {
24+
outputs = [ "out" ];
25+
separateDebugInfo = false;
26+
}) // {
1927
name = (drv.name + "-check");
2028

21-
# Using `srcOnly` (rather than getting the `src` via a `drv.passthru`)
22-
# should correctly apply the patches from `drv` (if any).
23-
src = drv.source or (srcOnly drv);
24-
2529
passthru = {
2630
inherit (drv) identifier config configFiles executableToolDepends cleanSrc env exeName;
2731
};
@@ -30,19 +34,12 @@ in stdenv.mkDerivation ({
3034

3135
inherit (component) doCheck doCrossCheck;
3236

33-
phases = ["unpackPhase" "buildPhase"];
37+
phases = ["unpackPhase" "patchPhase" "buildPhase"];
3438

3539
# If doCheck or doCrossCheck are false we may still build this
3640
# component and we want it to quietly succeed.
3741
buildPhase = ''
3842
mkdir $out
39-
${
40-
# Change to the source sub directory if there is one.
41-
lib.optionalString (subdir != "") ''
42-
cd ${lib.removePrefix "/" subdir}
43-
''
44-
}
45-
4643
runHook preCheck
4744
4845
${toString component.testWrapper} ${drv}/bin/${drv.exeName} ${lib.concatStringsSep " " component.testFlags} | tee $out/test-stdout

lib/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ in {
229229

230230
# Check a test component
231231
check = import ./check.nix {
232-
inherit stdenv lib haskellLib srcOnly;
232+
inherit stdenv lib haskellLib;
233233
};
234234

235235
# Do coverage of a package

0 commit comments

Comments
 (0)