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
This commit is contained in:
Zhenya Vinogradov 2020-12-09 07:43:36 +03:00 committed by GitHub
parent a62a254683
commit 99fdad7640
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 2 deletions

View File

@ -32,8 +32,18 @@ let
then haskellLib.cleanSourceWith {
inherit src;
filter = path: type:
pkgs.lib.hasSuffix ("/" + stackYaml) path
|| (resolver != null && pkgs.lib.hasSuffix ("/" + resolver) path);
let
origSrc = if src ? _isLibCleanSourceWith then src.origSrc else src;
origSubDir = if src ? _isLibCleanSourceWithEx then src.origSubDir else "";
relPath = pkgs.lib.removePrefix (toString origSrc + origSubDir + "/") path;
# checks if path1 is a parent directory for path2
isParent = path1: path2: pkgs.lib.hasPrefix "${path1}/" path2;
in
(relPath == stackYaml)
|| (resolver != null && (relPath == resolver || isParent relPath resolver))
;
}
else src;

View File

@ -158,6 +158,7 @@ let
builder-haddock = callTest ./builder-haddock {};
stack-simple = callTest ./stack-simple {};
stack-local-resolver = callTest ./stack-local-resolver {};
stack-local-resolver-subdir = callTest ./stack-local-resolver-subdir {};
stack-remote-resolver = callTest ./stack-remote-resolver {};
shell-for-setup-deps = callTest ./shell-for-setup-deps { inherit compiler-nix-name; };
setup-deps = import ./setup-deps { inherit pkgs compiler-nix-name; };

View File

@ -0,0 +1,2 @@
/.stack-work/
/*.cabal

View File

@ -0,0 +1,14 @@
{ project', recurseIntoAttrs, testSrc }:
let
project = project' {
src = testSrc "stack-local-resolver-subdir";
};
packages = project.hsPkgs;
in recurseIntoAttrs {
ifdInputs = {
inherit (project) stack-nix;
};
inherit (packages.stack-local-resolver.components) library;
}

View File

@ -0,0 +1,7 @@
name: stack-local-resolver
dependencies:
- base
library:
source-dirs: src

View File

@ -0,0 +1,4 @@
name: local-snapshot
resolver: lts-14.13
packages: []

View File

@ -0,0 +1,6 @@
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"

View File

@ -0,0 +1,4 @@
resolver: snapshot/snapshot.yaml
packages:
- .