on iko/ghcjs-patch-master help sign in
Fix `components.all` for exe only packages (#295)

Currently the builder tries and fails to register a non existent library component.

commitc258167a5003b0b6a1482f703491b781c76fb6fc authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateTue 5 Nov 2019, 19:49 (7 years ago) parent63fc8be
6 files changed+82−1
builder/comp-builder.nix+4−1 test/default.nix+1 test/exe-only/Main.hs+4 test/exe-only/Setup.hs+2 test/exe-only/default.nix+56 test/exe-only/exe-only.cabal+15
builder/comp-builder.nix+4−1
@@ -242,6 +242,9 @@ stdenv.mkDerivation ({
242242 # Note 2: if a package contains multiple libs (lib + sublibs) SETUP register will generate a
243243 # folder isntead of a file for the configuration. Therfore if the result is a folder,
244244 # 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.
245248 installPhase = ''
246249 runHook preInstall
247250 $SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
@@ -252,7 +255,7 @@ stdenv.mkDerivation ({
252255 for pkg in ${name}.conf/*; do
253256 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register "$pkg"
254257 done
255− else
258+ elif [ -e "${name}.conf" ]; then
256259 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
257260 fi
258261 ''}
test/default.nix+1
@@ -29,6 +29,7 @@ in pkgs.recurseIntoAttrs {
2929 fully-static = haskell-nix.callPackage ./fully-static { inherit (pkgs) buildPackages; };
3030 ghc-options-cabal = haskell-nix.callPackage ./ghc-options/cabal.nix {};
3131 ghc-options-stack = haskell-nix.callPackage ./ghc-options/stack.nix {};
32+ exe-only = haskell-nix.callPackage ./exe-only { inherit util; };
3233
3334 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
3435 # 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