setCabalPerFileOpts :: (Proxy p) => FilePath -> Producer (StateP Options (ReaderP Settings p)) ClientDirective GHC.Ghc ()
setCabalPerFileOpts configPath = cabalCached configPath $ do
  file <- fmap GHC.unpackFS $ liftP $ readRef refFileName
  cabalDir <- lift $ GHC.liftIO $ canonicalizePath $ takeDirectory configPath
  fileRel <- lift $ GHC.liftIO $ makeRelative cabalDir <$> canonicalizePath file
  respond $ ClientLog "CabalFileOpts" $ "Loading cabal (looking for file: " ++ fileRel ++ ")"
  config <- lift $ GHC.liftIO $ readFile configPath
  case parseCabalConfig config of
    (ParseFailed err) -> do
      respond $ ClientLog "CabalFileOpts" $ "Cabal error:" ++ show err
      respond $ ClientStderr "Warning: Parsing of the cabal config failed. Please correct it, or use --no-cabal."
    (ParseOk _ pkgDesc) -> do
      let srcInclude = "-i" ++ takeDirectory file
      respond $ ClientLog "CabalFileOpts" $ "build infos: " ++ show (reallyAllBuildInfo pkgDesc)
      flags <- case findBuildInfoFile pkgDesc fileRel of
        Left err -> do
          respond $ ClientLog "CabalFileOpts" $ "Couldn't find file: " ++ err
          return []
        Right buildInfo -> do
          let opts = getBuildInfoOptions buildInfo
          respond $ ClientLog "CabalFileOpts" $ "Cabal: Adding options " ++ show opts
          return opts
      dynFlags <- lift GHC.getSessionDynFlags
      (finalDynFlags, _, _) <- lift $ GHC.parseDynamicFlags dynFlags (map GHC.noLoc $ srcInclude : flags)
      void $ handleGHCException $ void $ GHC.setSessionDynFlags $ finalDynFlags `GHC.dopt_unset` GHC.Opt_WarnIsError
setCabalPerFileOpts :: (Proxy p) => FilePath -> Producer (StateP Options (ReaderP Settings p)) ClientDirective GHC.Ghc ()
setCabalPerFileOpts configPath = cabalCached configPath $ do
  file <- fmap GHC.unpackFS $ liftP $ readRef refFileName
  cabalDir <- lift $ GHC.liftIO $ canonicalizePath $ takeDirectory configPath
  fileRel <- lift $ GHC.liftIO $ makeRelative cabalDir <$> canonicalizePath file
  respond $ ClientLog "CabalFileOpts" $ "Loading cabal (looking for file: " ++ fileRel ++ ")"
  config <- lift $ GHC.liftIO $ readFile configPath
  case parseCabalConfig config of
    (ParseFailed err) -> do
      respond $ ClientLog "CabalFileOpts" $ "Cabal error:" ++ show err
      respond $ ClientStderr "Warning: Parsing of the cabal config failed. Please correct it, or use --no-cabal."
    (ParseOk _ pkgDesc) -> do
      let srcInclude = "-i" ++ takeDirectory file
      respond $ ClientLog "CabalFileOpts" $ "build infos: " ++ show (reallyAllBuildInfo pkgDesc)
      flags <- case findBuildInfoFile pkgDesc fileRel of
        Left err -> do
          respond $ ClientLog "CabalFileOpts" $ "Couldn't find file: " ++ err
          return []
        Right buildInfo -> do
          let opts = getBuildInfoOptions buildInfo
          respond $ ClientLog "CabalFileOpts" $ "Cabal: Adding options " ++ show opts
          return opts
      dynFlags <- lift GHC.getSessionDynFlags
      (finalDynFlags, _, _) <- lift $ GHC.parseDynamicFlags dynFlags (map GHC.noLoc $ srcInclude : flags)
      void $ handleGHCException $ void $ GHC.setSessionDynFlags $ finalDynFlags `GHC.dopt_unset` GHC.Opt_WarnIsError
setCabalPerFileOpts configPath = cabalCached configPath $ do
  file <- fmap GHC.unpackFS $ liftP $ readRef refFileName
  cabalDir <- lift $ GHC.liftIO $ canonicalizePath $ takeDirectory configPath
  fileRel <- lift $ GHC.liftIO $ makeRelative cabalDir <$> canonicalizePath file
  respond $ ClientLog "CabalFileOpts" $ "Loading cabal (looking for file: " ++ fileRel ++ ")"
  config <- lift $ GHC.liftIO $ readFile configPath
  case parseCabalConfig config of
    (ParseFailed err) -> do
      respond $ ClientLog "CabalFileOpts" $ "Cabal error:" ++ show err
      respond $ ClientStderr "Warning: Parsing of the cabal config failed. Please correct it, or use --no-cabal."
    (ParseOk _ pkgDesc) -> do
      let srcInclude = "-i" ++ takeDirectory file
      respond $ ClientLog "CabalFileOpts" $ "build infos: " ++ show (reallyAllBuildInfo pkgDesc)
      flags <- case findBuildInfoFile pkgDesc fileRel of
        Left err -> do
          respond $ ClientLog "CabalFileOpts" $ "Couldn't find file: " ++ err
          return []
        Right buildInfo -> do
          let opts = getBuildInfoOptions buildInfo
          respond $ ClientLog "CabalFileOpts" $ "Cabal: Adding options " ++ show opts
          return opts
      dynFlags <- lift GHC.getSessionDynFlags
      (finalDynFlags, _, _) <- lift $ GHC.parseDynamicFlags dynFlags (map GHC.noLoc $ srcInclude : flags)
      void $ handleGHCException $ void $ GHC.setSessionDynFlags $ finalDynFlags `GHC.dopt_unset` GHC.Opt_WarnIsError