on iko/ghcjs-patch-master help sign in
improve speed of make-config-files (#318) (#323)
24669a4Richard Wallace
builder/make-config-files.nix+44−27
@@ -1,4 +1,4 @@
1−{ stdenv, lib, haskellLib, ghc, nonReinstallablePkgs, runCommand }:
1+{ stdenv, lib, haskellLib, ghc, nonReinstallablePkgs, runCommand, writeText, writeScript }:
2
2
3let
3let
4 flagsAndConfig = field: xs: lib.optionalString (xs != []) ''
4 flagsAndConfig = field: xs: lib.optionalString (xs != []) ''
@@ -6,6 +6,8 @@ let
6 echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
6 echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
7 '';
7 '';
8
8
9+ target-pkg = "${ghc.targetPrefix}ghc-pkg";
10+
9 # This is a bit of a hack. So we'll have a slightly longer explaination here:
11 # This is a bit of a hack. So we'll have a slightly longer explaination here:
10 # exactDep will pass --exact-configuration to the `SETUP_HS confiugre` command.
12 # exactDep will pass --exact-configuration to the `SETUP_HS confiugre` command.
11 # This requires us to pass --dependency={dep name}={pkg id}. The dependency
13 # This requires us to pass --dependency={dep name}={pkg id}. The dependency
@@ -20,38 +22,57 @@ let
20 # sublib name to exactDep, as we don't have access to it at the call-site,
22 # sublib name to exactDep, as we don't have access to it at the call-site,
21 # we resort to a bit of globbing, which (as pkg db's should contain only
23 # we resort to a bit of globbing, which (as pkg db's should contain only
22 # a single package) work.
24 # a single package) work.
23− exactDep = pdbArg: p: ''
25+ exactDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-exactdep" { inherit nativeBuildInputs; } ''
26+ mkdir -p $out
27+ touch $out/configure-flags
28+ touch $out/cabal.config
29+
24− if id=$(target-pkg ${pdbArg} field ${p} id --simple-output); then
30+ if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then
25 echo "--dependency=${p}=$id" >> $out/configure-flags
31 echo "--dependency=${p}=$id" >> $out/configure-flags
26− elif id=$(target-pkg ${pdbArg} field "z-${p}-z-*" id --simple-output); then
32+ elif id=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" id --simple-output); then
27− name=$(target-pkg ${pdbArg} field "z-${p}-z-*" name --simple-output)
33+ name=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" name --simple-output)
28 # so we are dealing with a sublib. As we build sublibs separately, the above
34 # so we are dealing with a sublib. As we build sublibs separately, the above
29 # query should be safe.
35 # query should be safe.
30 echo "--dependency=''${name#z-${p}-z-}=$id" >> $out/configure-flags
36 echo "--dependency=''${name#z-${p}-z-}=$id" >> $out/configure-flags
31 fi
37 fi
32− if ver=$(target-pkg ${pdbArg} field ${p} version --simple-output); then
38+ if ver=$(${target-pkg} ${pdbArg} field ${p} version --simple-output); then
33 echo "constraint: ${p} == $ver" >> $out/cabal.config
39 echo "constraint: ${p} == $ver" >> $out/cabal.config
34 echo "constraint: ${p} installed" >> $out/cabal.config
40 echo "constraint: ${p} installed" >> $out/cabal.config
35 fi
41 fi
36 '';
42 '';
37
43
38− envDep = pdbArg: p: ''
44+ catExactDep = dep: ''
45+ cat ${dep}/configure-flags >> $out/configure-flags
46+ cat ${dep}/cabal.config >> $out/cabal.config
47+ '';
48+
49+ catPkgExactDep = p:
50+ catExactDep (exactDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
51+
52+ catGhcPkgExactDep = p: catExactDep (exactDep "" p [ghc]);
53+
54+ envDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-envdep" { inherit nativeBuildInputs; } ''
55+ touch $out
39− if id=$(target-pkg ${pdbArg} field ${p} id --simple-output); then
56+ if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then
40− echo "package-id $id" >> $out/ghc-environment
57+ echo "package-id $id" >> $out
41 fi
58 fi
42 '';
59 '';
43
60
44−in { identifier, component, fullName, flags ? {} }:
61+ catEnvDep = ghcEnv: ''
62+ cat ${ghcEnv} >> $out/ghc-environment
63+ '';
64+
65+ catPkgEnvDep = p:
66+ catEnvDep (envDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
67+
68+ catGhcPkgEnvDep = p: catEnvDep (envDep "" p [ghc]);
45
69
70+ packageDb = p: "--package-db ${p.components.library or p}/package.conf.d";
71+in { identifier, component, fullName, flags ? {} }:
46 runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
72 runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
47 mkdir -p $out
73 mkdir -p $out
48
74
49− # Calls ghc-pkg for the target platform
50− target-pkg() {
51− ${ghc.targetPrefix}ghc-pkg "$@"
52− }
53−
54− target-pkg init $out/package.conf.d
75+ ${target-pkg} init $out/package.conf.d
55
76
56 ${lib.concatStringsSep "\n" (lib.mapAttrsToList flagsAndConfig {
77 ${lib.concatStringsSep "\n" (lib.mapAttrsToList flagsAndConfig {
57 "extra-lib-dirs" = map (p: "${lib.getLib p}/lib") component.libs;
78 "extra-lib-dirs" = map (p: "${lib.getLib p}/lib") component.libs;
@@ -60,14 +81,12 @@ in { identifier, component, fullName, flags ? {} }:
60 })}
81 })}
61
82
62 # Copy over the nonReinstallablePkgs from the global package db.
83 # Copy over the nonReinstallablePkgs from the global package db.
63− # Note: we need to use --global-package-db with ghc-pkg to prevent it
64− # from looking into the implicit global package db when registering the package.
65 ${lib.concatMapStringsSep "\n" (p: ''
84 ${lib.concatMapStringsSep "\n" (p: ''
66− target-pkg describe ${p} | target-pkg --force --global-package-db $out/package.conf.d register - || true
85+ find ${ghc}/lib/${ghc.name}/package.conf.d -name '${p}*.conf' -exec cp -f {} $out/package.conf.d \;
67 '') nonReinstallablePkgs}
86 '') nonReinstallablePkgs}
68
87
69 ${lib.concatMapStringsSep "\n" (p: ''
88 ${lib.concatMapStringsSep "\n" (p: ''
70− target-pkg --package-db ${p}/package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register -
89+ cp -f "${p}/package.conf.d/"*.conf $out/package.conf.d
71 '') (haskellLib.flatLibDepends component)}
90 '') (haskellLib.flatLibDepends component)}
72
91
73 # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
92 # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
@@ -82,16 +101,16 @@ in { identifier, component, fullName, flags ? {} }:
82 cat > $out/ghc-environment <<EOF
101 cat > $out/ghc-environment <<EOF
83 package-db $out/package.conf.d
102 package-db $out/package.conf.d
84 EOF
103 EOF
85− ${lib.concatMapStringsSep "\n" (p: envDep "--package-db ${p.components.library or p}/package.conf.d" p.identifier.name) component.depends}
86− ${lib.concatMapStringsSep "\n" (envDep "") (lib.remove "ghc" nonReinstallablePkgs)}
87
104
105+ ${lib.concatMapStringsSep "\n" catPkgEnvDep component.depends}
106+ ${lib.concatMapStringsSep "\n" catGhcPkgEnvDep (lib.remove "ghc" nonReinstallablePkgs)}
88 '' + lib.optionalString component.doExactConfig ''
107 '' + lib.optionalString component.doExactConfig ''
89 echo "--exact-configuration" >> $out/configure-flags
108 echo "--exact-configuration" >> $out/configure-flags
90 echo "allow-newer: ${identifier.name}:*" >> $out/cabal.config
109 echo "allow-newer: ${identifier.name}:*" >> $out/cabal.config
91 echo "allow-older: ${identifier.name}:*" >> $out/cabal.config
110 echo "allow-older: ${identifier.name}:*" >> $out/cabal.config
92
111
93− ${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library or p}/package.conf.d" p.identifier.name) component.depends}
112+ ${lib.concatMapStringsSep "\n" catPkgExactDep component.depends}
94− ${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs}
113+ ${lib.concatMapStringsSep "\n" catGhcPkgExactDep nonReinstallablePkgs}
95
114
96 ''
115 ''
97 # This code originates in the `generic-builder.nix` from nixpkgs. However GHC has been fixed
116 # This code originates in the `generic-builder.nix` from nixpkgs. However GHC has been fixed
@@ -124,7 +143,5 @@ in { identifier, component, fullName, flags ? {} }:
124 sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," $f
143 sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," $f
125 done
144 done
126 '' + ''
145 '' + ''
127− target-pkg --package-db $out/package.conf.d recache
146+ ${target-pkg} -v0 --package-db $out/package.conf.d recache
128− '' + ''
129− target-pkg --package-db $out/package.conf.d check
130 '')
147 '')