haskell / hie-bios

Set up a GHC API session for various Haskell Projects
https://hackage.haskell.org/package/hie-bios
BSD 3-Clause "New" or "Revised" License
179 stars 62 forks source link

Inappropriate "not listed in your .cabal file's other-modules" error #439

Open maximpichler opened 1 month ago

maximpichler commented 1 month ago

I'm getting the following error:

Dummy:0:0:Error:These modules are needed for compilation but not listed in your .cabal file's other-modules for ‘main’ :
    Utils

This is in spite of the fact that Utils is listed in the other-modules section.

$ cat xyz.cabal
cabal-version: 3.0
name:          xyz
version:       0.1.0.0
build-type:    Simple

executable xyz
  ghc-options:    -Wall
  main-is:        Main.hs
  other-modules:  Utils
  build-depends:  base ^>=4.19.1.0
  hs-source-dirs: app

$ cat app/Main.hs
module Main where

import Utils (x)

main :: IO ()
main = print x

$ cat app/Utils.hs
module Utils where

x :: Int
x = 42

There is no hie.yaml file.

fendor commented 1 month ago

Hi, thank you for the bug report! Can you provide the logs of hie-bios debug app/Main.hs?

maximpichler commented 1 month ago

It seems that the error only occurs with the check subcommand, not with the debug one. Here is the full output for both.

$ hie-bios debug app/Main.hs
[Info] invoking build tool to determine build flags (this may take some time depending on the cache)
[Debug] cabal --numeric-version
[Debug] cabal exec -v0 -- ghc --print-libdir
[Debug] cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
[Debug] cabal --builddir=/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1 v2-exec --with-compiler /Users/maxim/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/maxim/.cache/hie-bios/ghc-pkg-b75bdac3b19d57e56569fb6ca4599bc0 ghc -v0 -- --numeric-version
  Environment Variables
    HIE_BIOS_GHC: /nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/bin/ghc-9.8.2
    HIE_BIOS_GHC_ARGS: -B/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib
[Debug] cabal exec -v0 -- ghc --print-libdir
[Debug] cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
[Info] cabal --builddir=/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1 v2-repl --with-compiler /Users/maxim/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/maxim/.cache/hie-bios/ghc-pkg-b75bdac3b19d57e56569fb6ca4599bc0 app/Main.hs
  Environment Variables
    HIE_BIOS_OUTPUT: /private/tmp/nix-shell.ggSSEs/HIE_BIOS_OUTPUT83390-0
    HIE_BIOS_GHC: /nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/bin/ghc-9.8.2
    HIE_BIOS_GHC_ARGS: -B/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib
[Debug] Build profile: -w ghc-9.8.2 -O1
[Debug] In order, the following will be built (use -v for more details):
[Debug]  - xyz-0.1.0.0 (exe:xyz) (first run)
[Debug] Preprocessing executable 'xyz' for xyz-0.1.0.0..
[Debug] cabal exec -v0 -- ghc --print-libdir
[Debug] cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
[Debug] cabal --builddir=/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1 v2-exec --with-compiler /Users/maxim/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/maxim/.cache/hie-bios/ghc-pkg-b75bdac3b19d57e56569fb6ca4599bc0 ghc -v0 -- --print-libdir
  Environment Variables
    HIE_BIOS_GHC: /nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/bin/ghc-9.8.2
    HIE_BIOS_GHC_ARGS: -B/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib
[Debug] cabal exec -v0 -- ghc --print-libdir
[Debug] cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
[Debug] cabal --builddir=/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1 v2-exec --with-compiler /Users/maxim/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/maxim/.cache/hie-bios/ghc-pkg-b75bdac3b19d57e56569fb6ca4599bc0 ghc -v0 -- --numeric-version
  Environment Variables
    HIE_BIOS_GHC: /nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/bin/ghc-9.8.2
    HIE_BIOS_GHC_ARGS: -B/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib
Root directory:        /Users/maxim/xyz
Component directory:   /Users/maxim/xyz
GHC options:           -fbuilding-cabal-package -O0 -outputdir /Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp -odir /Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp -hidir /Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp -stubdir /Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp -i -i/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp -iapp -i/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/autogen -i/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/global-autogen -I/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/autogen -I/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/global-autogen -I/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp -optP-include -optP/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/autogen/cabal_macros.h -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /Users/maxim/y/.cabal/store/ghc-9.8.2/package.db -package-db /Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/packagedb/ghc-9.8.2 -package-db /Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/package.conf.inplace -package-id base-4.19.1.0-inplace -XHaskell98 app/Main.hs Utils -Wall -hide-all-packages
GHC library directory: CradleSuccess "/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib"
GHC version:           CradleSuccess "9.8.2"
Config Location:       No explicit config found
Cradle:                Cradle{ cradleRootDir = "/Users/maxim/xyz", cradleOptsProg = CradleAction: Cabal}
Dependencies:          xyz.cabal cabal.project cabal.project.local
$ hie-bios check app/Main.hs
[Debug] cabal exec -v0 -- ghc --print-libdir
[Debug] cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
[Debug] cabal --builddir=/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1 v2-exec --with-compiler /Users/maxim/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/maxim/.cache/hie-bios/ghc-pkg-b75bdac3b19d57e56569fb6ca4599bc0 ghc -v0 -- --print-libdir
  Environment Variables
    HIE_BIOS_GHC: /nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/bin/ghc-9.8.2
    HIE_BIOS_GHC_ARGS: -B/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib
[Info] Cradle: Cradle{ cradleRootDir = "/Users/maxim/xyz", cradleOptsProg = CradleAction: Cabal}
[Info] invoking build tool to determine build flags (this may take some time depending on the cache)
[Debug] cabal --numeric-version
[Debug] cabal exec -v0 -- ghc --print-libdir
[Debug] cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
[Debug] cabal --builddir=/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1 v2-exec --with-compiler /Users/maxim/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/maxim/.cache/hie-bios/ghc-pkg-b75bdac3b19d57e56569fb6ca4599bc0 ghc -v0 -- --numeric-version
  Environment Variables
    HIE_BIOS_GHC: /nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/bin/ghc-9.8.2
    HIE_BIOS_GHC_ARGS: -B/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib
[Debug] cabal exec -v0 -- ghc --print-libdir
[Debug] cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
[Info] cabal --builddir=/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1 v2-repl --with-compiler /Users/maxim/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/maxim/.cache/hie-bios/ghc-pkg-b75bdac3b19d57e56569fb6ca4599bc0 app/Main.hs
  Environment Variables
    HIE_BIOS_OUTPUT: /private/tmp/nix-shell.ggSSEs/HIE_BIOS_OUTPUT83578-0
    HIE_BIOS_GHC: /nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/bin/ghc-9.8.2
    HIE_BIOS_GHC_ARGS: -B/nix/store/4imn003wyw1fn338i9znm7qm25bpkb9c-ghc-9.8.2/lib/ghc-9.8.2/lib
[Debug] Build profile: -w ghc-9.8.2 -O1
[Debug] In order, the following will be built (use -v for more details):
[Debug]  - xyz-0.1.0.0 (exe:xyz) (first run)
[Debug] Preprocessing executable 'xyz' for xyz-0.1.0.0..
[Debug] Set targets: [("app/Main.hs","app/Main.hs")]
[Debug] ModGraph: [ModLocation {ml_hs_file = Just "app/Main.hs", ml_hi_file = "/Users/maxim/.cache/hie-bios/b9fa09ce5296198935166d2e16897eb588042829/Main.hi", ml_dyn_hi_file = "/Users/maxim/.cache/hie-bios/b9fa09ce5296198935166d2e16897eb588042829/Main.dyn_hi", ml_obj_file = "/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp/Main.o", ml_dyn_obj_file = "/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp/Main.dyn_o", ml_hie_file = "/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp/Main.hie"},ModLocation {ml_hs_file = Just "/Users/maxim/xyz/app/Utils.hs", ml_hi_file = "/Users/maxim/.cache/hie-bios/b9fa09ce5296198935166d2e16897eb588042829/Utils.hi", ml_dyn_hi_file = "/Users/maxim/.cache/hie-bios/b9fa09ce5296198935166d2e16897eb588042829/Utils.dyn_hi", ml_obj_file = "/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp/Utils.o", ml_dyn_obj_file = "/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp/Utils.dyn_o", ml_hie_file = "/Users/maxim/.cache/hie-bios/dist-xyz-a7e63f893d4ee36251cd5964197be2c1/build/aarch64-osx/ghc-9.8.2/xyz-0.1.0.0/x/xyz/build/xyz/xyz-tmp/Utils.hie"}]
Dummy:0:0:Error:These modules are needed for compilation but not listed in your .cabal file's other-modules for ‘main’ :
    Utils
fendor commented 1 month ago

I think that's a bug in hie-bios's module checking logic. Perhaps a target guessing bug, since we see [("app/Main.hs","app/Main.hs")] is missing "app/Utils.hs".

To me, this code path has a rather low priority, and is only used for testing. Do you have a specific need?

maximpichler commented 1 month ago

I stumbled across this while debugging an issue with haskell-language-server and eglot. From what you say it seems that it is a red herring. Will report back if I come across any evidence to the contrary.