[GHC] #15513: How to pass "-hide-all-packages" to the GHC API?

GHC ghc-devs at haskell.org
Mon Aug 13 14:45:32 UTC 2018


#15513: How to pass "-hide-all-packages" to the GHC API?
-------------------------------------+-------------------------------------
           Reporter:  lspitzner      |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:  8.6.1
          Component:  Documentation  |           Version:  8.4.3
           Keywords:  environment    |  Operating System:  Unknown/Multiple
  file API                           |
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 In brittany, we have make use of the GHC API e.g. in the following
 fashion:

 {{{#!hs
 parseModuleFromString
   :: [String]
   -> System.IO.FilePath
   -> (GHC.DynFlags -> IO (Either String a))
   -> String
   -> IO (Either String (ExactPrint.Anns, GHC.ParsedSource, a))
 parseModuleFromString args fp dynCheck str =
   mask_ $ ExactPrint.ghcWrapper $ ExceptT.runExceptT $ do
     dflags0                       <- lift $ ExactPrint.initDynFlagsPure fp
 str
     (dflags1, leftover, warnings) <- lift
       $ GHC.parseDynamicFlagsCmdLine dflags0 (GHC.noLoc <$> args)
     when (not $ null leftover)
       $  ExceptT.throwE
       $  "when parsing ghc flags: leftover flags: "
       ++ show (leftover <&> \(L _ s) -> s)
     when (not $ null warnings)
       $  ExceptT.throwE
       $  "when parsing ghc flags: encountered warnings: "
       ++ show (warnings <&> warnExtractorCompat)
     dynCheckRes <- ExceptT.ExceptT $ liftIO $ dynCheck dflags1
     let res = ExactPrint.parseModuleFromStringInternal dflags1 fp str
     case res of
       Left  (span, err) -> ExceptT.throwE $ show span ++ ": " ++ err
       Right (a   , m  ) -> pure (a, m, dynCheckRes)
 }}}

 This code unfortunately picks up "package environment files", which I take
 it is not at all necessary for this use-case: Brittany only requires
 parsing functionality, so external packages should be irrelevant.
 "Unfortunately", because the package environment files can easily become
 stale, which in turn breaks the API.

 The users' guide mentions the "-hide-all-packages" flag, but my attempts
 to pass this to the API so far have failed. What I have tried is calling
 `parseDynamicFlagsCmdLine` with "-hide-all-packages" as an argument, and
 using the resulting dynflags afterwards. This appears to be without
 effect, I think even when it is the first thing executed inside of
 `runGhc`.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15513>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list