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

Do not install/register internal libraries when unnecessary.



This commit fails its tests, because dynamic executables
linked against internal libraries aren't handled correctly
yet.  I had to do more refactoring to handle this correctly,
so it's in a separate commit.

Some refactoring in this one for identifying public libraries
as opposed to internal ones.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 90e908b8
......@@ -43,6 +43,7 @@ module Distribution.PackageDescription (
ModuleReexport(..),
emptyLibrary,
withLib,
hasPublicLib,
hasLibs,
libModules,
......@@ -124,7 +125,6 @@ import Distribution.Text
import Language.Haskell.Extension
import Data.Data (Data)
import Data.Foldable (traverse_)
import Data.List (nub, intercalate)
import Data.Maybe (fromMaybe, maybeToList)
import Data.Foldable as Fold (Foldable(foldMap))
......@@ -432,22 +432,21 @@ instance Semigroup Library where
emptyLibrary :: Library
emptyLibrary = mempty
-- |does this package have any libraries?
-- | Does this package have a PUBLIC library?
hasPublicLib :: PackageDescription -> Bool
hasPublicLib p = any f (libraries p)
where f lib = buildable (libBuildInfo lib) &&
libName lib == display (packageName (package p))
-- | Does this package have any libraries?
hasLibs :: PackageDescription -> Bool
hasLibs p = any (buildable . libBuildInfo) (libraries p)
-- |'Maybe' version of 'hasLibs'
maybeHasLibs :: PackageDescription -> [Library]
maybeHasLibs p =
libraries p >>= \lib -> if buildable (libBuildInfo lib)
then return lib
else []
-- |If the package description has a library section, call the given
-- function with the library build info as argument.
withLib :: PackageDescription -> (Library -> IO ()) -> IO ()
withLib pkg_descr f =
traverse_ f (maybeHasLibs pkg_descr)
sequence_ [f lib | lib <- libraries pkg_descr, buildable (libBuildInfo lib)]
-- | Get all the module names from the library (exposed and internal modules)
-- which need to be compiled. (This does not include reexports, which
......
......@@ -1121,17 +1121,20 @@ installLib :: Verbosity
-> Library
-> ComponentLocalBuildInfo
-> IO ()
installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do
-- copy .hi files over:
whenVanilla $ copyModuleFiles "hi"
whenProf $ copyModuleFiles "p_hi"
whenShared $ copyModuleFiles "dyn_hi"
whenRegistered $ do
whenVanilla $ copyModuleFiles "hi"
whenProf $ copyModuleFiles "p_hi"
whenShared $ copyModuleFiles "dyn_hi"
-- copy the built library files over:
whenVanilla $ installOrdinary builtDir targetDir vanillaLibName
whenProf $ installOrdinary builtDir targetDir profileLibName
whenGHCi $ installOrdinary builtDir targetDir ghciLibName
whenShared $ installShared builtDir dynlibTargetDir sharedLibName
whenRegistered $ do
whenVanilla $ installOrdinary builtDir targetDir vanillaLibName
whenProf $ installOrdinary builtDir targetDir profileLibName
whenGHCi $ installOrdinary builtDir targetDir ghciLibName
whenRegisteredOrDynExecutable $ do
whenShared $ installShared builtDir dynlibTargetDir sharedLibName
where
builtDir = libBuildDir lbi clbi
......@@ -1169,6 +1172,17 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
whenGHCi = when (hasLib && withGHCiLib lbi)
whenShared = when (hasLib && withSharedLib lbi)
-- Some files (e.g. interface files) are completely unnecessary when
-- we are not actually going to register the library. A library is
-- not registered if there is no "public library", e.g. in the case
-- that we have an internal library and executables, but no public
-- library.
whenRegistered = when (hasPublicLib pkg)
-- However, we must always install dynamic libraries when linking
-- dynamic executables, because we'll try to load them!
whenRegisteredOrDynExecutable = when (hasPublicLib pkg || (hasExes pkg && withDynExe lbi))
-- -----------------------------------------------------------------------------
-- Registering
......
......@@ -82,7 +82,13 @@ import qualified Data.ByteString.Lazy.Char8 as BS.Char8
register :: PackageDescription -> LocalBuildInfo
-> RegisterFlags -- ^Install in the user's database?; verbose
-> IO ()
register pkg lbi regFlags = withLib pkg (registerOne pkg lbi regFlags)
register pkg lbi regFlags =
-- We do NOT register libraries outside of the inplace database
-- if there is no public library, since no one else can use it
-- usefully (they're not public.) If we start supporting scoped
-- packages, we'll have to relax this.
when (hasPublicLib pkg) $
withLib pkg (registerOne pkg lbi regFlags)
registerOne :: PackageDescription -> LocalBuildInfo -> RegisterFlags
-> Library
......
......@@ -1105,7 +1105,7 @@ elaborateInstallPlan platform compiler progdb
then BuildInplaceOnly else BuildAndInstall
pkgBuildPackageDBStack = buildAndRegisterDbs
pkgRegisterPackageDBStack = buildAndRegisterDbs
pkgRequiresRegistration = isJust (Cabal.condLibrary gdesc)
pkgRequiresRegistration = PD.hasPublicLib (PD.packageDescription gdesc)
pkgSetupScriptStyle = packageSetupScriptStylePostSolver
pkgsImplicitSetupDeps pkg pkgDescription
......
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