Opened 10 months ago

Last modified 6 months ago

#16360 new bug

GHC fails when GHC_PACKAGE_PATH contains trailing slash

Reported by: nh2 Owned by:
Priority: low Milestone:
Component: Compiler Version: 8.6.3
Keywords: newcomer Cc: nh2
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC doesn't work at all Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


When the directory given in GHC_PACKAGE_PATH contains a trailing slash, GHC stops working completely.

For example, this works:

env GHC_PACKAGE_PATH=/raid/src/ghc/ghc-atomic-writes/_build/stage1/lib/package.conf.d /raid/src/ghc/ghc-atomic-writes/_build/stage1/bin/ghc "--make" "-outputdir" "example-programs-build/" "example-programs/Hello.hs" "-o" "example-programs-build/haskell-hello"

but adding a trailing / like GHC_PACKAGE_PATH=/path/to/package.conf.d/ fails:

env GHC_PACKAGE_PATH=/raid/src/ghc/ghc-atomic-writes/_build/stage1/lib/package.conf.d/ /raid/src/ghc/ghc-atomic-writes/_build/stage1/bin/ghc "--make" "-outputdir" "example-programs-build/" "example-programs/Hello.hs" "-o" "example-programs-build/haskell-hello"    
[1 of 1] Compiling Main             ( example-programs/Hello.hs, example-programs-build/Main.o ) [Prelude changed]

example-programs/Hello.hs:1:1: error:
    Could not find module ‘Prelude’
    There are files missing in the ‘base-’ package,
    try running 'ghc-pkg check'.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
1 | main :: IO ()
  | ^

This is surprising; most programs accept trailing slashes where directories are expected, and shells ofthen TAB-complete directories this way. It wastes developer time when they don't notice.

Change History (3)

comment:1 Changed 10 months ago by nh2

Keywords: newcomer added

comment:2 Changed 10 months ago by nh2

Priority: normallow

comment:3 Changed 6 months ago by Marge Bot <ben+marge-bot@…>

In 9d238791/ghc:

Handle trailing path separator in package DB names (#16360)

Package DB directories with trailing separator (provided via
GHC_PACKAGE_PATH or via -package-db) resulted in incorrect calculation of
${pkgroot} substitution variable.  Keep the trailing separator while
resolving as directory or file, but remove it before dropping the last
path component with takeDirectory.

Closes #16360.
Note: See TracTickets for help on using tickets.