on iko/ghcjs-patch-master help sign in
Filter components using buildable flag (#240)
6f566a6Hamish Mackenzie
lib/default.nix+7−3
@@ -28,7 +28,8 @@ with haskellLib;
28 tys;
28 tys;
29 in libComp (subComps z);
29 in libComp (subComps z);
30
30
31− getAllComponents = foldComponents subComponentTypes (c: acc: [c] ++ acc) [];
31+ getAllComponents = foldComponents subComponentTypes (c: acc:
32+ lib.optional c.buildable c ++ acc) [];
32
33
33 componentPrefix = {
34 componentPrefix = {
34 # Are all of these right?
35 # Are all of these right?
@@ -45,9 +46,12 @@ with haskellLib;
45 applyLibrary = cname: f { cname = config.package.identifier.name; ctype = "lib"; };
46 applyLibrary = cname: f { cname = config.package.identifier.name; ctype = "lib"; };
46 applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype} or (throw "Missing component mapping for ${ctype}."); };
47 applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype} or (throw "Missing component mapping for ${ctype}."); };
47 applyAllComp = f { cname = config.package.identifier.name; ctype = "all"; };
48 applyAllComp = f { cname = config.package.identifier.name; ctype = "all"; };
49+ buildableAttrs = lib.filterAttrs (n: comp: comp.buildable or true);
50+ libComp = if comps.library == null || !(comps.library.buildable or true)
51+ then {}
48− libComp = if comps.library == null then {} else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
52+ else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
49 subComps = lib.mapAttrs
53 subComps = lib.mapAttrs
50− (ctype: lib.mapAttrs (applySubComp ctype))
54+ (ctype: attrs: lib.mapAttrs (applySubComp ctype) (buildableAttrs attrs))
51 (builtins.intersectAttrs (lib.genAttrs subComponentTypes (_: null)) comps);
55 (builtins.intersectAttrs (lib.genAttrs subComponentTypes (_: null)) comps);
52 allComp = { all = applyAllComp comps.all; };
56 allComp = { all = applyAllComp comps.all; };
53 in subComps // libComp // allComp;
57 in subComps // libComp // allComp;
modules/package.nix+4
@@ -132,6 +132,10 @@ in {
132 componentType = submodule {
132 componentType = submodule {
133 # add the shared componentOptions
133 # add the shared componentOptions
134 options = (packageOptions config) // {
134 options = (packageOptions config) // {
135+ buildable = mkOption {
136+ type = bool;
137+ default = true;
138+ };
135 depends = mkOption {
139 depends = mkOption {
136 type = listOfFilteringNulls unspecified;
140 type = listOfFilteringNulls unspecified;
137 default = [];
141 default = [];
nix-tools/nix-tools-src.json+3−3
@@ -1,7 +1,7 @@
1{
1{
2 "url": "https://github.com/input-output-hk/nix-tools",
2 "url": "https://github.com/input-output-hk/nix-tools",
3− "rev": "a9f227d9238102fb424157156712ef9b64413096",
3+ "rev": "9a08485cb33a60bbf18c2f442020b12ff6373d24",
4− "date": "2019-07-18T12:21:16+12:00",
4+ "date": "2019-09-25T17:39:56+08:00",
5− "sha256": "19r5an3hrjn1a4mm2n0fhaa5b1fi975pyjcisbnrhwfajlqb362f",
5+ "sha256": "04ijh8fgnc4f8zdvysv2qkhp0mq60jdhp3agm2v47xlq8r456vlm",
6 "fetchSubmodules": false
6 "fetchSubmodules": false
7}
7}
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 {
21 callStackToNix = haskell.callPackage ./call-stack-to-nix {};
21 callStackToNix = haskell.callPackage ./call-stack-to-nix {};
22 callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
22 callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
23 cabal-source-repo = haskell.callPackage ./cabal-source-repo {};
23 cabal-source-repo = haskell.callPackage ./cabal-source-repo {};
24+ buildable = haskell.callPackage ./buildable {};
24
25
25 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
26 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
26 # An empty list means success.
27 # An empty list means success.