Skip to content

Commit

Permalink
Place cabal constraints in config file, not args #723
Browse files Browse the repository at this point in the history
It seems that, on Windows, the large number of arguments causes the process
package to give the incredibly misleading error message:

C:\Users\chris\AppData\Roaming\local\bin\cabal.exe: streamingProcess: does not exist (No such file or directory)

This workaround isn't just a hack, but a good thing: putting constraints in the
config file is an improvement in general, so I'm happy to keep it. Nonetheless,
this is something that should be fixed at the process package level.
  • Loading branch information
snoyberg committed Aug 6, 2015
1 parent 551a9ee commit 881023e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ getDefaultResolver cabalfps gpds initOpts =
return (ResolverSnapshot snap, flags, Map.empty)
Nothing -> return (resolver, Map.empty, Map.empty)
MethodSolver -> do
(ghcVersion, extraDeps) <- cabalSolver (map parent cabalfps) []
(ghcVersion, extraDeps) <- cabalSolver (map parent cabalfps) Map.empty []
return
( ResolverGhc ghcVersion
, Map.filter (not . Map.null) $ fmap snd extraDeps
Expand Down
31 changes: 17 additions & 14 deletions src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ import System.Directory (copyFile,
getTemporaryDirectory)
import qualified System.FilePath as FP
import System.IO.Temp
import System.Process (rawSystem)
import System.Process.Read

cabalSolver :: (MonadIO m, MonadLogger m, MonadMask m, MonadBaseControl IO m, MonadReader env m, HasConfig env)
=> [Path Abs Dir] -- ^ cabal files
-> [String] -- ^ additional arguments, usually constraints
-> Map PackageName Version -- ^ constraints
-> [String] -- ^ additional arguments
-> m (MajorVersion, Map PackageName (Version, Map FlagName Bool))
cabalSolver cabalfps cabalArgs = withSystemTempDirectory "cabal-solver" $ \dir -> do
configLines <- getCabalConfig dir
cabalSolver cabalfps constraints 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 @@ -115,12 +117,13 @@ getGhcMajorVersion menv = do

getCabalConfig :: (MonadReader env m, HasConfig env, MonadIO m, MonadThrow m)
=> FilePath -- ^ temp dir
-> Map PackageName Version -- ^ constraints
-> m [Text]
getCabalConfig dir = do
getCabalConfig dir constraints = do
indices <- asks $ configPackageIndices . getConfig
remotes <- mapM goIndex indices
let cache = T.pack $ "remote-repo-cache: " ++ dir
return $ cache : remotes
return $ cache : remotes ++ map goConstraint (Map.toList constraints)
where
goIndex index = do
src <- configPackageIndex $ indexName index
Expand All @@ -135,6 +138,13 @@ getCabalConfig dir = do
, ":http://0.0.0.0/fake-url"
]

goConstraint (name, version) = T.concat
[ "constraint: "
, T.pack $ packageNameString name
, "=="
, T.pack $ versionString version
]

-- | Determine missing extra-deps
solveExtraDeps :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadMask m, MonadLogger m, MonadBaseControl IO m, HasHttpManager env)
=> Bool -- ^ modify stack.yaml?
Expand All @@ -155,18 +165,11 @@ solveExtraDeps modStackYaml = do
let packages = Map.union
(bcExtraDeps bconfig)
(fmap mpiVersion snapshot)
constraints = map
(\(k, v) -> concat
[ "--constraint="
, packageNameString k
, "=="
, versionString v
])
(Map.toList packages)

(_ghc, extraDeps) <- cabalSolver
(Map.keys $ envConfigPackages econfig)
constraints
packages
[]

let newDeps = extraDeps `Map.difference` packages
newFlags = Map.filter (not . Map.null) $ fmap snd newDeps
Expand Down

0 comments on commit 881023e

Please # to comment.