Opened 19 months ago

Last modified 2 months ago

#13753 new feature request

Improve GHC's ghc package environment lookup logic

Reported by: hvr Owned by:
Priority: normal Milestone: 8.8.1
Component: Compiler Version: 8.0.1
Keywords: Cc: RyanGlScott, int-e
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4690
Wiki Page:

Description

Documentation for package enviroments which describes the current lookup logic: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html#package-environments

There's two things I'd like to improve:

  1. Define a special magic "null" environment, which instructs GHC to ignore any package environment files. To this end, I propose to use the name - (i.e. a single dash), as that is more portable than using the empty string for environment variables. In other words:
    • -package-env - or
    • GHC_ENVIRONMENT=- (unless a -package-env flag which has higher priority overrides it)
    would prevent GHC from interpreting any package environment files.
  1. Provide a way to disambiguate environment names (i.e. those that are looked up in $HOME/.ghc/arch-os-version/environments/name) and environment files arguments. Currently, if you say GHC_ENVIRONMENT=test then a local file test would shadow the environment named test which would result in rather confusing errors. Instead I suggest to have package-env identifiers be interpreted as "names" by default, and only if they look like relative or absolute paths (i.e. ./foobar or /home/foo/...) be interpreted as file locations (relative to $CWD).

Change History (12)

comment:1 Changed 19 months ago by RyanGlScott

Cc: RyanGlScott added

comment:2 Changed 15 months ago by bgamari

Milestone: 8.2.28.4.1

It doesn't look like this will happen for 8.2.2.

comment:3 Changed 11 months ago by bgamari

Milestone: 8.4.18.6.1

This ticket won't be resolved in 8.4; remilestoning for 8.6. Do holler if you are affected by this or would otherwise like to work on it.

comment:4 Changed 7 months ago by gershomb

Along with this, GHC and GHCI should always notify when loading with a package-env file. The default lookup paths make it too easy to accidentally run with a file when you don't realize you are, causing potentially strange behavior. Now that cabal new-* commands generate these files by default, I imagine there will be many people confused by this.

comment:5 Changed 7 months ago by gershomb

And one other note -- if the env file points to bad/missing stuff, GHC should emit an error that points to the env file as the source of the problem!

comment:6 Changed 7 months ago by hvr

I've created #15145 to track the notification feature, for which I have already a working patch which I'll upload asap to Phab for further discussion.

comment:7 Changed 7 months ago by hvr

Differential Rev(s): Phab:D4690

Phab:D4690 implements the first half of this feature request, i.e. the ability to opt out from the package environment feature.

comment:8 Changed 7 months ago by int-e

Cc: int-e added

comment:9 Changed 7 months ago by Ben Gamari <ben@…>

In 8f3c149/ghc:

Add support for opting out of package environments

This implements the first part proposed in #13753:

Define a special magic "null" environment, which instructs GHC to ignore
any package environment files. To this end, I propose to use the name
`-` (i.e. a single dash), as that is more portable than using the empty
string for environment variables. In other words, a

- `-package-env -` CLI flag, or a
- `GHC_ENVIRONMENT=-` env var (unless a `-package-env` flag is present)

would inhibit GHC from looking up and interpreting any package
environment files from the filesystem; this is the equivalent of
`-ignore-dot-ghci` for package environment files.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13753

Differential Revision: https://phabricator.haskell.org/D4690

comment:10 Changed 6 months ago by bgamari

Milestone: 8.6.18.8.1

These will not be addressed in GHC 8.6.

comment:11 Changed 4 months ago by refold

Just to clarify: Ben's latest comment refers to the second part of the ticket, the `-package-env -` patch will be in 8.6.

comment:12 Changed 2 months ago by bgamari

comment:9 has been backported to ghc-8.4 in 84c250b41b22604a830a1a8152bad8167a8b0db1.

Last edited 2 months ago by bgamari (previous) (diff)
Note: See TracTickets for help on using tickets.