stack exec does not find executable after stack build --profile

Created on 14 Jun 2019  ·  8Comments  ·  Source: commercialhaskell/stack

General summary/comments

When trying to run stack exec app after building with --profile (and without previously building without this flag) stack exec fails on "could not find executable".

Seems like stack does not add the profile build path into 'stack exec' PATH so it cannot find it.

Note that this bug does not happen if you define this in your stack.yaml:

build:
  library-profiling: true
  executable-profiling: true

Steps to reproduce

This reproduces in a very minimal environment, this gist contains the whole story

  1. Take the three stack.yaml, asdf-exe.cabal and Main.hs files from here: https://gist.github.com/soupi/995024e0c5dd9194ffb2949a8d10cbde
  2. build with --profile
  3. try to exec the binary
mkdir bug && cd bug
cd bug
wget https://gist.githubusercontent.com/soupi/995024e0c5dd9194ffb2949a8d10cbde/raw/ee033b34111cf5b3e0fe8e9f20a1e2af46a7b95a/asdf-exe.cabal
wget https://gist.githubusercontent.com/soupi/995024e0c5dd9194ffb2949a8d10cbde/raw/ee033b34111cf5b3e0fe8e9f20a1e2af46a7b95a/Main.hs
wget https://gist.githubusercontent.com/soupi/995024e0c5dd9194ffb2949a8d10cbde/raw/ee033b34111cf5b3e0fe8e9f20a1e2af46a7b95a/stack.yaml
stack build --profile
stack exec asdf-exe

Expected

program should run

Actual

$ stack exec asdf-exe
Executable named asdf-exe not found on path: ["/home/suppi/code/temp/asdf/asdf/.stack-work/install/x86_64-linux/0bd777249a6b78fc1e75a29ad125c689ebfc9c535f675bfa85708b5ecd2a9471/8.6.5/bin","/home/suppi/.stack/snapshots/x86_64-linux/0bd777249a6b78fc1e75a29ad125c689ebfc9c535f675bfa85708b5ecd2a9471/8.6.5/bin","/home/suppi/.stack/compiler-tools/x86_64-linux/ghc-8.6.5/bin","/home/suppi/.stack/programs/x86_64-linux/ghc-8.6.5/bin",...]

Stack version

$ stack --version
Version 2.1.1, Git revision f612ea85316bbc327a64e4ad8d9f0b150dc12d4b (7648 commits) x86_64 hpack-0.31.2

Method of installation

  • stack upgrade
documentation

Most helpful comment

@qrilka what you suggested does work and makes sense. I would suggest documenting this somewhere as this is a behaviour change from previous stack versions.

All 8 comments

Thanks for the report; I'll investigate shortly! I may have encountered something similar (without using --profile).

@soupi please try using stack exece --profile <your-exec-name>
The way Stack 2 works is a bit different than what we had in Stack 1: one of the main things are so called implicit snapshots, adding profiling changes such a snapshot so paths for stack with --profile and without it are different. @snoyberg do we have this documented anywhere in a good form? I'm struggling a bit with explaining it without going into internal details :-\

I'm not sure if we have it documented very thoroughly, but what you've said is most of the story. The snapshot build path depends on all of the settings involved, which includes whether or not profiling is enabled.

@qrilka what you suggested does work and makes sense. I would suggest documenting this somewhere as this is a behaviour change from previous stack versions.

I bumped into this today, too. I was running stack build --file-watch in one terminal and stack exec in another. It took me a while to realize why my changes weren’t getting picked up in the other terminal: stack exec was running a different version of the executable from what stack build was building!

The most awkward part of this is that I can’t actually figure out how to get stack exec to use the version I want. The full command I’m running to build the executable is

stack test --haddock-deps --fast --file-watch --ghc-options=-j8

but stack exec complains that --fast isn’t even a valid option, so I’m not sure what to do.

I also ran into this, following the build commands from Tweag's blog post.

I keep hitting this too.

I'm on

  • Win10
  • Stack version 2.1.3
  • lts-14.3 (GHC 8.6.5)

I think I am having the same issue on Windows 10 version 2004 with Version 2.4.0, Git revision 6be6c8fbf12940f061e7b10aadeb5fe44bead66b (dirty) (8132 commits) PRE-RELEASE x86_64 hpack-0.33.0. It seems that stack build puts the executable in a different location to the path that stack exec adds to the PATH. EDIT: I am not using -- profile.

stack build ends with Installing executable ansi-terminal-example in C:\Users\mikep\Documents\Code\GitHub\ansi-terminal\.stack-work\install\f4e278ce\bin

but stack exec ansi-terminal-example fails with: Executable named ansi-terminal-example not found on path: [".","C:\\Users\\mikep\\Documents\\Code\\GitHub\\ansi-terminal\\.stack-work\\install\\747ba8e1\\bin", ....

Was this page helpful?
0 / 5 - 0 ratings