@@ -398,7 +398,7 @@ runGhci GhciOpts{..} targets mainIsTargets pkgs extraFiles exposePackages = do
398
398
scriptPath <- writeGhciScript tmpDirectory (renderScript isIntero pkgs mainFile ghciOnlyMain extraFiles)
399
399
execGhci (macrosOptions ++ [" -ghci-script=" <> toFilePath scriptPath])
400
400
401
- writeMacrosFile :: ( MonadIO m ) => Path Abs Dir -> [GhciPkgInfo ] -> m [String ]
401
+ writeMacrosFile :: HasRunner env => Path Abs Dir -> [GhciPkgInfo ] -> RIO env [String ]
402
402
writeMacrosFile tmpDirectory packages = do
403
403
preprocessCabalMacros packages macrosFile
404
404
where
@@ -807,12 +807,21 @@ getExtraLoadDeps loadAllDeps sourceMap targets =
807
807
(_, Just PSIndex {}) -> return loadAllDeps
808
808
(_, _) -> return False
809
809
810
- preprocessCabalMacros :: MonadIO m => [GhciPkgInfo ] -> Path Abs File -> m [String ]
811
- preprocessCabalMacros pkgs out = liftIO $ do
812
- let fps = nubOrd (concatMap (mapMaybe (bioCabalMacros . snd ) . ghciPkgOpts) pkgs)
813
- files <- mapM (S8. readFile . toFilePath) fps
810
+ preprocessCabalMacros :: HasRunner env => [GhciPkgInfo ] -> Path Abs File -> RIO env [String ]
811
+ preprocessCabalMacros pkgs out = do
812
+ fps <- fmap (nubOrd . catMaybes . concat ) $
813
+ forM pkgs $ \ pkg -> forM (ghciPkgOpts pkg) $ \ (_, bio) -> do
814
+ let cabalMacros = bioCabalMacros bio
815
+ exists <- liftIO $ doesFileExist cabalMacros
816
+ if exists
817
+ then return $ Just cabalMacros
818
+ else do
819
+ prettyWarnL [" Didn't find expected autogen file:" , display cabalMacros]
820
+ return Nothing
821
+ files <- liftIO $ mapM (S8. readFile . toFilePath) fps
814
822
if null files then return [] else do
815
- S8. writeFile (toFilePath out) $ S8. concat $ map (<> " \n #undef CURRENT_PACKAGE_KEY\n #undef CURRENT_COMPONENT_ID\n " ) files
823
+ liftIO $ S8. writeFile (toFilePath out) $ S8. concat $
824
+ map (<> " \n #undef CURRENT_PACKAGE_KEY\n #undef CURRENT_COMPONENT_ID\n " ) files
816
825
return [" -optP-include" , " -optP" <> toFilePath out]
817
826
818
827
setScriptPerms :: MonadIO m => FilePath -> m ()
@@ -844,47 +853,3 @@ hasLocalComp p t =
844
853
TargetComps s -> any p (S. toList s)
845
854
TargetAll ProjectPackage -> True
846
855
_ -> False
847
-
848
-
849
- {- Copied from Stack.Ide, may be useful in the future
850
-
851
- -- | Get options and target files for the given package info.
852
- getPackageOptsAndTargetFiles
853
- :: (MonadThrow m, MonadIO m, MonadReader env m, HasEnvConfig env)
854
- => Path Abs Dir -> GhciPkgInfo -> m ([FilePath], [FilePath])
855
- getPackageOptsAndTargetFiles pwd pkg = do
856
- dist <- distDirFromDir (ghciPkgDir pkg)
857
- let autogen = autogenDir dist
858
- paths_foo <-
859
- liftM
860
- (autogen </>)
861
- (parseRelFile
862
- ("Paths_" ++ packageNameString (ghciPkgName pkg) ++ ".hs"))
863
- paths_foo_exists <- doesFileExist paths_foo
864
- let ghcOptions bio =
865
- bioOneWordOpts bio ++
866
- bioOpts bio ++
867
- bioPackageFlags bio ++
868
- maybe [] (\cabalMacros -> ["-optP-include", "-optP" <> toFilePath cabalMacros]) (bioCabalMacros bio)
869
- return
870
- ( ("--dist-dir=" <> toFilePathNoTrailingSep dist) :
871
- -- FIXME: use compilerOptionsCabalFlag
872
- map ("--ghc-option=" ++) (concatMap (ghcOptions . snd) (ghciPkgOpts pkg))
873
- , mapMaybe
874
- (fmap toFilePath . stripProperPrefix pwd)
875
- (S.toList (ghciPkgCFiles pkg) <> S.toList (ghciPkgModFiles pkg) <>
876
- [paths_foo | paths_foo_exists]))
877
-
878
- -- | List load targets for a package target.
879
- targetsCmd :: Text -> GlobalOpts -> IO ()
880
- targetsCmd target go@GlobalOpts{..} =
881
- withBuildConfig go $
882
- do let boptsCli = defaultBuildOptsCLI { boptsCLITargets = [target] }
883
- (_realTargets,_,pkgs) <- ghciSetup (ideGhciOpts boptsCli)
884
- pwd <- getCurrentDir
885
- targets <-
886
- fmap
887
- (concat . snd . unzip)
888
- (mapM (getPackageOptsAndTargetFiles pwd) pkgs)
889
- forM_ targets (liftIO . putStrLn)
890
- -}
0 commit comments