Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal fails to find project on windows #29

Open
1 of 4 tasks
edmundnoble opened this issue Mar 28, 2019 · 9 comments
Open
1 of 4 tasks

Cabal fails to find project on windows #29

edmundnoble opened this issue Mar 28, 2019 · 9 comments

Comments

@edmundnoble
Copy link
Contributor

edmundnoble commented Mar 28, 2019

Status

  • A workaround is available
    The following workaround might help with some cases of this issue:

    OK. Dig more. I found a workaround. Just pick 'bare' type for the workspace and ghci will pick the dependencies from the .ghc.environment.-- file under your project and load your modules successfully.

  • A fix is written
  • A fix is released
  • The fixed verison is on the marketplace.

  • Version of vscode-ghc-simple: 0.1.7
  • Version of VSCode: 1.32.3
  • Version of Haskell-related tools:
    • GHC: 8.6.4
    • Stack:
    • Cabal: 2.4.10

Steps to reproduce

Open a Haskell file in VS code, where the workspace is cabal new.

The cabal instance started by vscode-ghc-simple reports:

    -> :set prompt ""
ghci | cabal.exe: No targets given and there is no package in the current directory.
ghci | Use the target 'all' for all packages in the project or specify packages or
ghci | components by name or location. See 'cabal build --help' for more details on
ghci | target options.
ghci | 

Hinting that cabal is being run in the wrong folder. However, running cd (which prints out the current working directory) using the same options as cabal is run with shows the exact same path that I get when I run cd myself from cmd inside of the project folder, and running cabal new-repl from there works fine.

Workspace

Create a project using cabal init, use the cabal 2.4 style init when prompted. Use the src/ source directoy.

@dramforever
Copy link
Owner

This is a weird problem.

I cannot reproduce this on Linux: everything works fine. It seems to be Windows specific and cabal new-build specific.

Hinting that cabal is being run in the wrong folder. However, running cd (which prints out the current working directory) using the same options as cabal is run with shows the exact same path that I get when I run cd myself from cmd inside of the project folder, and running cabal new-repl from there works fine.

I remember wondering about this exact weirdness back when I first tried to add cabal new-build support, and I was on Windows back then. I guess this problem didn't magically fix itself.

@dramforever
Copy link
Owner

Wait, when outside of a project cabal new-repl actually builts a 'fake-package' and launches GHCi from it. So how is this error message even possible?

@hughjfchen
Copy link

I met the same problem on MacOS. ghc-simple output hints that it's running outside of the current project folder and trying to build a fake-package. No modules from my project loaded.

@hughjfchen
Copy link

OK. I did some tests:

  1. cabal new-repl under my project folder works fine
  2. start vscode from my project directory, open a haskell source file, ghc-simple outputs that it's trying to build a fake-package and success. But when it tried to load my module, it complains it can't find dependencies packages of my module and failed to load my module
  3. I cabal init a hello-world project, and ghc-simple load the source file successfully because the module has no extra dependencies except base

based on above 3 points, I guess ghc-simple start 'cabel new-reple' under the fake-package folder, not my project folder. So questions are:

  1. why do we need to try to build a fake-package before start ghci?
  2. will building the fake-package change the working directory for this extension?
  3. how can we track the working directory before start ghci and after building the fake-package?
  4. any thing else do we need to identify this problem?

@hughjfchen
Copy link

OK. Dig more. I found a workaround. Just pick 'bare' type for the workspace and ghci will pick the dependencies from the .ghc.environment.-- file under your project and load your modules successfully.

@dramforever
Copy link
Owner

why do we need to try to build a fake-package before start ghci?

This is the behavior of cabal new-repl outside of a project directory and is not implemented in vscode-ghc-simple.

Which is weird, since I do set cwd of the subprocess to the workspace folder. I'll have to investigate why it's not working as intended.

@hughjfchen
Copy link

OK. So the problem is when ghc-simple trying to start a session, the working directory is not my project directory where the active source file of the workspace located.
Wait, the active source file of the workspace is located at /src, not . Maybe cwd is /src , not . But how comes ghci working under the ? Can't figure out that.

@aboichis
Copy link

aboichis commented May 15, 2019

AFAICT the problem is that vscode launches cabal with a cwd that has a lowercase drive letter.
For example, in cmd.exe:

G:\cabaltest>cabal new-build --dry-run
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O1
In order, the following would be built (use -v for more details):
 - cabaltest-0.1.0.0 (exe:cabaltest) (first run)

G:\cabaltest>cd .. && cd g:\cabaltest

g:\cabaltest>cabal new-build --dry-run
cabal: No targets given and there is no package in the current directory. Use
the target 'all' for all packages in the project or specify packages or
components by name or location. See 'cabal build --help' for more details on
target options.

@hughjfchen
Copy link

But I'm on MacOS and also had this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants