on iko/ghcjs-patch-master help sign in
Fix project flags (#253)
f648a65Hamish Mackenzie
@@ -107,7 +107,7 @@ let
107 pkg-def-extras = [ stack-pkgs.extras ] ++ pkg-def-extras;
107 pkg-def-extras = [ stack-pkgs.extras ] ++ pkg-def-extras;
108 # set doExactConfig = true. The stackage set should be consistent
108 # set doExactConfig = true. The stackage set should be consistent
109 # and we should trust stackage here!
109 # and we should trust stackage here!
110− modules = [ { doExactConfig = true; } patchesModule ] ++ modules;
110+ modules = [ { doExactConfig = true; } patchesModule ] ++ stack-pkgs.modules or [] ++ modules;
111 };
111 };
112
112
113 # Create a Haskell package set based on a Cabal configuration.
113 # Create a Haskell package set based on a Cabal configuration.
@@ -127,7 +127,7 @@ let
127 pkg-def-extras = [ plan-pkgs.extras ] ++ pkg-def-extras;
127 pkg-def-extras = [ plan-pkgs.extras ] ++ pkg-def-extras;
128 # set doExactConfig = true, as we trust cabals resolution for
128 # set doExactConfig = true, as we trust cabals resolution for
129 # the plan.
129 # the plan.
130− modules = [ { doExactConfig = true; } patchesModule ] ++ modules;
130+ modules = [ { doExactConfig = true; } patchesModule ] ++ plan-pkgs.modules or [] ++ modules;
131 };
131 };
132
132
133 # Package sets for all stackage snapshots.
133 # Package sets for all stackage snapshots.
docs/user-guide/projects.md+13−1
@@ -29,6 +29,8 @@ let
29 # example:
29 # example:
30 # packages.cbors.patches = [ ./one.patch ];
30 # packages.cbors.patches = [ ./one.patch ];
31 # packages.cbors.flags.optimize-gmp = false;
31 # packages.cbors.flags.optimize-gmp = false;
32+ # It may be better to set flags in stack.yaml instead (overrides will
33+ # be included for them automatically by `stack-to-nix`).
32 ];
34 ];
33 };
35 };
34
36
@@ -36,7 +38,17 @@ let
36 pkgSet = haskell.mkCabalProjectPkgSet {
38 pkgSet = haskell.mkCabalProjectPkgSet {
37 plan-pkgs = my-pkgs;
39 plan-pkgs = my-pkgs;
38 pkg-def-extras = [];
40 pkg-def-extras = [];
39− modules = [];
41+ modules = [
42+ # specific package overrides would go here
43+ # example:
44+ # packages.cbors.patches = [ ./one.patch ];
45+ # To override a flag you will need to use mkOverride to make
46+ # it clear that you wish to replace the value found in the
47+ # `plan.json` file (all the flags values are included there
48+ # by `cabal`).
49+ # packages.cbors.flags.optimize-gmp = stdenv.lib.mkOverride 10 false;
50+ # It may be better to set flags in `cabal.project` instead.
51+ ];
40 };
52 };
41
53
42in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
54in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
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": "47ab47199194990681d24afd725e3f0e942e4f3d",
3+ "rev": "5d4649a833cb8b963266cea016d5a12a30022266",
4− "date": "2019-09-30T23:06:49+13:00",
4+ "date": "2019-10-11T14:24:33+13:00",
5− "sha256": "1wbfs4k2sadzz0swrpbmdhsph0icfqni8f3dzxcny0vzpx7fiwfq",
5+ "sha256": "1xf3llli08axrhhda80hx95nmbwmdcz0y4r2vmgfhi3lqbcww8vk",
6 "fetchSubmodules": false
6 "fetchSubmodules": false
7}
7}
test/buildable/default.nix+6−1
@@ -9,7 +9,12 @@ let
9 });
9 });
10 pkgSet = mkCabalProjectPkgSet {
10 pkgSet = mkCabalProjectPkgSet {
11 plan-pkgs = plan.pkgs;
11 plan-pkgs = plan.pkgs;
12+ # We need mkOverride to override the value from `plan.json`.
13+ # Normally we could set the flag in `cabal.project`,
14+ # but for this test that does not work because then cabal would
15+ # see the exe is not buildable and exclude it before haskell.nix
16+ # can.
12− modules = [ { packages.buildable-test.flags.exclude-broken = true; } ];
17+ modules = [ { packages.buildable-test.flags.exclude-broken = mkOverride 10 true; } ];
13 };
18 };
14 packages = pkgSet.config.hsPkgs;
19 packages = pkgSet.config.hsPkgs;
15in
20in
test/default.nix+2
@@ -22,6 +22,8 @@ in pkgs.recurseIntoAttrs {
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 buildable = haskell.callPackage ./buildable {};
25+ project-flags-cabal = haskell.callPackage ./project-flags/cabal.nix {};
26+ project-flags-stack = haskell.callPackage ./project-flags/stack.nix {};
25
27
26 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
28 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
27 # An empty list means success.
29 # An empty list means success.
test/project-flags/.gitignorenew file+2
@@ -0,0 +1,2 @@
1+.stack-work/
2+*~
test/project-flags/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
test/project-flags/app/Main.hsnew file+9
@@ -0,0 +1,9 @@
1+{-# LANGUAGE CPP #-}
2+module Main where
3+
4+import Lib
5+
6+#ifdef TEST_FLAG
7+main :: IO ()
8+main = someFunc
9+#endif
test/project-flags/cabal.nixnew file+34
@@ -0,0 +1,34 @@
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+ };
13+ packages = pkgSet.config.hsPkgs;
14+in
15+ stdenv.mkDerivation {
16+ name = "call-cabal-project-to-nix-test";
17+
18+ buildCommand = ''
19+ exe="${packages.test-project-flags.components.exes.test-project-flags-exe}/bin/test-project-flags-exe"
20+
21+ printf "checking whether executable runs... " >& 2
22+ $exe
23+
24+ touch $out
25+ '';
26+
27+ meta.platforms = platforms.all;
28+
29+ passthru = {
30+ # Attributes used for debugging with nix repl
31+ inherit pkgSet packages;
32+ plan-nix = plan.nix;
33+ };
34+ }
test/project-flags/cabal.projectnew file+4
@@ -0,0 +1,4 @@
1+packages: .
2+
3+package test-project-flags
4+ flags: +test-flag
test/project-flags/src/Lib.hsnew file+9
@@ -0,0 +1,9 @@
1+{-# LANGUAGE CPP #-}
2+module Lib
3+ ( someFunc
4+ ) where
5+
6+#ifdef TEST_FLAG
7+someFunc :: IO ()
8+someFunc = putStrLn "someFunc"
9+#endif
test/project-flags/stack.nixnew file+33
@@ -0,0 +1,33 @@
1+{ stdenv, mkStackPkgSet, callStackToNix, importAndFilterProject }:
2+
3+with stdenv.lib;
4+
5+let
6+ stack = (importAndFilterProject (callStackToNix {
7+ src = ./.;
8+ }));
9+ pkgSet = mkStackPkgSet {
10+ stack-pkgs = stack.pkgs;
11+ };
12+ packages = pkgSet.config.hsPkgs;
13+in
14+ stdenv.mkDerivation {
15+ name = "callStackToNix-test";
16+
17+ buildCommand = ''
18+ exe="${packages.test-project-flags.components.exes.test-project-flags-exe}/bin/test-project-flags-exe"
19+
20+ printf "checking whether executable runs... " >& 2
21+ $exe
22+
23+ touch $out
24+ '';
25+
26+ meta.platforms = platforms.all;
27+
28+ passthru = {
29+ # Attributes used for debugging with nix repl
30+ inherit pkgSet packages;
31+ stack-nix = stack.nix;
32+ };
33+ }
test/project-flags/stack.yamlnew file+8
@@ -0,0 +1,8 @@
1+resolver: lts-13.19
2+
3+packages:
4+- .
5+
6+flags:
7+ test-project-flags:
8+ test-flag: true
test/project-flags/test-project-flags.cabalnew file+28
@@ -0,0 +1,28 @@
1+cabal-version: >=1.10
2+name: test-project-flags
3+version: 0.1.0.0
4+license: PublicDomain
5+author: Hamish Mackenzie
6+maintainer: Hamish.Mackenzie@iohk.io
7+build-type: Simple
8+
9+flag test-flag
10+ description: A flag that needs to be turned on
11+ default: False
12+
13+library
14+ build-depends: base >=4.7 && <5
15+ exposed-modules: Lib
16+ hs-source-dirs: src
17+ default-language: Haskell2010
18+ if flag(test-flag)
19+ cpp-options: -DTEST_FLAG
20+
21+executable test-project-flags-exe
22+ main-is: Main.hs
23+ build-depends: base >=4.7 && <5, test-project-flags
24+ hs-source-dirs: app
25+ ghc-options: -threaded -rtsopts -with-rtsopts=-N
26+ default-language: Haskell2010
27+ if flag(test-flag)
28+ cpp-options: -DTEST_FLAG