on iko/ghcjs-patch-master help sign in
Filter components using buildable flag (#240)

* Filter components using buildable flag * Bump nix-tools * Include components without buildable flag * Test buildable components are filtered correctly

commit6f566a6d5dc3c6c901603f87adcc0b1538284f0b authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateThu 26 Sep 2019, 17:47 (7 years ago) parent3b60632
7 files changed+86−6
lib/default.nix+7−3 modules/package.nix+4 nix-tools/nix-tools-src.json+3−3 test/buildable/Main.hs+4 test/buildable/buildable-test.cabal+31 test/buildable/default.nix+36 test/default.nix+1
lib/default.nix+7−3
@@ -28,7 +28,8 @@ with haskellLib;
2828 tys;
2929 in libComp (subComps z);
3030
31− getAllComponents = foldComponents subComponentTypes (c: acc: [c] ++ acc) [];
31+ getAllComponents = foldComponents subComponentTypes (c: acc:
32+ lib.optional c.buildable c ++ acc) [];
3233
3334 componentPrefix = {
3435 # Are all of these right?
@@ -45,9 +46,12 @@ with haskellLib;
4546 applyLibrary = cname: f { cname = config.package.identifier.name; ctype = "lib"; };
4647 applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype} or (throw "Missing component mapping for ${ctype}."); };
4748 applyAllComp = f { cname = config.package.identifier.name; ctype = "all"; };
48− libComp = if comps.library == null then {} else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
49+ buildableAttrs = lib.filterAttrs (n: comp: comp.buildable or true);
50+ libComp = if comps.library == null || !(comps.library.buildable or true)
51+ then {}
52+ else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
4953 subComps = lib.mapAttrs
50− (ctype: lib.mapAttrs (applySubComp ctype))
54+ (ctype: attrs: lib.mapAttrs (applySubComp ctype) (buildableAttrs attrs))
5155 (builtins.intersectAttrs (lib.genAttrs subComponentTypes (_: null)) comps);
5256 allComp = { all = applyAllComp comps.all; };
5357 in subComps // libComp // allComp;
modules/package.nix+4
@@ -132,6 +132,10 @@ in {
132132 componentType = submodule {
133133 # add the shared componentOptions
134134 options = (packageOptions config) // {
135+ buildable = mkOption {
136+ type = bool;
137+ default = true;
138+ };
135139 depends = mkOption {
136140 type = listOfFilteringNulls unspecified;
137141 default = [];
nix-tools/nix-tools-src.json+3−3
@@ -1,7 +1,7 @@
11{
22 "url": "https://github.com/input-output-hk/nix-tools",
3− "rev": "a9f227d9238102fb424157156712ef9b64413096",
4− "date": "2019-07-18T12:21:16+12:00",
5− "sha256": "19r5an3hrjn1a4mm2n0fhaa5b1fi975pyjcisbnrhwfajlqb362f",
3+ "rev": "9a08485cb33a60bbf18c2f442020b12ff6373d24",
4+ "date": "2019-09-25T17:39:56+08:00",
5+ "sha256": "04ijh8fgnc4f8zdvysv2qkhp0mq60jdhp3agm2v47xlq8r456vlm",
66 "fetchSubmodules": false
77}
test/buildable/Main.hsnew file+4
@@ -0,0 +1,4 @@
1+module Main where
2+
3+main :: IO ()
4+main = putStrLn "Hello, Haskell!"
test/buildable/buildable-test.cabalnew file+31
@@ -0,0 +1,31 @@
1+cabal-version: >=1.10
2+
3+name: buildable-test
4+version: 0.1.0.0
5+license: PublicDomain
6+author: Hamish Mackenzie
7+maintainer: hamish.mackenzie@iohk.io
8+build-type: Simple
9+
10+flag exclude-broken
11+ default: False
12+ description: Turning this on should exclude the does-not-build2
13+
14+executable builds
15+ main-is: Main.hs
16+ build-depends: base
17+ default-language: Haskell2010
18+
19+executable does-not-build
20+ buildable: False
21+ main-is: Missing.hs
22+ build-depends: base
23+ default-language: Haskell2010
24+
25+executable does-not-build2
26+ if flag( exclude-broken )
27+ buildable: False
28+ main-is: Missing.hs
29+ build-depends: base
30+ default-language: Haskell2010
31+
test/buildable/default.nixnew file+36
@@ -0,0 +1,36 @@
1+{ stdenv, mkCabalProjectPkgSet, callCabalProjectToNix, importAndFilterProject }:
2+
3+with stdenv.lib;
4+
5+let
6+ plan = importAndFilterProject (callCabalProjectToNix {
7+ index-state = "2019-04-30T00:00:00Z";
8+ src = ./.;
9+ });
10+ pkgSet = mkCabalProjectPkgSet {
11+ plan-pkgs = plan.pkgs;
12+ modules = [ { packages.buildable-test.flags.exclude-broken = true; } ];
13+ };
14+ packages = pkgSet.config.hsPkgs;
15+in
16+ stdenv.mkDerivation {
17+ name = "buildable-test";
18+
19+ buildCommand =
20+ (concatStrings (mapAttrsToList (name: value: ''
21+ exe="${value}/bin/${name}"
22+
23+ printf "checking whether executable runs... " >& 2
24+ $exe
25+ '') packages.buildable-test.components.exes)) + ''
26+ touch $out
27+ '';
28+
29+ meta.platforms = platforms.all;
30+
31+ passthru = {
32+ # Attributes used for debugging with nix repl
33+ inherit pkgSet packages;
34+ inherit (plan) nix;
35+ };
36+ }
test/default.nix+1
@@ -21,6 +21,7 @@ in pkgs.recurseIntoAttrs {
2121 callStackToNix = haskell.callPackage ./call-stack-to-nix {};
2222 callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
2323 cabal-source-repo = haskell.callPackage ./cabal-source-repo {};
24+ buildable = haskell.callPackage ./buildable {};
2425
2526 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
2627 # An empty list means success.