on iko/ghcjs-patch-master help sign in
Fix `components.all` for exe only packages (#295)
c258167Hamish Mackenzie
builder/comp-builder.nix+4−1
@@ -242,6 +242,9 @@ stdenv.mkDerivation ({
242 # Note 2: if a package contains multiple libs (lib + sublibs) SETUP register will generate a
242 # Note 2: if a package contains multiple libs (lib + sublibs) SETUP register will generate a
243 # folder isntead of a file for the configuration. Therfore if the result is a folder,
243 # folder isntead of a file for the configuration. Therfore if the result is a folder,
244 # we need to register each and every element of that folder.
244 # we need to register each and every element of that folder.
245+ #
246+ # Note 3: if a package has no libs SETUP will not generate anything. This can
247+ # happen when building the `all` component of a package.
245 installPhase = ''
248 installPhase = ''
246 runHook preInstall
249 runHook preInstall
247 $SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
250 $SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
@@ -252,7 +255,7 @@ stdenv.mkDerivation ({
252 for pkg in ${name}.conf/*; do
255 for pkg in ${name}.conf/*; do
253 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register "$pkg"
256 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register "$pkg"
254 done
257 done
255− else
258+ elif [ -e "${name}.conf" ]; then
256 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
259 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
257 fi
260 fi
258 ''}
261 ''}
test/default.nix+1
@@ -29,6 +29,7 @@ in pkgs.recurseIntoAttrs {
29 fully-static = haskell-nix.callPackage ./fully-static { inherit (pkgs) buildPackages; };
29 fully-static = haskell-nix.callPackage ./fully-static { inherit (pkgs) buildPackages; };
30 ghc-options-cabal = haskell-nix.callPackage ./ghc-options/cabal.nix {};
30 ghc-options-cabal = haskell-nix.callPackage ./ghc-options/cabal.nix {};
31 ghc-options-stack = haskell-nix.callPackage ./ghc-options/stack.nix {};
31 ghc-options-stack = haskell-nix.callPackage ./ghc-options/stack.nix {};
32+ exe-only = haskell-nix.callPackage ./exe-only { inherit util; };
32
33
33 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
34 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
34 # An empty list means success.
35 # An empty list means success.
test/exe-only/Main.hsnew file+4
@@ -0,0 +1,4 @@
1+module Main where
2+
3+main :: IO ()
4+main = putStrLn "Hello, Haskell!"
test/exe-only/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
test/exe-only/default.nixnew file+56
@@ -0,0 +1,56 @@
1+# Test a package set
2+{ stdenv, util, haskell-nix }:
3+
4+with stdenv.lib;
5+
6+let
7+ project = haskell-nix.cabalProject' {
8+ name = "exe-only";
9+ src = ./.;
10+ };
11+
12+ packages = project.hsPkgs;
13+
14+in
15+ stdenv.mkDerivation {
16+ name = "exe-only-test";
17+
18+ buildCommand = ''
19+ exe="${packages.exe-only.components.exes.exe-only}/bin/exe-only"
20+
21+ size=$(command stat --format '%s' "$exe")
22+ printf "size of executable $exe is $size. \n" >& 2
23+
24+ # fixme: run on target platform when cross-compiled
25+ printf "checking whether executable runs... " >& 2
26+ $exe
27+ '' + (if stdenv.hostPlatform.isMusl then ''
28+ printf "checking that executable is statically linked... " >& 2
29+ (ldd $exe 2>&1 || true) | grep -i "not a"
30+ '' else ''
31+ printf "checking that executable is dynamically linked to system libraries... " >& 2
32+ '' + optionalString stdenv.isLinux ''
33+ ldd $exe | grep libpthread
34+ '' + optionalString stdenv.isDarwin ''
35+ otool -L $exe |grep .dylib
36+ '') + ''
37+
38+ printf "Checking that \"all\" component has the programs... " >& 2
39+ all_exe="${packages.exe-only.components.all}/bin/exe-only"
40+ test -f "$all_exe"
41+ echo "$all_exe" >& 2
42+
43+ touch $out
44+ '';
45+
46+ meta.platforms = platforms.all;
47+
48+ passthru = {
49+ # Used for debugging with nix repl
50+ inherit pkgSet packages;
51+
52+ # Used for testing externally with nix-shell (../tests.sh).
53+ # This just adds cabal-install to the existing shells.
54+ test-shell = util.addCabalInstall packages.exe-only.components.all;
55+ };
56+}
test/exe-only/exe-only.cabalnew file+15
@@ -0,0 +1,15 @@
1+cabal-version: >=1.10
2+
3+name: exe-only
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+executable exe-only
11+ main-is: Main.hs
12+ build-depends: base
13+ , extra
14+ , optparse-applicative
15+ default-language: Haskell2010