diff --git a/ChangeLog.md b/ChangeLog.md index ab19a94305..e37b93347d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/src/Stack/Build/Source.hs b/src/Stack/Build/Source.hs index 1b7cb5692d..139c2be4cb 100644 --- a/src/Stack/Build/Source.hs +++ b/src/Stack/Build/Source.hs @@ -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 @@ -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 diff --git a/test/integration/tests/366-non-root-dir/Main.hs b/test/integration/tests/366-non-root-dir/Main.hs new file mode 100644 index 0000000000..1855418810 --- /dev/null +++ b/test/integration/tests/366-non-root-dir/Main.hs @@ -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"] diff --git a/test/integration/tests/366-non-root-dir/files/app/Main.hs b/test/integration/tests/366-non-root-dir/files/app/Main.hs new file mode 100644 index 0000000000..377b6b5516 --- /dev/null +++ b/test/integration/tests/366-non-root-dir/files/app/Main.hs @@ -0,0 +1,2 @@ +main :: IO () +main = return () diff --git a/test/integration/tests/366-non-root-dir/files/new-template.cabal b/test/integration/tests/366-non-root-dir/files/new-template.cabal new file mode 100644 index 0000000000..1ce3458647 --- /dev/null +++ b/test/integration/tests/366-non-root-dir/files/new-template.cabal @@ -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 diff --git a/test/integration/tests/366-non-root-dir/files/stack.yaml b/test/integration/tests/366-non-root-dir/files/stack.yaml new file mode 100644 index 0000000000..6252712e3b --- /dev/null +++ b/test/integration/tests/366-non-root-dir/files/stack.yaml @@ -0,0 +1,5 @@ +flags: {} +packages: +- '.' +extra-deps: [] +resolver: lts-2.17