Preserve cabal flags when reconfiguring project
This commit is contained in:
parent
2549bba7b8
commit
19b3de3569
@ -172,13 +172,16 @@ withCabal action = do
|
|||||||
mCabalConfig <- liftIO $ timeMaybe (setupConfigFile crdl)
|
mCabalConfig <- liftIO $ timeMaybe (setupConfigFile crdl)
|
||||||
mCabalSandboxConfig <- liftIO $ timeMaybe (sandboxConfigFile crdl)
|
mCabalSandboxConfig <- liftIO $ timeMaybe (sandboxConfigFile crdl)
|
||||||
|
|
||||||
|
let haveSetupConfig = isJust mCabalConfig
|
||||||
|
|
||||||
cusPkgDb <- getCustomPkgDbStack
|
cusPkgDb <- getCustomPkgDbStack
|
||||||
pkgDbStackOutOfSync <- do
|
(flgs, pkgDbStackOutOfSync) <- do
|
||||||
if isJust mCabalConfig
|
if haveSetupConfig
|
||||||
then runCHQuery $ do
|
then runCHQuery $ do
|
||||||
|
flgs <- nonDefaultConfigFlags
|
||||||
pkgDb <- map chPkgToGhcPkg <$> packageDbStack
|
pkgDb <- map chPkgToGhcPkg <$> packageDbStack
|
||||||
return $ fromMaybe False $ (pkgDb /=) <$> cusPkgDb
|
return (flgs, fromMaybe False $ (pkgDb /=) <$> cusPkgDb)
|
||||||
else return False
|
else return ([], False)
|
||||||
|
|
||||||
when (isSetupConfigOutOfDate mCabalFile mCabalConfig) $
|
when (isSetupConfigOutOfDate mCabalFile mCabalConfig) $
|
||||||
gmLog GmDebug "" $ strDoc $ "setup configuration is out of date"
|
gmLog GmDebug "" $ strDoc $ "setup configuration is out of date"
|
||||||
@ -197,9 +200,16 @@ withCabal action = do
|
|||||||
case proj of
|
case proj of
|
||||||
CabalProject -> do
|
CabalProject -> do
|
||||||
gmLog GmDebug "" $ strDoc "reconfiguring Cabal project"
|
gmLog GmDebug "" $ strDoc "reconfiguring Cabal project"
|
||||||
cabalReconfigure (optPrograms opts) crdl
|
cabalReconfigure (optPrograms opts) crdl flgs
|
||||||
StackProject {} -> do
|
StackProject {} -> do
|
||||||
gmLog GmDebug "" $ strDoc "reconfiguring Stack project"
|
gmLog GmDebug "" $ strDoc "reconfiguring Stack project"
|
||||||
|
-- TODO: we could support flags for stack too, but it seems
|
||||||
|
-- you're supposed to put those in stack.yaml so detecting which
|
||||||
|
-- flags to pass down would be more difficult
|
||||||
|
|
||||||
|
-- "--flag PACKAGE:[-]FLAG Override flags set in stack.yaml
|
||||||
|
-- (applies to local packages and extra-deps)"
|
||||||
|
|
||||||
stackReconfigure crdl (optPrograms opts)
|
stackReconfigure crdl (optPrograms opts)
|
||||||
_ ->
|
_ ->
|
||||||
error $ "withCabal: unsupported project type: " ++ show proj
|
error $ "withCabal: unsupported project type: " ++ show proj
|
||||||
@ -207,7 +217,7 @@ withCabal action = do
|
|||||||
action
|
action
|
||||||
|
|
||||||
where
|
where
|
||||||
cabalReconfigure progs crdl = do
|
cabalReconfigure progs crdl flgs = do
|
||||||
readProc <- gmReadProcess
|
readProc <- gmReadProcess
|
||||||
withDirectory_ (cradleRootDir crdl) $ do
|
withDirectory_ (cradleRootDir crdl) $ do
|
||||||
cusPkgStack <- maybe [] ((PackageDb "clear"):) <$> getCustomPkgDbStack
|
cusPkgStack <- maybe [] ((PackageDb "clear"):) <$> getCustomPkgDbStack
|
||||||
@ -219,8 +229,13 @@ withCabal action = do
|
|||||||
then [ "--with-ghc-pkg=" ++ T.ghcPkgProgram progs ]
|
then [ "--with-ghc-pkg=" ++ T.ghcPkgProgram progs ]
|
||||||
else []
|
else []
|
||||||
++ map pkgDbArg cusPkgStack
|
++ map pkgDbArg cusPkgStack
|
||||||
liftIO $ void $ readProc (T.cabalProgram progs) ("configure":progOpts) ""
|
++ flagOpt
|
||||||
|
|
||||||
|
toFlag (f, True) = f
|
||||||
|
toFlag (f, False) = '-':f
|
||||||
|
flagOpt = ["--flags", unwords $ map toFlag flgs]
|
||||||
|
|
||||||
|
liftIO $ void $ readProc (T.cabalProgram progs) ("configure":progOpts) ""
|
||||||
stackReconfigure crdl progs = do
|
stackReconfigure crdl progs = do
|
||||||
withDirectory_ (cradleRootDir crdl) $ do
|
withDirectory_ (cradleRootDir crdl) $ do
|
||||||
supported <- haveStackSupport
|
supported <- haveStackSupport
|
||||||
|
@ -70,12 +70,25 @@ spec = do
|
|||||||
pkgs = pkgOptions ghcOpts
|
pkgs = pkgOptions ghcOpts
|
||||||
pkgs `shouldBe` ["Cabal","base","template-haskell"]
|
pkgs `shouldBe` ["Cabal","base","template-haskell"]
|
||||||
|
|
||||||
it "uses non default flags" $ do
|
it "uses non default flags and preserves them across reconfigures" $ do
|
||||||
let tdir = "test/data/cabal-flags"
|
let tdir = "test/data/cabal-flags"
|
||||||
_ <- withDirectory_ tdir $
|
_ <- withDirectory_ tdir $
|
||||||
readProcess "cabal" ["configure", "-ftest-flag"] ""
|
readProcess "cabal" ["configure", "-ftest-flag"] ""
|
||||||
|
|
||||||
|
let test = do
|
||||||
opts <- map gmcGhcOpts <$> runD' tdir getComponents
|
opts <- map gmcGhcOpts <$> runD' tdir getComponents
|
||||||
let ghcOpts = head opts
|
let ghcOpts = head opts
|
||||||
pkgs = pkgOptions ghcOpts
|
pkgs = pkgOptions ghcOpts
|
||||||
pkgs `shouldBe` ["Cabal","base"]
|
pkgs `shouldBe` ["Cabal","base"]
|
||||||
|
|
||||||
|
test
|
||||||
|
|
||||||
|
touch $ tdir </> "cabal-flags.cabal"
|
||||||
|
|
||||||
|
test
|
||||||
|
|
||||||
|
touch :: FilePath -> IO ()
|
||||||
|
touch fn = do
|
||||||
|
f <- readFile fn
|
||||||
|
writeFile (fn <.> "tmp") f
|
||||||
|
renameFile (fn <.> "tmp") fn
|
||||||
|
Loading…
Reference in New Issue
Block a user