Ticket #10777: cabal-rsp.patch

File cabal-rsp.patch, 4.2 KB (added by awson, 3 years ago)

Quick and dirty Cabal patch to make it use response files in a couple of ar and ld invocations

  • Distribution/Simple/Program/Ar.hs

    diff -urN a/Distribution/Simple/Program/Ar.hs b/Distribution/Simple/Program/Ar.hs
    a b  
    3131import Distribution.Simple.Utils
    3232         ( dieWithLocation, withTempDirectory )
    3333import Distribution.System
    34          ( Arch(..), OS(..), Platform(..) )
     34         ( Arch(..), {- OS(..), -} Platform(..) )
    3535import Distribution.Verbosity
    3636         ( Verbosity, deafening, verbose )
    3737import System.Directory (doesFileExist, renameFile)
     
    4040         ( Handle, IOMode(ReadWriteMode), SeekMode(AbsoluteSeek)
    4141         , hFileSize, hSeek, withBinaryFile )
    4242
     43import Distribution.Compat.Exception ( catchExit, catchIO )
     44import System.IO ( hPutStrLn, hClose )
     45import Distribution.Simple.Utils ( withTempFile )
     46
    4347-- | Call @ar@ to create a library archive from a bunch of object files.
    4448--
    4549createArLibArchive :: Verbosity -> LocalBuildInfo
     
    5155  withTempDirectory verbosity targetDir "objs" $ \ tmpDir -> do
    5256  let tmpPath = tmpDir </> targetName
    5357
     58  {-
    5459  -- The args to use with "ar" are actually rather subtle and system-dependent.
    5560  -- In particular we have the following issues:
    5661  --
     
    8590        [ runProgramInvocation verbosity inv
    8691        | inv <- multiStageProgramInvocation
    8792                   simple (initial, middle, final) files ]
     93  -}
     94  withTempFile tmpDir ".rsp" $ \rsppath rsphnd ->
     95    do
     96      let
     97        normslash '\\' = '/'
     98        normslash x = x
     99      hPutStrLn rsphnd (map normslash $ unwords files)
     100      hClose rsphnd
     101      runProgramInvocation verbosity (programInvocation ar $ verbosityOpts verbosity ++ ["-r", tmpPath, '@':rsppath])
     102    `catchIO`   (\_ -> return ())
     103    `catchExit` (\_ -> return ())
    88104
    89105  when stripLib $ Strip.stripLib verbosity platform progConf tmpPath
    90106  unless (hostArch == Arm) $ -- See #1537
     
    95111  where
    96112    progConf = withPrograms lbi
    97113    stripLib = stripLibs    lbi
    98     platform@(Platform hostArch hostOS) = hostPlatform lbi
     114    platform@(Platform hostArch _hostOS) = hostPlatform lbi
    99115    verbosityOpts v | v >= deafening = ["-v"]
    100116                    | v >= verbose   = []
    101117                    | otherwise      = ["-c"]
  • Distribution/Simple/Program/Ld.hs

    diff -urN a/Distribution/Simple/Program/Ld.hs b/Distribution/Simple/Program/Ld.hs
    a b  
    1515import Distribution.Simple.Program.Types
    1616         ( ConfiguredProgram(..) )
    1717import Distribution.Simple.Program.Run
    18          ( programInvocation, multiStageProgramInvocation
     18         ( programInvocation {-, multiStageProgramInvocation -}
    1919         , runProgramInvocation )
     20import Distribution.Simple.Utils ( withTempFile )
     21import System.IO ( hPutStrLn, hClose )
     22import Distribution.Compat.Exception ( catchExit, catchIO )
    2023import Distribution.Verbosity
    2124         ( Verbosity )
    2225
    2326import System.Directory
    24          ( renameFile )
     27         ( {- renameFile, -} getTemporaryDirectory )
     28{-
    2529import System.FilePath
    2630         ( (<.>) )
     31-}
    2732
    2833-- | Call @ld -r@ to link a bunch of object files together.
    2934--
    3035combineObjectFiles :: Verbosity -> ConfiguredProgram
    3136                   -> FilePath -> [FilePath] -> IO ()
    32 combineObjectFiles verbosity ld target files =
    33 
     37combineObjectFiles verbosity ld target files = do
     38    tempDir <- getTemporaryDirectory
     39    withTempFile tempDir ".rsp" $ \rsppath rsphnd ->
     40      do
     41        hPutStrLn rsphnd (map normslash $ unwords files)
     42        hClose rsphnd
     43        runProgramInvocation verbosity (programInvocation ld ["-r", "-o", target, '@':rsppath])
     44      `catchIO`   (\_ -> return ())
     45      `catchExit` (\_ -> return ())
     46  where
     47    normslash '\\' = '/'
     48    normslash x = x
     49{-
    3450  -- Unlike "ar", the "ld" tool is not designed to be used with xargs. That is,
    3551  -- if we have more object files than fit on a single command line then we
    3652  -- have a slight problem. What we have to do is link files in batches into
     
    6076    run (inv:invs) = do runProgramInvocation verbosity inv
    6177                        renameFile target tmpfile
    6278                        run invs
     79-}