Skip to content
This repository has been archived by the owner on Mar 4, 2023. It is now read-only.

Commit

Permalink
Implement cabalSessionConfigs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nominolo committed May 4, 2011
1 parent f1a391d commit 80de510
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/Scion/Cabal.hs
Expand Up @@ -34,7 +34,7 @@ import GHC.Paths ( ghc, ghc_pkg )
import System.Directory
import System.Exit ( ExitCode(..) )
import System.FilePath ( (</>), dropFileName, takeExtension,
dropExtension,(<.>) )
dropExtension,(<.>), takeBaseName )

-- | Something went wrong inside Cabal.
data CabalException = CabalException String
Expand Down Expand Up @@ -126,7 +126,7 @@ availableComponents pd =
[ Executable (PD.exeName e)
| e <- PD.executables pd ]

-- | List all possible components of the given file.
-- | List all possible components of the @.cabal@ given file.
--
-- Some components might not be available depending on the way the
-- program is configured.
Expand All @@ -138,8 +138,21 @@ fileComponents cabal_file = do
gpd <- io $ PD.readPackageDescription V.silent cabal_file
return (availableComponents (PD.flattenPackageDescription gpd))

-- | List all possible default session configs
-- | List all possible default session configs from a given @.cabal@ file.
cabalSessionConfigs :: (ExceptionMonad m, MonadIO m) => FilePath
-> m [SessionConfig]
cabalSessionConfigs cabal_file = do
return []
comps <- fileComponents cabal_file
return (map componentToSessionConfig comps)
where
componentToSessionConfig comp =
CabalConfig{ sc_name = nameFromComponent comp
, sc_cabalFile = cabal_file
, sc_component = comp
, sc_configFlags = []
}
library_name = takeBaseName cabal_file

nameFromComponent Library = library_name
nameFromComponent (Executable exe_name) =
library_name ++ ":" ++ exe_name
2 changes: 1 addition & 1 deletion src/Scion/Types/Session.hs
Expand Up @@ -96,7 +96,7 @@ data SessionConfig =
-- | A configuration with no files.
EmptyConfig
{ sc_flags :: [String] }
deriving (Show)
deriving (Eq, Show)

-- | The @SessionState@ contains the cached part of a worker's state.
data SessionState = SessionState
Expand Down
4 changes: 4 additions & 0 deletions test/TestSuite.hs
Expand Up @@ -53,6 +53,10 @@ tests =
comps <- ignoreMostErrors $ fileComponents ("./foobar.blab")
io $ comps @?= Nothing,

testCase "cabal03" $ runScion $ do
confs <- cabalSessionConfigs (cabal_file001 ".")
io $ map sc_name confs @?= ["hello:hello"],

testCase "cabal10" $ runScion $ do
withSession (cabal_config001 ".") $ \sid -> do
notes <- sessionNotes sid
Expand Down

0 comments on commit 80de510

Please sign in to comment.