Commit f5133394 authored by David Eichmann's avatar David Eichmann 🏋

extra-bundled-libraries: align naming convention with ghc

parent 3904dfbd
......@@ -31,7 +31,8 @@ module Distribution.Simple.BuildPaths (
mkGenericSharedLibName,
mkSharedLibName,
mkStaticLibName,
mkGenericSharedBundledLibName,
exeExtension,
objExtension,
dllExtension,
......@@ -57,6 +58,7 @@ import Distribution.System
import Distribution.Verbosity
import Distribution.Simple.Utils
import Data.List (stripPrefix)
import System.FilePath ((</>), (<.>), normalise)
-- ---------------------------------------------------------------------------
......@@ -218,6 +220,24 @@ mkStaticLibName platform (CompilerId compilerFlavor compilerVersion) lib
= "lib" ++ getHSLibraryName lib ++ "-" ++ comp <.> staticLibExtension platform
where comp = prettyShow compilerFlavor ++ prettyShow compilerVersion
-- | Create a library name for a bundled shared library from a given name.
-- This matches the naming convention for shared libraries as implemented in
-- GHC's packageHsLibs function in the Packages module.
-- If the given name is prefixed with HS, then this prepends 'lib' and appends
-- the compiler flavour/version and shared library extension e.g.:
-- "HSrts-1.0" -> "libHSrts-1.0-ghc8.7.20190109.so"
-- Otherwise the given name should be prefixed with 'C', then this strips the
-- 'C', prepends 'lib' and appends the shared library extension e.g.:
-- "Cffi" -> "libffi.so"
mkGenericSharedBundledLibName :: Platform -> CompilerId -> String -> String
mkGenericSharedBundledLibName platform comp lib
| "HS" `isPrefixOf` lib
= mkGenericSharedLibName platform comp lib
| Just lib' <- stripPrefix "C" lib
= "lib" ++ lib' <.> dllExtension platform
| otherwise
= error ("Don't understand library name " ++ lib)
-- ------------------------------------------------------------
-- * Platform file extensions
-- ------------------------------------------------------------
......
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE CPP #-}
......@@ -109,12 +110,12 @@ import Distribution.Types.UnqualComponentName
import Distribution.Utils.NubList
import Language.Haskell.Extension
import Control.Monad (msum)
import Control.Monad (msum, forM_)
import Data.Char (isLower)
import qualified Data.Map as Map
import System.Directory
( doesFileExist, getAppUserDataDirectory, createDirectoryIfMissing
, canonicalizePath, removeFile, renameFile )
, canonicalizePath, removeFile, renameFile, getDirectoryContents )
import System.FilePath ( (</>), (<.>), takeExtension
, takeDirectory, replaceExtension
,isRelative )
......@@ -1820,7 +1821,7 @@ 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"
......@@ -1829,7 +1830,10 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
-- copy the built library files over:
whenHasCode $ do
whenVanilla $ do
sequence_ [ installOrdinary builtDir targetDir (mkGenericStaticLibName (l ++ f))
sequence_ [ installOrdinary
builtDir
targetDir
(mkGenericStaticLibName (l ++ f))
| l <- getHSLibraryName (componentUnitId clbi):(extraBundledLibs (libBuildInfo lib))
, f <- "":extraLibFlavours (libBuildInfo lib)
]
......@@ -1837,12 +1841,41 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
whenProf $ do
installOrdinary builtDir targetDir profileLibName
whenGHCi $ installOrdinary builtDir targetDir ghciProfLibName
whenShared $
sequence_ [ installShared builtDir dynlibTargetDir
(mkGenericSharedLibName platform compiler_id (l ++ f))
| l <- getHSLibraryName uid : extraBundledLibs (libBuildInfo lib)
, f <- "":extraDynLibFlavours (libBuildInfo lib)
]
whenShared $ if
-- The behavior for "extra-bundled-libraries" changed in version 2.5.0.
-- See ghc issue #15837 and Cabal PR #5855.
| specVersion pkg < mkVersion [2,5] -> do
sequence_ [ installShared builtDir dynlibTargetDir
(mkGenericSharedLibName platform compiler_id (l ++ f))
| l <- getHSLibraryName uid : extraBundledLibs (libBuildInfo lib)
, f <- "":extraDynLibFlavours (libBuildInfo lib)
]
| otherwise -> do
sequence_ [ installShared
builtDir
dynlibTargetDir
(mkGenericSharedLibName
platform
compiler_id
(getHSLibraryName uid ++ f))
| f <- "":extraDynLibFlavours (libBuildInfo lib)
]
sequence_ [ do
files <- getDirectoryContents builtDir
let l' = mkGenericSharedBundledLibName
platform
compiler_id
l
forM_ files $ \ file ->
when (l' `isPrefixOf` file) $ do
isFile <- doesFileExist (builtDir </> file)
when isFile $ do
installShared
builtDir
dynlibTargetDir
file
| l <- extraBundledLibs (libBuildInfo lib)
]
where
builtDir = componentBuildDir lbi clbi
......
......@@ -2453,6 +2453,15 @@ system-dependent values for these fields.
directory (e.g. via a custom setup). Libraries listed here will
be included when ``copy``-ing packages and be listed in the
``hs-libraries`` of the package configuration in the package database.
Library names must either be prefixed with "HS" or "C" and corresponding
library file names must match:
- Libraries with name "HS<library-name>":
- `libHS<library-name>.a`
- `libHS<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>*`
- Libraries with name "C<library-name>":
- `libC<library-name>.a`
- `lib<library-name>.<dyn-library-extension>*`
.. pkg-field:: extra-lib-dirs: directory list
......
......@@ -49,6 +49,12 @@ relative to the respective preceding *published* version.
* Require fields with optional commas to consistently omit or place
commas between elements.
* Changed the behavior of `extra-bundled-libraries` field. The naming convention
of dynamic library files (e.g. generated by a custom build script) has
changed. For library names prefixed with "C", the dynamic library file
name(s) must be of the form `lib<library-name>.<dyn-library-extension>*`
instead of the old `libC<library-name>-ghc<ghc-flavour><ghc-version>.<dyn-library-extension>`
``cabal-version: 2.4``
----------------------
......
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