on iko/ghcjs-patch-master help sign in
Keep source for component builds (#345)

This fixes and issue with TH functions like `makeRelativeToProject` that can be used to keep a reference to source files. If they are in a temporary location that can result in surprising `file not found` errors at run time. It may also be useful for making debug symbols and the like refer to real files. There is a risk that keeping the source for all packages could expand closure sizes (if for instance debug info is wanted, but you do not want to keep the source in the store). For that reason we have made this an option that must be enabled.

commit41b72e182ac4569c9490ceb65930860fa6b231f6 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateFri 13 Dec 2019, 16:43 (7 years ago) parent300fff4
4 files changed+34−16
builder/comp-builder.nix+12−3 lib/check.nix+3−5 modules/package.nix+14−8 modules/plan.nix+5
builder/comp-builder.nix+12−3
@@ -31,6 +31,7 @@
3131, doHaddock ? component.doHaddock # Enable haddock and hoogle generation
3232, doHoogle ? component.doHoogle # Also build a hoogle index
3333, hyperlinkSource ? component.doHyperlinkSource # Link documentation to the source code
34+, keepSource ? component.keepSource # Build from `source` output in the store then delete `dist`
3435
3536# Profiling
3637, enableLibraryProfiling ? component.enableLibraryProfiling
@@ -189,7 +190,8 @@ stdenv.mkDerivation ({
189190
190191 outputs = ["out" ]
191192 ++ (lib.optional enableSeparateDataOutput "data")
192− ++ (lib.optional doHaddock' "doc");
193+ ++ (lib.optional doHaddock' "doc")
194+ ++ (lib.optional keepSource "source");
193195
194196 # Phases
195197 preInstallPhases = lib.optional doHaddock' "haddockPhase";
@@ -200,7 +202,12 @@ stdenv.mkDerivation ({
200202 ${buildPackages.haskell-nix.haskellPackages.hpack.components.exes.hpack}/bin/hpack
201203 '';
202204
203− configurePhase = ''
205+ configurePhase =
206+ (lib.optionalString keepSource ''
207+ cp -r . $source
208+ cd $source
209+ chmod -R +w .
210+ '') + ''
204211 runHook preConfigure
205212 echo Configure flags:
206213 printf "%q " ${finalConfigureFlags}
@@ -322,7 +329,9 @@ stdenv.mkDerivation ({
322329 '')
323330 }
324331 runHook postInstall
325− '';
332+ '' + (lib.optionalString keepSource ''
333+ rm -rf dist
334+ '');
326335
327336 shellHook = ''
328337 export PATH="${shellWrappers}/bin:$PATH"
lib/check.nix+3−5
@@ -12,25 +12,23 @@ in stdenv.mkDerivation ({
1212
1313 # Useing `srcOnly` (rather than getting the `src` via a `drv.passthru`)
1414 # should correctly apply the patches from `drv` (if any).
15− src = srcOnly drv;
15+ src = drv.source or (srcOnly drv);
1616
1717 passthru = {
1818 inherit (drv) identifier config configFiles executableToolDepends cleanSrc env;
1919 };
2020
21− inherit (drv) meta LANG LC_ALL;
21+ inherit (drv) meta LANG LC_ALL buildInputs nativeBuildInputs;
2222
2323 inherit (component) doCheck doCrossCheck;
2424
25− phases = ["buildPhase" "checkPhase"];
25+ phases = ["unpackPhase" "buildPhase"];
2626
2727 # If doCheck or doCrossCheck are false we may still build this
2828 # component and we want it to quietly succeed.
2929 buildPhase = ''
3030 touch $out
31− '';
3231
33− checkPhase = ''
3432 runHook preCheck
3533
3634 ${toString component.testWrapper} ${drv}/${drv.installedExe} ${lib.concatStringsSep " " component.testFlags} | tee $out
modules/package.nix+14−8
@@ -316,12 +316,18 @@ in {
316316 # this is relevant would be to switch from the bool type to
317317 # something like an anyBool type, which would merge definitions by
318318 # returning true if any is true.
319− config.components.all = lib.mkMerge (
320− builtins.map (c:
321− # Exclude attributes that are likely to have conflicting definitions
322− # (a common use case for `all` is in `shellFor` and it only has an
323− # install phase).
324− builtins.removeAttrs c ["preCheck" "postCheck"]
325− ) (haskellLib.getAllComponents config)
326− );
319+ config.components.all =
320+ let allComps = haskellLib.getAllComponents config;
321+ in lib.mkMerge (
322+ builtins.map (c:
323+ # Exclude attributes that are likely to have conflicting definitions
324+ # (a common use case for `all` is in `shellFor` and it only has an
325+ # install phase).
326+ builtins.removeAttrs c ["preCheck" "postCheck" "keepSource"]
327+ ) allComps
328+ ) // {
329+ # If any one of the components needs us to keep the source
330+ # then keep it for the `all` component
331+ keepSource = lib.foldl' (x: comp: x || comp.keepSource) false allComps;
332+ };
327333}
modules/plan.nix+5
@@ -153,6 +153,11 @@ let
153153 default = (def.profilingDetail or "exported-functions");
154154 };
155155
156+ keepSource = mkOption {
157+ type = bool;
158+ default = (def.keepSource or false);
159+ description = "Keep component source in the store in a `source` output";
160+ };
156161 };
157162 packageOptions = def: componentOptions def // {
158163 preUnpack = mkOption {