Ticket #5977 (closed feature request: fixed)

Opened 14 months ago

Last modified 12 months ago

Allow ignoring global package db

Reported by: duncan Owned by: pcapriotti
Priority: high Milestone: 7.6.1
Component: Compiler Version: 7.4.1
Keywords: Cc: JeremyShaw
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

For sandboxing, users want to be able to use only local package dbs. To handle rts, base etc, they copy those specific packages from the global package db into a local package db.

Currently however there is no sensible way to tell ghc to look only at the listed package dbs, and not the global db. There is a flag -no-user-package-conf to avoid looking at the per-user one, but no equivalent to ignore or to specify the global one.

(Note: as a quirky non-sensible way, you can use GHC_PACKAGE_PATH="" to clear the package db stack, but this should be possible using command line flags.)

The user interface we're now using in cabal is like this:

  • --global sets the initial db stack to [GlobalPackageDB]
  • --user sets the initial db stack to [GlobalPackageDB, UserPackageDB]
  • --package-db=clear clears the db stack to []
  • --package-db=global pushes GlobalPackageDB on the top of the stack
  • --package-db=user pushes UserPackageDB on the top of the stack
  • --package-db=${otherfile} pushes SpecificPackageDB ${otherfile} on the top of the stack

It seems to me we could do something similar with ghc. Currently in ghc we have a -hide-all-packages flag that resets the package set to empty. We could do with an equivalent for the package database stack. I suggest something like:

  • -clear-package-conf
  • -global-package-conf
  • -user-package-conf (and the existing -no-user-package-conf)
  • -package-conf file

The default would remain that the global and user dbs are used, but this can be reset using -clear-package-conf.

Personally I prefer the nomenclarture "package db" rather than "package conf" here, but it's not that important.

Attachments

0001-Add-flags-to-manipulate-package-db-stack-5977.patch Download (7.5 KB) - added by pcapriotti 13 months ago.
0002-Rename-package-conf-flags-to-package-db.patch Download (16.0 KB) - added by pcapriotti 13 months ago.
0003-Update-documentation-of-the-package-db-flags.patch Download (10.7 KB) - added by pcapriotti 13 months ago.
5977-tests.patch Download (21.8 KB) - added by pcapriotti 13 months ago.
0004-Simplify-the-behavior-of-package-db-flags.patch Download (9.4 KB) - added by pcapriotti 13 months ago.

Change History

  Changed 14 months ago by JeremyShaw

  • cc JeremyShaw added

  Changed 14 months ago by simonmar

  • priority changed from normal to high
  • difficulty set to Unknown
  • milestone set to 7.6.1

Yep, let's do something for 7.6.1.

  Changed 13 months ago by simonpj

  • owner set to pcapriotti

Changed 13 months ago by pcapriotti

Changed 13 months ago by pcapriotti

Changed 13 months ago by pcapriotti

Changed 13 months ago by pcapriotti

  Changed 13 months ago by pcapriotti

  • status changed from new to patch

The attached patch series adds the extra flags described in this ticket (with the addition of no-global-package-conf, for symmetry), and renames them to *-package-db.

You can find the corresponding patch for Cabal in my github fork:  https://github.com/pcapriotti/cabal

  Changed 13 months ago by simonpj

  • owner changed from pcapriotti to simonmar

follow-up: ↓ 8   Changed 13 months ago by simonmar

I had a look at the patches. The situation in DynFlags is now a bit strange - we have both the Opt_ReadGlobalPackageConf options and the [PkgConfRef]. I think we should have just the [PkgConfRef] representing the stack, and all the flags should manipulate it directly.

So

  • We start with [global,user]
  • -no-user-package-db removes user from the list (similarly for global)
  • -user-package-db adds user to the end (similarly for global)
  • -package-conf file adds file to the end
  • -clear-package-db sets the list to empty

  Changed 13 months ago by simonmar

  • owner changed from simonmar to pcapriotti

in reply to: ↑ 6   Changed 13 months ago by pcapriotti

I'm not sure how that would interact with GHC_PACKAGE_PATH. For example, if I run:

GHC_PACKAGE_PATH="foo:" ghc --no-user-package-db

I'd expect it to use [global, foo] as db stack, but we can't remove user from the stack originating from GHC_PACKAGE_PATH unless we keep the information somewhere (currently it's in Opt_ReadUserPackageConf).

So at the moment there is an "initial stack", which is [global, user] by default, and is affected by -no-user-package-db, -no-global-package-db, -clear-package-db, and GHC_PACKAGE_PATH. The other flags append to the stack *after* the initial stack has been determined.

  Changed 13 months ago by simonmar

I find it weird that -no-user-package-db affects the "initial stack", but -user-package-db appends the user db to the final stack. So e.g. -user-package-db -no-user-package-db does not do what you expect.

So I see two alternatives. One is to modify my proposal to take into account GHC_PACKAGE_PATH: just initialise the stack from GHC_PACKAGE_PATH before processing the arguments, defaulting to [global,user] if GHC_PACKAGE_PATH is not set.

The other alternative is to keep the concept of the "initial stack", but make -user-package-db and -global-package-db just the inverses of -no-user-package-db and -no-global-package-db respectively. I'd be ok with that too.

Changed 13 months ago by pcapriotti

  Changed 13 months ago by pcapriotti

The attached patch implements option 1. The list of flags is now maintained as a [PkgConfRef] -> [PkgConfRef], which is later applied to the base stack obtained by GHC_PACKAGE_PATH.

  Changed 13 months ago by simonmar

Yes, that looks ok.

  Changed 12 months ago by p.capriotti@…

commit 6a831be4aa73e86568256813ffa862d7cfd5732d

Author: Paolo Capriotti <p.capriotti@gmail.com>
Date:   Thu May 3 11:29:51 2012 +0100

    Add flags to manipulate package db stack (#5977)
    
    Introduce new flags to allow any package database stack to be set up.
    The `-no-user-package-conf` and `-no-global-package-conf` flags remove
    the corresponding package db from the initial stack, while
    `-user-package-conf` and `-global-package-conf` push it back on top of
    the stack.

 compiler/main/DynFlags.hs  |   24 +++++++++++--
 compiler/main/Packages.lhs |   81 +++++++++++++++++++++-----------------------
 2 files changed, 60 insertions(+), 45 deletions(-)

  Changed 12 months ago by pcapriotti

  • status changed from patch to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.