Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow user to set the cabal flags

  • Loading branch information...
commit 3a763c0be74ada051a3da0d0663ca82ed6a39460 1 parent ae327b3
@JPMoresmau authored
View
23 lib/Scion/Cabal.hs
@@ -13,7 +13,7 @@
module Scion.Cabal
( CabalComponent(..), CabalPackage(..),
scionDistDir, cabalProjectComponents, cabalParse, cabalParseArbitrary, cabalDependencies,
- cabalConfigurations, preprocessPackage, dependencies )
+ cabalConfigurations, preprocessPackage, dependencies, cabalClean )
where
import Scion.Types
@@ -36,7 +36,7 @@ import Data.List ( intercalate,sortBy,partition )
import Data.Maybe
import qualified Data.Map as DM
import System.Directory ( doesFileExist, getDirectoryContents,
- getModificationTime )
+ getModificationTime, removeFile )
import System.FilePath ( (</>), dropFileName, takeExtension,dropExtension,(<.>) )
import System.Exit ( ExitCode(..) )
@@ -124,6 +124,15 @@ cabalComponentInit c = do
Left err-> Just err
Right _ ->Nothing
+cabalClean :: FilePath -> ScionM ()
+cabalClean cabal_file = do
+ ok <- liftIO $ doesFileExist cabal_file
+ when ok (do
+ let root_dir = dropFileName cabal_file
+ let setup_config = localBuildInfoFile (root_dir </> scionDistDir)
+ liftIO $ removeFile setup_config
+ )
+
cabalInit :: FilePath -> ScionM (Either String LocalBuildInfo)
cabalInit cabal_file = do
ok <- liftIO $ doesFileExist cabal_file
@@ -151,7 +160,7 @@ cabalInit cabal_file = do
return $ Right _lbi
where
do_configure root_dir = do
- r <- gtry $ configureCabalProject root_dir scionDistDir []
+ r <- gtry $ configureCabalProject root_dir scionDistDir
case r of
Left (err :: IOException) -> return (Left (show err))
Right lbi -> return $ Right lbi
@@ -428,22 +437,22 @@ configureCabalProject ::
FilePath -- ^ The project root. (Where the .cabal file resides)
-> FilePath -- ^ dist dir, i.e., directory where to put generated
-- files.
- -> [String] -- ^ command line arguments to "configure". [XXX:
- -- currently ignored!]
-> ScionM (LocalBuildInfo)
-configureCabalProject root_dir dist_dir _extra_args = do
+configureCabalProject root_dir dist_dir = do
cabal_file <- find_cabal_file
gen_pkg_descr <- liftIO $ readPackageDescription V.normal cabal_file
let prog_conf =
userSpecifyPaths [("ghc", ghc), ("ghc-pkg", ghc_pkg)]
defaultProgramConfiguration
+ user_flags <- getSessionSelector userFlags
let config_flags =
(defaultConfigFlags prog_conf)
{ configDistPref = Flag dist_dir
, configVerbosity = Flag V.deafening
, configUserInstall = Flag True
- -- TODO: parse flags properly
+ , configConfigurationsFlags = map (\(n,v)->(PD.FlagName n,v)) user_flags
}
+
setWorkingDir root_dir
ghandle (\(e :: IOError) ->
liftIO $ throwIO $
View
7 lib/Scion/Types.hs
@@ -94,13 +94,16 @@ data SessionState
-- state of a module so that we have something to give the user; GHC is very unforgiving
-- if a module doesn't parse or typecheck correctly.
- client :: String
+ client :: String,
-- ^ can be set by the client. Only used by vim to enable special hack
+
+ userFlags :: [(String,Bool)]
+ -- ^ special assignment of Cabal flags, may influence which components are buildable, etc...
}
mkSessionState :: DynFlags -> IO (IORef SessionState)
mkSessionState dflags =
- newIORef (SessionState normal dflags Nothing Nothing mempty Nothing Nothing mempty emptyModuleCache "")
+ newIORef (SessionState normal dflags Nothing Nothing mempty Nothing Nothing mempty emptyModuleCache "" mempty)
newtype ScionM a
= ScionM { unScionM :: IORef SessionState -> Ghc a }
View
9 server/Scion/Server/Commands.hs
@@ -191,6 +191,7 @@ allCommands =
, cmdCompletionVarIds
, cmdCompletionClassTypeNames
, cmdOccurrences
+ , cmdSetUserFlags
]
------------------------------------------------------------------------------
@@ -646,6 +647,14 @@ cmdOccurrences =
projectRootDir
>>= (\rootDir -> occurrences rootDir contents query literate)
+cmdSetUserFlags :: Cmd
+cmdSetUserFlags =
+ Cmd "set-user-flags" $ reqArg "user-flags" <&> reqArg' "cabal-file" S.toString $ cmd
+ where cmd user_flags cabal_file= do
+ modifySessionState $ \sess ->
+ sess { userFlags = user_flags }
+ cabalClean cabal_file
+
cmdTokenTypes :: Cmd
cmdTokenTypes =
Please sign in to comment.
Something went wrong with that request. Please try again.