From a1107e21fef75bb914c4ec6627646eb51e7dd533 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 24 Oct 2016 23:39:22 -0700 Subject: [PATCH] Don't use installedPkgs for internal library library dirs. In 1.24, installedPkgs contained only references to the external package database, not any internal libraries. In particular, when we built a dynamically linked executable, installedPkgs did NOT have a reference to the internal library; instead, depLibraryPaths has a special case (hasInternalDeps) to add the final libdir to the RPATH. In HEAD, after 0d15ede, we started adding internal libraries (with the INPLACE registrations) to installedPkgs to fix #2971. But depLibraryPaths was not updated, which means that the inplace registrations got picked up and added to the RPATH, resulting in bad temporary directories showing up in RPATHs. In this commit, we just filter out internal entries from installedPkgs and compute the library dirs for them from scratch (this code already existed, so no loss!) Fixes #4025. Signed-off-by: Edward Z. Yang --- Cabal/Cabal.cabal | 3 +++ Cabal/Distribution/Simple/LocalBuildInfo.hs | 14 ++++++++++++-- Cabal/tests/PackageTests/Regression/T4025/A.hs | 4 ++++ .../PackageTests/Regression/T4025/T4025.cabal | 13 +++++++++++++ .../PackageTests/Regression/T4025/exe/Main.hs | 2 ++ Cabal/tests/PackageTests/Tests.hs | 13 +++++++++++++ 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 Cabal/tests/PackageTests/Regression/T4025/A.hs create mode 100644 Cabal/tests/PackageTests/Regression/T4025/T4025.cabal create mode 100644 Cabal/tests/PackageTests/Regression/T4025/exe/Main.hs diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal index 9696ad62cb8..42d352f659f 100644 --- a/Cabal/Cabal.cabal +++ b/Cabal/Cabal.cabal @@ -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 diff --git a/Cabal/Distribution/Simple/LocalBuildInfo.hs b/Cabal/Distribution/Simple/LocalBuildInfo.hs index 105485a3b35..b259814c0a4 100644 --- a/Cabal/Distribution/Simple/LocalBuildInfo.hs +++ b/Cabal/Distribution/Simple/LocalBuildInfo.hs @@ -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' diff --git a/Cabal/tests/PackageTests/Regression/T4025/A.hs b/Cabal/tests/PackageTests/Regression/T4025/A.hs new file mode 100644 index 00000000000..ecf2c1f4d7a --- /dev/null +++ b/Cabal/tests/PackageTests/Regression/T4025/A.hs @@ -0,0 +1,4 @@ +module A where +{-# NOINLINE a #-} +a :: Int +a = 23 diff --git a/Cabal/tests/PackageTests/Regression/T4025/T4025.cabal b/Cabal/tests/PackageTests/Regression/T4025/T4025.cabal new file mode 100644 index 00000000000..245fdbf0672 --- /dev/null +++ b/Cabal/tests/PackageTests/Regression/T4025/T4025.cabal @@ -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 diff --git a/Cabal/tests/PackageTests/Regression/T4025/exe/Main.hs b/Cabal/tests/PackageTests/Regression/T4025/exe/Main.hs new file mode 100644 index 00000000000..f3fe84d228c --- /dev/null +++ b/Cabal/tests/PackageTests/Regression/T4025/exe/Main.hs @@ -0,0 +1,2 @@ +import A +main = print a diff --git a/Cabal/tests/PackageTests/Tests.hs b/Cabal/tests/PackageTests/Tests.hs index d09b8c5fd36..892a0b7d6a4 100644 --- a/Cabal/tests/PackageTests/Tests.hs +++ b/Cabal/tests/PackageTests/Tests.hs @@ -539,6 +539,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.