Commit 60409cb9 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov

Refactoring.

Add a D.S.Program.Strip module. Call 'stripLib' from createLibArchive so that
it's done only once.
parent 3e283256
......@@ -190,6 +190,7 @@ library
Distribution.Simple.Program.Ld
Distribution.Simple.Program.Run
Distribution.Simple.Program.Script
Distribution.Simple.Program.Strip
Distribution.Simple.Program.Types
Distribution.Simple.Register
Distribution.Simple.Setup
......
......@@ -111,6 +111,7 @@ import Distribution.Simple.Program
import qualified Distribution.Simple.Program.HcPkg as HcPkg
import qualified Distribution.Simple.Program.Ar as Ar
import qualified Distribution.Simple.Program.Ld as Ld
import qualified Distribution.Simple.Program.Strip as Strip
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup
( toFlag, fromFlag, fromFlagOrDefault )
......@@ -901,13 +902,11 @@ buildOrReplLib forRepl verbosity numJobsFlag pkg_descr lbi lib clbi = do
}
whenVanillaLib False $ do
(arProg, _) <- requireProgram verbosity arProgram (withPrograms lbi)
Ar.createArLibArchive verbosity arProg
Ar.createArLibArchive verbosity (withPrograms lbi) (stripLibs lbi)
vanillaLibFilePath staticObjectFiles
whenProfLib $ do
(arProg, _) <- requireProgram verbosity arProgram (withPrograms lbi)
Ar.createArLibArchive verbosity arProg
Ar.createArLibArchive verbosity (withPrograms lbi) (stripLibs lbi)
profileLibFilePath profObjectFiles
whenGHCiLib $ do
......@@ -1266,39 +1265,10 @@ installExe verbosity lbi installDirs buildPref
installExecutableFile verbosity
(buildPref </> exeName exe </> exeFileName)
(dest <.> exeExtension)
stripExe verbosity lbi exeFileName (dest <.> exeExtension)
when (stripExes lbi) $
Strip.stripExe verbosity (withPrograms lbi) (dest <.> exeExtension)
installBinary (binDir </> fixedExeBaseName)
stripExe :: Verbosity -> LocalBuildInfo -> FilePath -> FilePath -> IO ()
stripExe verbosity lbi name path =
when (stripExes lbi) $ runStrip verbosity (withPrograms lbi) name args
where
args = path : case buildOS of
OSX -> ["-x"] -- By default, stripping the ghc binary on at least
-- some OS X installations causes:
-- HSbase-3.0.o: unknown symbol `_environ'"
-- The -x flag fixes that.
_ -> []
runStrip :: Verbosity -> ProgramConfiguration -> FilePath -> [String] -> IO ()
runStrip verbosity progConf name args =
case lookupProgram stripProgram progConf of
Just strip -> rawSystemProgram verbosity strip args
Nothing -> unless (buildOS == Windows) $
-- Don't bother warning on windows, we don't expect them to
-- have the strip program anyway.
warn verbosity $ "Unable to strip executable or library '"
++ name ++ "' (missing the 'strip' program)"
-- TODO: Move into createArLibArchive?
stripLib :: Verbosity -> LocalBuildInfo -> FilePath -> FilePath -> IO ()
stripLib verbosity lbi name path =
when (stripLibs lbi) $ do runStrip verbosity (withPrograms lbi) name args
-- 'strip' messes with object file metadata.
Ar.wipeMetadata path
where
args = [path, "--strip-unneeded"]
-- |Install for ghc, .hi, .a and, if --with-ghci given, .o
installLib :: Verbosity
-> LocalBuildInfo
......@@ -1326,9 +1296,10 @@ installLib verbosity lbi targetDir dynlibTargetDir builtDir _pkg lib clbi = do
let src = srcDir </> name
dst = dstDir </> name
createDirectoryIfMissingVerbose verbosity True dstDir
stripLib verbosity lbi name src
if isShared
then installExecutableFile verbosity src dst
then do when (stripLibs lbi) $
Strip.stripLib verbosity (withPrograms lbi) src
installExecutableFile verbosity src dst
else installOrdinaryFile verbosity src dst
installOrdinary = install False
......
......@@ -12,20 +12,21 @@
module Distribution.Simple.Program.Ar (
createArLibArchive,
multiStageProgramInvocation,
wipeMetadata
multiStageProgramInvocation
) where
import Control.Monad (unless)
import Control.Monad (when, unless)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import Data.Char (isSpace)
import Distribution.Compat.CopyFile (filesEqual)
import Distribution.Simple.Program.Types
( ConfiguredProgram(..) )
import Distribution.Simple.Program
( ProgramConfiguration, arProgram, requireProgram )
import Distribution.Simple.Program.Run
( programInvocation, multiStageProgramInvocation
, runProgramInvocation )
import qualified Distribution.Simple.Program.Strip as Strip
( stripLib )
import Distribution.Simple.Utils
( dieWithLocation, withTempDirectory )
import Distribution.System
......@@ -40,9 +41,10 @@ import System.IO
-- | Call @ar@ to create a library archive from a bunch of object files.
--
createArLibArchive :: Verbosity -> ConfiguredProgram
createArLibArchive :: Verbosity -> ProgramConfiguration -> Bool
-> FilePath -> [FilePath] -> IO ()
createArLibArchive verbosity ar targetPath files = do
createArLibArchive verbosity progConf stripLib targetPath files = do
(ar, _) <- requireProgram verbosity arProgram progConf
let (targetDir, targetName) = splitFileName targetPath
withTempDirectory verbosity targetDir targetName $ \ tmpDir -> do
......@@ -83,6 +85,7 @@ createArLibArchive verbosity ar targetPath files = do
| inv <- multiStageProgramInvocation
simple (initial, middle, final) files ]
when stripLib $ Strip.stripLib verbosity progConf tmpPath
wipeMetadata tmpPath
equal <- filesEqual tmpPath targetPath
unless equal $ renameFile tmpPath targetPath
......
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.Program.Strip
--
-- Maintainer : cabal-devel@haskell.org
-- Portability : portable
--
-- This module provides an library interface to the @strip@ program.
module Distribution.Simple.Program.Strip (stripLib, stripExe)
where
import Distribution.Simple.Program (ProgramConfiguration, lookupProgram
,rawSystemProgram, stripProgram)
import Distribution.Simple.Utils (warn)
import Distribution.System (OS (..), buildOS)
import Distribution.Verbosity (Verbosity)
import Control.Monad (unless)
import System.FilePath (takeBaseName)
runStrip :: Verbosity -> ProgramConfiguration -> FilePath -> [String] -> IO ()
runStrip verbosity progConf path args =
case lookupProgram stripProgram progConf of
Just strip -> rawSystemProgram verbosity strip (path:args)
Nothing -> unless (buildOS == Windows) $
-- Don't bother warning on windows, we don't expect them to
-- have the strip program anyway.
warn verbosity $ "Unable to strip executable or library '"
++ (takeBaseName path)
++ "' (missing the 'strip' program)"
stripExe :: Verbosity -> ProgramConfiguration -> FilePath -> IO ()
stripExe verbosity conf path =
runStrip verbosity conf path args
where
args = case buildOS of
OSX -> ["-x"] -- By default, stripping the ghc binary on at least
-- some OS X installations causes:
-- HSbase-3.0.o: unknown symbol `_environ'"
-- The -x flag fixes that.
_ -> []
stripLib :: Verbosity -> ProgramConfiguration -> FilePath -> IO ()
stripLib verbosity conf path = do
runStrip verbosity conf path args
where
args = ["--strip-unneeded"]
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