Skip to content

Commit

Permalink
Merge pull request #1143 from sebastianpoeplau/master
Browse files Browse the repository at this point in the history
Consider user-specified package flags in stack solver #1071
  • Loading branch information
snoyberg committed Oct 12, 2015
2 parents f3e478a + 232198c commit 3c7e588
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ getDefaultResolver cabalfps gpds initOpts =
return (ResolverSnapshot snap, flags, Map.empty)
Nothing -> return (resolver, Map.empty, Map.empty)
MethodSolver -> do
(compilerVersion, extraDeps) <- cabalSolver Ghc (map parent cabalfps) Map.empty []
(compilerVersion, extraDeps) <- cabalSolver Ghc (map parent cabalfps) Map.empty Map.empty []
return
( ResolverCompiler compilerVersion
, Map.filter (not . Map.null) $ fmap snd extraDeps
Expand Down
12 changes: 11 additions & 1 deletion src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ cabalSolver :: (MonadIO m, MonadLogger m, MonadMask m, MonadBaseControl IO m, Mo
=> WhichCompiler
-> [Path Abs Dir] -- ^ cabal files
-> Map PackageName Version -- ^ constraints
-> Map PackageName (Map FlagName Bool) -- ^ user-specified flags
-> [String] -- ^ additional arguments
-> m (CompilerVersion, Map PackageName (Version, Map FlagName Bool))
cabalSolver wc cabalfps constraints cabalArgs = withSystemTempDirectory "cabal-solver" $ \dir -> do
cabalSolver wc cabalfps constraints userFlags cabalArgs = withSystemTempDirectory "cabal-solver" $ \dir -> do
configLines <- getCabalConfig dir constraints
let configFile = dir FP.</> "cabal.config"
liftIO $ S.writeFile configFile $ encodeUtf8 $ T.unlines configLines
Expand Down Expand Up @@ -96,6 +97,7 @@ cabalSolver wc cabalfps constraints cabalArgs = withSystemTempDirectory "cabal-s
: "--package-db=clear"
: "--package-db=global"
: cabalArgs ++
toConstraintArgs userFlags ++
(map toFilePath cabalfps) ++
["--ghcjs" | wc == Ghcjs]

Expand Down Expand Up @@ -132,6 +134,13 @@ cabalSolver wc cabalfps constraints cabalArgs = withSystemTempDirectory "cabal-s
Nothing -> (t0, True)
Just x -> (x, True)
Just x -> (x, False)
toConstraintArgs userFlagMap =
[formatFlagConstraint package flag enabled | (package, fs) <- Map.toList userFlagMap
, (flag, enabled) <- Map.toList fs]
formatFlagConstraint package flag enabled =
let sign = if enabled then '+' else '-'
in
"--constraint=" ++ unwords [packageNameString package, sign : flagNameString flag]

getCabalConfig :: (MonadReader env m, HasConfig env, MonadIO m, MonadThrow m)
=> FilePath -- ^ temp dir
Expand Down Expand Up @@ -189,6 +198,7 @@ solveExtraDeps modStackYaml = do
wc
(Map.keys $ envConfigPackages econfig)
packages
(bcFlags bconfig)
[]

let newDeps = extraDeps `Map.difference` packages
Expand Down

0 comments on commit 3c7e588

Please sign in to comment.