on iko/ghcjs-patch-master help sign in
Fix stack.yaml filtering when resolver file is in a subdirectory (#943)

* Fix stack.yaml filtering when resolver file is in a subdirectory `maybeCleanedSource` tries to include the resolver file into the cleaned source, if a resolver is specified, but it was only working when the file was in the root of the project, because all directories would be filtered out. * fixup! Fix stack.yaml filtering when resolver file is in a subdirectory Fix calculating relPath for paths using subDir * Add test case for local stack snapshot located in a subdirectory

commit99fdad764061f4166e4c0d1d8783bd039c7bb851 authorZhenya Vinogradov <zhenyavinogradov@gmail.com> dateWed 9 Dec 2020, 07:43 (6 years ago) parenta62a254
8 files changed+50−2
lib/stack-cache-generator.nix+12−2 test/default.nix+1 test/stack-local-resolver-subdir/.gitignore+2 test/stack-local-resolver-subdir/default.nix+14 test/stack-local-resolver-subdir/package.yaml+7 test/stack-local-resolver-subdir/snapshot/snapshot.yaml+4 test/stack-local-resolver-subdir/src/Lib.hs+6 test/stack-local-resolver-subdir/stack.yaml+4
lib/stack-cache-generator.nix+12−2
@@ -32,8 +32,18 @@ let
3232 then haskellLib.cleanSourceWith {
3333 inherit src;
3434 filter = path: type:
35− pkgs.lib.hasSuffix ("/" + stackYaml) path
36− || (resolver != null && pkgs.lib.hasSuffix ("/" + resolver) path);
35+ let
36+ origSrc = if src ? _isLibCleanSourceWith then src.origSrc else src;
37+ origSubDir = if src ? _isLibCleanSourceWithEx then src.origSubDir else "";
38+ relPath = pkgs.lib.removePrefix (toString origSrc + origSubDir + "/") path;
39+
40+ # checks if path1 is a parent directory for path2
41+ isParent = path1: path2: pkgs.lib.hasPrefix "${path1}/" path2;
42+
43+ in
44+ (relPath == stackYaml)
45+ || (resolver != null && (relPath == resolver || isParent relPath resolver))
46+ ;
3747 }
3848 else src;
3949
test/default.nix+1
@@ -158,6 +158,7 @@ let
158158 builder-haddock = callTest ./builder-haddock {};
159159 stack-simple = callTest ./stack-simple {};
160160 stack-local-resolver = callTest ./stack-local-resolver {};
161+ stack-local-resolver-subdir = callTest ./stack-local-resolver-subdir {};
161162 stack-remote-resolver = callTest ./stack-remote-resolver {};
162163 shell-for-setup-deps = callTest ./shell-for-setup-deps { inherit compiler-nix-name; };
163164 setup-deps = import ./setup-deps { inherit pkgs compiler-nix-name; };
test/stack-local-resolver-subdir/.gitignorenew file+2
@@ -0,0 +1,2 @@
1+/.stack-work/
2+/*.cabal
test/stack-local-resolver-subdir/default.nixnew file+14
@@ -0,0 +1,14 @@
1+{ project', recurseIntoAttrs, testSrc }:
2+
3+let
4+ project = project' {
5+ src = testSrc "stack-local-resolver-subdir";
6+ };
7+ packages = project.hsPkgs;
8+
9+in recurseIntoAttrs {
10+ ifdInputs = {
11+ inherit (project) stack-nix;
12+ };
13+ inherit (packages.stack-local-resolver.components) library;
14+}
test/stack-local-resolver-subdir/package.yamlnew file+7
@@ -0,0 +1,7 @@
1+name: stack-local-resolver
2+
3+dependencies:
4+- base
5+
6+library:
7+ source-dirs: src
test/stack-local-resolver-subdir/snapshot/snapshot.yamlnew file+4
@@ -0,0 +1,4 @@
1+name: local-snapshot
2+resolver: lts-14.13
3+
4+packages: []
test/stack-local-resolver-subdir/src/Lib.hsnew file+6
@@ -0,0 +1,6 @@
1+module Lib
2+ ( someFunc
3+ ) where
4+
5+someFunc :: IO ()
6+someFunc = putStrLn "someFunc"
test/stack-local-resolver-subdir/stack.yamlnew file+4
@@ -0,0 +1,4 @@
1+resolver: snapshot/snapshot.yaml
2+
3+packages:
4+- .