Skip to content

Commit

Permalink
Local projects used for deps in stack init (fixes #384)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jun 24, 2015
1 parent b09cd42 commit 06dd391
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Specifying flags for multiple packages [#335](https://github.com/commercialhaskell/stack/issues/335)
* single test suite failure should show entire log [#388](https://github.com/commercialhaskell/stack/issues/388)
* valid-wanted is a confusing option name [#386](https://github.com/commercialhaskell/stack/issues/386)
* stack init in multi-package project should use local packages for dependency checking [#384](https://github.com/commercialhaskell/stack/issues/384)

## 0.1.0.0

Expand Down
19 changes: 13 additions & 6 deletions src/Stack/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,18 @@ loadBuildPlan name = do
-- only modify non-manual flags, and will prefer default values for flags.
-- Returns @Nothing@ if no combination exists.
checkBuildPlan :: (MonadLogger m, MonadThrow m, MonadIO m, MonadReader env m, HasConfig env, MonadCatch m)
=> MiniBuildPlan
=> Map PackageName Version -- ^ locally available packages
-> MiniBuildPlan
-> GenericPackageDescription
-> m (Maybe (Map FlagName Bool))
checkBuildPlan mbp gpd = do
checkBuildPlan locals mbp gpd = do
platform <- asks (configPlatform . getConfig)
loop platform flagOptions
where
packages = Map.union locals $ fmap mpiVersion $ mbpPackages mbp
loop _ [] = return Nothing
loop platform (flags:rest) = do
passes <- checkDeps flags (packageDeps pkg) (mbpPackages mbp)
passes <- checkDeps flags (packageDeps pkg) packages
if passes
then return $ Just flags
else loop platform rest
Expand Down Expand Up @@ -523,7 +525,7 @@ checkBuildPlan mbp gpd = do
checkDeps :: MonadLogger m
=> Map FlagName Bool -- ^ used only for debugging purposes
-> Map PackageName VersionRange
-> Map PackageName MiniPackageInfo
-> Map PackageName Version
-> m Bool
checkDeps flags deps packages = do
let errs = mapMaybe go $ Map.toList deps
Expand All @@ -536,7 +538,7 @@ checkDeps flags deps packages = do
where
go :: (PackageName, VersionRange) -> Maybe Text
go (name, range) =
case fmap mpiVersion $ Map.lookup name packages of
case Map.lookup name packages of
Nothing -> Just $ "Package not present: " <> packageNameText name
Just v
| withinRange v range -> Nothing
Expand Down Expand Up @@ -565,7 +567,7 @@ findBuildPlan gpds0 =
checkGPDs flags (gpd:gpds) = do
let C.PackageIdentifier pname' _ = C.package $ C.packageDescription gpd
pname = fromCabalPackageName pname'
mflags <- checkBuildPlan mbp gpd
mflags <- checkBuildPlan localNames mbp gpd
case mflags of
Nothing -> loop names'
Just flags' -> checkGPDs
Expand All @@ -575,6 +577,11 @@ findBuildPlan gpds0 =
gpds
checkGPDs Map.empty gpds0

localNames = Map.fromList $ map (fromCabalIdent . C.package . C.packageDescription) gpds0

fromCabalIdent (C.PackageIdentifier name version) =
(fromCabalPackageName name, fromCabalVersion version)

shadowMiniBuildPlan :: MiniBuildPlan
-> Set PackageName
-> (MiniBuildPlan, Map PackageName MiniPackageInfo)
Expand Down
6 changes: 6 additions & 0 deletions test/integration/tests/384-local-deps/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import StackTest

main :: IO ()
main = do
stack ["init"]
stack ["test"]
10 changes: 10 additions & 0 deletions test/integration/tests/384-local-deps/files/dir1/dir1.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: dir1
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10

library
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.7 && < 5
default-language: Haskell2010
6 changes: 6 additions & 0 deletions test/integration/tests/384-local-deps/files/dir1/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Lib
( someFunc
) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
10 changes: 10 additions & 0 deletions test/integration/tests/384-local-deps/files/dir2/dir2.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: dir2
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10

library
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.7 && < 5, dir1
default-language: Haskell2010
6 changes: 6 additions & 0 deletions test/integration/tests/384-local-deps/files/dir2/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Lib
( someFunc
) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"

0 comments on commit 06dd391

Please sign in to comment.