Skip to content

Commit

Permalink
Targets outside of root dir don't build (fixes #366)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jul 7, 2015
1 parent facd185 commit 8fc9378
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Set the `HASKELL_DIST_DIR` environment variable [#524](https://github.com/commercialhaskell/stack/pull/524)
* Track build status of tests and benchmarks [#525](https://github.com/commercialhaskell/stack/issues/525)
* `--no-run-tests` [#517](https://github.com/commercialhaskell/stack/pull/517)
* Targets outside of root dir don't build [#366](https://github.com/commercialhaskell/stack/issues/366)

## 0.1.2.0

Expand Down
22 changes: 12 additions & 10 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,18 @@ loadLocals :: forall m env .
-> Map PackageName Version
-> m ([LocalPackage], Set PackageName, Set PackageIdentifier)
loadLocals bopts latestVersion = do
targets <- mapM parseTarget $
(isWanted', names, idents) <-
case boptsTargets bopts of
[] -> ["."]
x -> x

-- Group targets by their kind
(dirs, names, idents) <-
case partitionEithers targets of
([], targets') -> return $ partitionTargetSpecs targets'
(bad, _) -> throwM $ Couldn'tParseTargets bad
-- If there are no targets specified: build all locals
[] -> return (\_ _ -> True, Map.empty, Set.empty)
targets -> do
targets' <- mapM parseTarget $ boptsTargets bopts
-- Group targets by their kind
(dirs, names, idents) <-
case partitionEithers targets' of
([], targets') -> return $ partitionTargetSpecs targets'
(bad, _) -> throwM $ Couldn'tParseTargets bad
return (isWanted dirs names, names, idents)

econfig <- asks getEnvConfig
bconfig <- asks getBuildConfig
Expand All @@ -191,7 +193,7 @@ loadLocals bopts latestVersion = do
lps <- forM (Map.toList $ bcPackages bconfig) $ \(dir, validWanted) -> do
cabalfp <- getCabalFileName dir
name <- parsePackageNameFromFilePath cabalfp
let wanted = validWanted && isWanted dirs names dir name
let wanted = validWanted && isWanted' dir name
config = PackageConfig
{ packageConfigEnableTests = False
, packageConfigEnableBenchmarks = False
Expand Down
9 changes: 9 additions & 0 deletions test/integration/tests/366-non-root-dir/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import StackTest
import System.Directory

main :: IO ()
main = do
stackErr ["exec", "hello-world"]
setCurrentDirectory "app"
stack ["build"]
stack ["exec", "hello-world"]
2 changes: 2 additions & 0 deletions test/integration/tests/366-non-root-dir/files/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = return ()
11 changes: 11 additions & 0 deletions test/integration/tests/366-non-root-dir/files/new-template.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: new-template
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10

executable hello-world
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
default-language: Haskell2010
5 changes: 5 additions & 0 deletions test/integration/tests/366-non-root-dir/files/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flags: {}
packages:
- '.'
extra-deps: []
resolver: lts-2.17

0 comments on commit 8fc9378

Please sign in to comment.