Skip to content

Commit

Permalink
Merge pull request #4033 from ezyang/pr/T4025
Browse files Browse the repository at this point in the history
Don't use installedPkgs for internal library library dirs.
  • Loading branch information
ezyang authored Oct 27, 2016
2 parents 2681137 + a1107e2 commit 37b112f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ extra-source-files:
tests/PackageTests/Regression/T3294/T3294.cabal
tests/PackageTests/Regression/T3847/Main.hs
tests/PackageTests/Regression/T3847/T3847.cabal
tests/PackageTests/Regression/T4025/A.hs
tests/PackageTests/Regression/T4025/T4025.cabal
tests/PackageTests/Regression/T4025/exe/Main.hs
tests/PackageTests/TemplateHaskell/dynamic/Exe.hs
tests/PackageTests/TemplateHaskell/dynamic/Lib.hs
tests/PackageTests/TemplateHaskell/dynamic/TH.hs
Expand Down
14 changes: 12 additions & 2 deletions Cabal/Distribution/Simple/LocalBuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,23 @@ depLibraryPaths inplace relative lbi clbi = do
| inplace = componentBuildDir lbi sub_clbi
| otherwise = dynlibdir (absoluteComponentInstallDirs pkgDescr lbi (componentUnitId sub_clbi) NoCopyDest)

let ipkgs = allPackages (installedPkgs lbi)
-- Why do we go through all the trouble of a hand-crafting
-- internalLibs, when 'installedPkgs' actually contains the
-- internal libraries? The trouble is that 'installedPkgs'
-- may contain *inplace* entries, which we must NOT use for
-- not inplace 'depLibraryPaths' (e.g., for RPATH calculation).
-- See #4025 for more details. This is all horrible but it
-- is a moot point if you are using a per-component build,
-- because you never have any internal libraries in this case;
-- they're all external.
let external_ipkgs = filter is_external (allPackages (installedPkgs lbi))
is_external ipkg = not (installedUnitId ipkg `elem` internalDeps)
-- First look for dynamic libraries in `dynamic-library-dirs`, and use
-- `library-dirs` as a fall back.
getDynDir pkg = case Installed.libraryDynDirs pkg of
[] -> Installed.libraryDirs pkg
d -> d
allDepLibDirs = concatMap getDynDir ipkgs
allDepLibDirs = concatMap getDynDir external_ipkgs

allDepLibDirs' = internalLibs ++ allDepLibDirs
allDepLibDirsC <- traverse canonicalizePathNoFail allDepLibDirs'
Expand Down
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/Regression/T4025/A.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A where
{-# NOINLINE a #-}
a :: Int
a = 23
13 changes: 13 additions & 0 deletions Cabal/tests/PackageTests/Regression/T4025/T4025.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: T4025
version: 1.0
build-type: Simple
cabal-version: >= 1.10

library
build-depends: base
exposed-modules: A

executable exe
build-depends: T4025, base
hs-source-dirs: exe
main-is: Main.hs
2 changes: 2 additions & 0 deletions Cabal/tests/PackageTests/Regression/T4025/exe/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import A
main = print a
13 changes: 13 additions & 0 deletions Cabal/tests/PackageTests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,19 @@ tests config = do
-- Test that we pick up include dirs from internal library
tc "Regression/T2971a" $ cabal_build []

-- Test that we don't accidentally add the inplace directory to
-- an executable RPATH. Don't test on Windows, which doesn't
-- support RPATH.
unlessWindows $ do
tc "Regression/T4025" $ do
cabal "configure" ["--enable-executable-dynamic"]
cabal "build" []
-- This should fail as it we should NOT be able to find the
-- dynamic library for the internal library (since we didn't
-- install it). If we incorrectly encoded our local dist
-- dir in the RPATH, this will succeed.
shouldFail $ runExe' "exe" []

-- 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.
Expand Down

0 comments on commit 37b112f

Please sign in to comment.