commercialhaskell / commercialhaskell/stack

Bug: `stack build` and `stack --stack-yaml=stack.yaml build` interpret paths in YAML differently

Open
#4,029 2 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

### General summary/comments (optional)

When, at the top level of my project, I symlink to a `stack.yaml` in a
subdir, the way `stack` interprets the paths in that `stack.yaml`
depends on whether I explicitly tell `stack` where to find the YAML
file. I.e., a plain `stack build` succeeds, interpreting the paths in
the YAML file relative to the ***location of the symlink***, whereas
the explicit `stack --stack-yaml=stack.yaml build` and
`STACK_YAML=stack.yaml stack build` both fail, interpreting the paths
in the YAML file relative the ***location of the target of the
symlink***.

I would prefer that all three invocations interpret the paths relative
the location of the symlink -- because that avoids having to add a
bunch of `../` prefixes, and makes the actual YAML file robust to
`mv`s as long as the symlink is updated accordingly -- but the bug is
that the three invocations don't all behave the same.

### Steps to reproduce

``` console
$ stack --version
Version 1.7.1, Git revision 681c800873816c022739ca7ed14755e85a579565 (5807 commits) x86_64 hpack-0.28.2
# Create a dir to work in
$ mkdir -p /var/tmp/tmp/stack-symlink-path-bug
$ cd /var/tmp/tmp/stack-symlink-path-bug
# Download a package to refer to in the stack.yaml file
$ stack unpack microlens --to deps
# Create stack.yaml
$ stack init --resolver lts-11.9
$ grep -v '^#' stack.yaml
resolver: lts-11.9
packages:
- deps/microlens-0.4.9.1
# Move stack.yaml into subdir and create a symlink to it at top level
$ mkdir stack-yamls
$ mv stack.yaml stack-yamls
$ ln -s stack-yamls/stack.yaml ./
# Build with implicit stack.yaml: success
$ stack build
[success]
# Build with explicit stack.yaml: failure
$ stack --stack-yaml=stack.yaml build
/var/tmp/tmp/stack-symlink-path-bug/stack-yamls/deps/microlens-0.4.9.1/: getDirectoryContents:openDirStream: does not exist (No such file or directory)
# Build with explicit stack.yaml: failure
$ STACK_YAML=stack.yaml stack build
Getting project config file from STACK_YAML environment
/var/tmp/tmp/stack-symlink-path-bug/stack-yamls/deps/microlens-0.4.9.1/: getDirectoryContents:openDirStream: does not exist (No such file or directory)
```

### Expected

I expect that all three `stack build` invocations would behave the same.

### Actual

The `stack build` using the implicit `stack.yaml` behaves differently
from the two `stack build` invocations with an explicit `stack.yaml`.

### Method of installation

Via `stack upgrade`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.