on iko/ghcjs-patch-master help sign in
Improve cleaning of stack projects (#1074)
44ecbc8Hamish Mackenzie
lib/call-stack-to-nix.nix+26−11
@@ -23,9 +23,20 @@ let
23 }) resolver fetchedResolver;
23 }) resolver fetchedResolver;
24
24
25 subDir' = src.origSubDir or "";
25 subDir' = src.origSubDir or "";
26+ subDir = pkgs.lib.strings.removePrefix "/" subDir';
27+ maybeCleanedSource =
28+ if haskellLib.canCleanSource src
29+ then (haskellLib.cleanSourceWith {
30+ name = if name != null then "${name}-root-cabal-files" else "source-root-cabal-files";
31+ src = src.origSrc or src;
32+ filter = path: type: (!(src ? filter) || src.filter path type) && (
33+ type == "directory" ||
34+ pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ stackYaml ".cabal" "package.yaml" ]); })
35+ else src.origSrc or src;
36+
26 stackToNixArgs = builtins.concatStringsSep " " [
37 stackToNixArgs = builtins.concatStringsSep " " [
27 "--full"
38 "--full"
28− "--stack-yaml=$SRC/${stackYaml}"
39+ "--stack-yaml=$SRC${subDir'}/${stackYaml}"
29 (if ignorePackageYaml then "--ignore-package-yaml" else "")
40 (if ignorePackageYaml then "--ignore-package-yaml" else "")
30 "-o ."
41 "-o ."
31 ];
42 ];
@@ -46,18 +57,22 @@ let
46 preferLocalBuild = false;
57 preferLocalBuild = false;
47 } (''
58 } (''
48 mkdir -p $out${subDir'}
59 mkdir -p $out${subDir'}
60+ SRC=$(mktemp -d)
61+ cd $SRC
62+ # if maybeCleanedSource is empty, this means it's a new
63+ # project where the files haven't been added to the git
64+ # repo yet. We fail early and provide a useful error
65+ # message to prevent headaches (#290).
66+ if [ -z "$(ls -A ${maybeCleanedSource})" ]; then
67+ echo "cleaned source is empty. Did you forget to 'git add -A'?"; exit 1;
68+ fi
69+ lndir -silent "${maybeCleanedSource}/." $SRC
70+ ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"}
49 ${
71 ${
50− # If no resolver was fetched use the original stack.yaml
72+ # If a resolver was fetched use the it instead of the original stack.yaml
51− if fetchedResolver == null
73+ pkgs.lib.optionalString (fetchedResolver != null)
52− then ''
53− SRC=${src}
54− ''
55− else
56 # Replace the resolver path in the stack.yaml with the fetched version
74 # Replace the resolver path in the stack.yaml with the fetched version
57 ''
75 ''
58− SRC=$(mktemp -d)
59− cd $SRC
60− lndir -silent "${src}/." $SRC
61 rm ${stackYaml}
76 rm ${stackYaml}
62 cp ${src}/${stackYaml} .
77 cp ${src}/${stackYaml} .
63 chmod +w ${stackYaml}
78 chmod +w ${stackYaml}
@@ -71,7 +86,7 @@ let
71 # We need to strip out any references to $src, as those won't
86 # We need to strip out any references to $src, as those won't
72 # be accessable in restricted mode.
87 # be accessable in restricted mode.
73 for nixf in $(find $out -name "*.nix" -type f); do
88 for nixf in $(find $out -name "*.nix" -type f); do
74− substituteInPlace $nixf --replace "$SRC" "."
89+ substituteInPlace $nixf --replace "$SRC${subDir'}" "."
75 done
90 done
76
91
77 # move pkgs.nix to default.nix ensure we can just nix `import` the result.
92 # move pkgs.nix to default.nix ensure we can just nix `import` the result.
lib/fetch-resolver.nix+6−2
@@ -5,10 +5,12 @@
5, resolverSha256 ? null
5, resolverSha256 ? null
6}:
6}:
7let
7let
8+ srcDir = src.origSrcSubDir or src;
9+
8 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
10 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
9 # access to the store is restricted. If origSrc was already in the store
11 # access to the store is restricted. If origSrc was already in the store
10 # you can pass the project in as a string.
12 # you can pass the project in as a string.
11− rawStackYaml = builtins.readFile ((src.origSrcSubDir or src) + ("/" + stackYaml));
13+ rawStackYaml = builtins.readFile (srcDir + "/${stackYaml}");
12
14
13 # Determine the resolver as it may point to another file we need
15 # Determine the resolver as it may point to another file we need
14 # to look at.
16 # to look at.
@@ -28,6 +30,8 @@ let
28 url = resolver;
30 url = resolver;
29 sha256 = resolverSha256;
31 sha256 = resolverSha256;
30 }
32 }
33+ else if resolver != null && __pathExists (srcDir + "/${resolver}")
34+ then pkgs.copyPathToStore (srcDir + "/${resolver}")
31− else null;
35+ else null;
32
36
33in { inherit resolver fetchedResolver; }
37in { inherit resolver fetchedResolver; }