summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlanZimmerman <>2018-09-12 21:38:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-09-12 21:38:00 (GMT)
commit3019e8533f88b1372f1e94c8a3a03e0847f4e52b (patch)
tree50e18ce16eb419cc40aee9f51c7833221a74f48a
parent50239cf5b883b43136a02d2524e5091ce4b0ca61 (diff)
version 0.5.8.00.5.8.0
-rw-r--r--ChangeLog2
-rw-r--r--ghc-exactprint.cabal2
-rw-r--r--src/Language/Haskell/GHC/ExactPrint/Parsers.hs28
3 files changed, 26 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a4af6d8..e8872c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+2018-09-12 v0.5.8.0
+ * Disable use of .ghc.env files when parsing. By @lspitzner
2018-08-11 v0.5.7.0
* Include support for GHC 8.6.1 beta 1
2018-07-11 v0.5.7.0
diff --git a/ghc-exactprint.cabal b/ghc-exactprint.cabal
index c0c6488..76f368a 100644
--- a/ghc-exactprint.cabal
+++ b/ghc-exactprint.cabal
@@ -1,5 +1,5 @@
name: ghc-exactprint
-version: 0.5.7.1
+version: 0.5.8.0
synopsis: ExactPrint for GHC
description: Using the API Annotations available from GHC 7.10.2, this
library provides a means to round trip any code that can
diff --git a/src/Language/Haskell/GHC/ExactPrint/Parsers.hs b/src/Language/Haskell/GHC/ExactPrint/Parsers.hs
index 4037ef3..8feb2b2 100644
--- a/src/Language/Haskell/GHC/ExactPrint/Parsers.hs
+++ b/src/Language/Haskell/GHC/ExactPrint/Parsers.hs
@@ -277,7 +277,7 @@ parseModuleApiAnnsWithCppInternal cppOptions dflags file = do
GHC.POk (mkApiAnns -> apianns) pmod ->
Right $ (apianns, injectedComments, dflags', pmod)
--- | Internal function. Exposed if you want to much with DynFlags
+-- | Internal function. Exposed if you want to muck with DynFlags
-- before parsing. Or after parsing.
postParseTransform
:: Either a (GHC.ApiAnns, [Comment], GHC.DynFlags, GHC.ParsedSource)
@@ -289,6 +289,11 @@ postParseTransform parseRes opts = either Left mkAnns parseRes
Right (relativiseApiAnnsWithOptions opts cs m apianns, m)
-- | Internal function. Initializes DynFlags value for parsing.
+--
+-- Passes "-hide-all-packages" to the GHC API to prevent parsing of
+-- package environment files. However this only works if there is no
+-- invocation of `setSessionDynFlags` before calling `initDynFlags`.
+-- See ghc tickets #15513, #15541.
initDynFlags :: GHC.GhcMonad m => FilePath -> m GHC.DynFlags
initDynFlags file = do
dflags0 <- GHC.getSessionDynFlags
@@ -296,13 +301,22 @@ initDynFlags file = do
(dflags1, _, _) <- GHC.parseDynamicFilePragma dflags0 src_opts
-- Turn this on last to avoid T10942
let dflags2 = dflags1 `GHC.gopt_set` GHC.Opt_KeepRawTokenStream
- void $ GHC.setSessionDynFlags dflags2
- return dflags2
+ -- Prevent parsing of .ghc.environment.* "package environment files"
+ (dflags3, [], []) <- GHC.parseDynamicFlagsCmdLine
+ dflags2
+ [GHC.noLoc "-hide-all-packages"]
+ _ <- GHC.setSessionDynFlags dflags3
+ return dflags3
-- | Requires GhcMonad constraint because there is
-- no pure variant of `parseDynamicFilePragma`. Yet, in constrast to
-- `initDynFlags`, it does not (try to) read the file at filepath, but
-- solely depends on the module source in the input string.
+--
+-- Passes "-hide-all-packages" to the GHC API to prevent parsing of
+-- package environment files. However this only works if there is no
+-- invocation of `setSessionDynFlags` before calling `initDynFlagsPure`.
+-- See ghc tickets #15513, #15541.
initDynFlagsPure :: GHC.GhcMonad m => FilePath -> String -> m GHC.DynFlags
initDynFlagsPure fp s = do
-- I was told we could get away with using the unsafeGlobalDynFlags.
@@ -313,8 +327,12 @@ initDynFlagsPure fp s = do
(dflags1, _, _) <- GHC.parseDynamicFilePragma dflags0 pragmaInfo
-- Turn this on last to avoid T10942
let dflags2 = dflags1 `GHC.gopt_set` GHC.Opt_KeepRawTokenStream
- void $ GHC.setSessionDynFlags dflags2
- return dflags2
+ -- Prevent parsing of .ghc.environment.* "package environment files"
+ (dflags3, [], []) <- GHC.parseDynamicFlagsCmdLine
+ dflags2
+ [GHC.noLoc "-hide-all-packages"]
+ _ <- GHC.setSessionDynFlags dflags3
+ return dflags3
-- ---------------------------------------------------------------------