Commit b736896a authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Only consider dependencies in closure when computing -I on hsc2hs



Previously, we unconditionally blasted in all packages, even
if our component didn't actually depend on them.
This fixes #2971.

Also, added a test T2971a which is the opposite problem; previously
we didn't bring in include-dirs from internal libraries.  That
was fixed by the previous commit.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 0d15edef
......@@ -260,6 +260,14 @@ extra-source-files:
tests/PackageTests/ReexportedModules/p/p.cabal
tests/PackageTests/ReexportedModules/q/A.hs
tests/PackageTests/ReexportedModules/q/q.cabal
tests/PackageTests/Regression/T2971/p/include/T2971test.h
tests/PackageTests/Regression/T2971/p/p.cabal
tests/PackageTests/Regression/T2971/q/Bar.hsc
tests/PackageTests/Regression/T2971/q/Foo.hs
tests/PackageTests/Regression/T2971/q/q.cabal
tests/PackageTests/Regression/T2971a/Main.hsc
tests/PackageTests/Regression/T2971a/T2971a.cabal
tests/PackageTests/Regression/T2971a/include/T2971a.h
tests/PackageTests/Regression/T3294/T3294.cabal
tests/PackageTests/Regression/T3847/Main.hs
tests/PackageTests/Regression/T3847/T3847.cabal
......
......@@ -434,13 +434,16 @@ ppHsc2hs bi lbi clbi =
++ ["-o", outFile, inFile]
}
where
-- TODO: installedPkgs contains ALL dependencies associated with
-- the package, but we really only want to look at packages for the
-- *current* dependency. We should use PackageIndex.dependencyClosure
-- on the direct depends of the component. The signature of this
-- function was recently refactored, so this should be fixable
-- now. Tracked with #2971 (which has a test case.)
pkgs = PackageIndex.topologicalOrder (packageHacks (installedPkgs lbi))
hacked_index = packageHacks (installedPkgs lbi)
-- Look only at the dependencies of the current component
-- being built! This relies on 'installedPkgs' maintaining
-- 'InstalledPackageInfo' for internal deps too; see #2971.
pkgs = PackageIndex.topologicalOrder $
case PackageIndex.dependencyClosure hacked_index
(map fst (componentPackageDeps clbi)) of
Left index' -> index'
Right inf ->
error ("ppHsc2hs: broken closure: " ++ show inf)
isOSX = case buildOS of OSX -> True; _ -> False
isELF = case buildOS of OSX -> False; Windows -> False; AIX -> False; _ -> True;
packageHacks = case compilerFlavor (compiler lbi) of
......
......@@ -60,7 +60,7 @@ whitelistedFiles = [ "ghc", "ghc-pkg", "ghc-7.10", "ghc-pkg-7.10", "ghc-pkg-ghc-
whitelistedExtensionss :: [String]
whitelistedExtensionss = map ('.' : )
[ "hs", "lhs", "c", "sh", "cabal", "hsc", "err", "out", "in", "project" ]
[ "hs", "lhs", "c", "h", "sh", "cabal", "hsc", "err", "out", "in", "project" ]
getOtherModulesFiles :: GenericPackageDescription -> [FilePath]
getOtherModulesFiles gpd = mainModules ++ map fromModuleName otherModules'
......
name: p
version: 0.1.0.0
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
cabal-version: >=1.10
library
build-depends: base
include-dirs: include
install-includes: T2971test.h
default-language: Haskell2010
#include <T2971test.h>
main = putStrLn "hello world"
name: q
version: 0.1.0.0
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Custom
cabal-version: >=1.10
executable bar
main-is: Bar.hs
build-depends: base
executable foo
main-is: Foo.hs
build-depends: base, p
#include <T2971a.h>
main = return ()
name: T2971a
version: 0.1.0.0
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
cabal-version: >=1.10
library
build-depends: base
include-dirs: include
install-includes: T2971a.h
default-language: Haskell2010
executable exe
main-is: Main.hs
build-depends: base, T2971a
......@@ -526,6 +526,19 @@ tests config = do
tc "Regression/T3847" $ do
cabal "configure" ["--disable-tests"]
-- Test that we don't pick up include-dirs from libraries
-- we didn't actually depend on.
tc "Regression/T2971" $ do
withPackageDb $ do
withPackage "p" $ cabal_install []
withPackage "q" $ do
cabal "configure" []
assertOutputContains "T2971test.h"
=<< shouldFail (cabal' "build" [])
-- Test that we pick up include dirs from internal library
tc "Regression/T2971a" $ cabal_build []
-- Test error message we report when a non-buildable target is
-- requested to be built
-- TODO: We can give a better error message here, see #3858.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment