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
This commit is contained in:
Hamish Mackenzie 2019-09-26 17:47:03 +12:00 committed by Moritz Angermann
parent 3b60632c62
commit 6f566a6d5d
7 changed files with 86 additions and 6 deletions

View File

@ -28,7 +28,8 @@ with haskellLib;
tys;
in libComp (subComps z);
getAllComponents = foldComponents subComponentTypes (c: acc: [c] ++ acc) [];
getAllComponents = foldComponents subComponentTypes (c: acc:
lib.optional c.buildable c ++ acc) [];
componentPrefix = {
# Are all of these right?
@ -45,9 +46,12 @@ with haskellLib;
applyLibrary = cname: f { cname = config.package.identifier.name; ctype = "lib"; };
applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype} or (throw "Missing component mapping for ${ctype}."); };
applyAllComp = f { cname = config.package.identifier.name; ctype = "all"; };
libComp = if comps.library == null then {} else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
buildableAttrs = lib.filterAttrs (n: comp: comp.buildable or true);
libComp = if comps.library == null || !(comps.library.buildable or true)
then {}
else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
subComps = lib.mapAttrs
(ctype: lib.mapAttrs (applySubComp ctype))
(ctype: attrs: lib.mapAttrs (applySubComp ctype) (buildableAttrs attrs))
(builtins.intersectAttrs (lib.genAttrs subComponentTypes (_: null)) comps);
allComp = { all = applyAllComp comps.all; };
in subComps // libComp // allComp;

View File

@ -132,6 +132,10 @@ in {
componentType = submodule {
# add the shared componentOptions
options = (packageOptions config) // {
buildable = mkOption {
type = bool;
default = true;
};
depends = mkOption {
type = listOfFilteringNulls unspecified;
default = [];

View File

@ -1,7 +1,7 @@
{
"url": "https://github.com/input-output-hk/nix-tools",
"rev": "a9f227d9238102fb424157156712ef9b64413096",
"date": "2019-07-18T12:21:16+12:00",
"sha256": "19r5an3hrjn1a4mm2n0fhaa5b1fi975pyjcisbnrhwfajlqb362f",
"rev": "9a08485cb33a60bbf18c2f442020b12ff6373d24",
"date": "2019-09-25T17:39:56+08:00",
"sha256": "04ijh8fgnc4f8zdvysv2qkhp0mq60jdhp3agm2v47xlq8r456vlm",
"fetchSubmodules": false
}

4
test/buildable/Main.hs Normal file
View File

@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello, Haskell!"

View File

@ -0,0 +1,31 @@
cabal-version: >=1.10
name: buildable-test
version: 0.1.0.0
license: PublicDomain
author: Hamish Mackenzie
maintainer: hamish.mackenzie@iohk.io
build-type: Simple
flag exclude-broken
default: False
description: Turning this on should exclude the does-not-build2
executable builds
main-is: Main.hs
build-depends: base
default-language: Haskell2010
executable does-not-build
buildable: False
main-is: Missing.hs
build-depends: base
default-language: Haskell2010
executable does-not-build2
if flag( exclude-broken )
buildable: False
main-is: Missing.hs
build-depends: base
default-language: Haskell2010

View File

@ -0,0 +1,36 @@
{ stdenv, mkCabalProjectPkgSet, callCabalProjectToNix, importAndFilterProject }:
with stdenv.lib;
let
plan = importAndFilterProject (callCabalProjectToNix {
index-state = "2019-04-30T00:00:00Z";
src = ./.;
});
pkgSet = mkCabalProjectPkgSet {
plan-pkgs = plan.pkgs;
modules = [ { packages.buildable-test.flags.exclude-broken = true; } ];
};
packages = pkgSet.config.hsPkgs;
in
stdenv.mkDerivation {
name = "buildable-test";
buildCommand =
(concatStrings (mapAttrsToList (name: value: ''
exe="${value}/bin/${name}"
printf "checking whether executable runs... " >& 2
$exe
'') packages.buildable-test.components.exes)) + ''
touch $out
'';
meta.platforms = platforms.all;
passthru = {
# Attributes used for debugging with nix repl
inherit pkgSet packages;
inherit (plan) nix;
};
}

View File

@ -21,6 +21,7 @@ in pkgs.recurseIntoAttrs {
callStackToNix = haskell.callPackage ./call-stack-to-nix {};
callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
cabal-source-repo = haskell.callPackage ./cabal-source-repo {};
buildable = haskell.callPackage ./buildable {};
# Run unit tests with: nix-instantiate --eval --strict -A unit.tests
# An empty list means success.