move libs to try to fit within available path space

This commit is contained in:
Joey Hess 2012-12-08 12:29:09 -04:00
parent d930d1a105
commit c7a4ad8bc3

View file

@ -36,15 +36,14 @@ installLibs :: FilePath -> IO [Maybe FilePath]
installLibs appbase = do installLibs appbase = do
needlibs <- otool appbase needlibs <- otool appbase
forM needlibs $ \lib -> do forM needlibs $ \lib -> do
let libdir = parentDir lib let dest = appbase </> takeFileName lib
let dest = appbase ++ lib
ifM (doesFileExist dest) ifM (doesFileExist dest)
( return Nothing ( return Nothing
, do , do
createDirectoryIfMissing True (appbase ++ libdir) createDirectoryIfMissing True appbase
_ <- boolSystem "cp" [File lib, File dest]
putStrLn $ "installing " ++ lib putStrLn $ "installing " ++ lib
return $ Just libdir _ <- boolSystem "cp" [File lib, File dest]
return $ Just appbase
) )
{- Returns libraries to install. -} {- Returns libraries to install. -}
@ -52,10 +51,13 @@ otool :: FilePath -> IO [FilePath]
otool appbase = do otool appbase = do
files <- filterM doesFileExist =<< dirContentsRecursive appbase files <- filterM doesFileExist =<< dirContentsRecursive appbase
l <- forM files $ \file -> do l <- forM files $ \file -> do
libs <- parseOtool <$> readProcess "otool" ["-L", file] libs <- filter unprocessed . parseOtool
<$> readProcess "otool" ["-L", file]
forM_ libs $ \lib -> install_name_tool file lib forM_ libs $ \lib -> install_name_tool file lib
return libs return libs
return $ nub $ concat l return $ nub $ concat l
where
unprocessed s = not ("@executable_path" `isInfixOf` s)
parseOtool :: String -> [FilePath] parseOtool :: String -> [FilePath]
parseOtool = catMaybes . map parse . lines parseOtool = catMaybes . map parse . lines
@ -74,7 +76,7 @@ install_name_tool binary lib = do
ok <- boolSystem "install_name_tool" ok <- boolSystem "install_name_tool"
[ Param "-change" [ Param "-change"
, File lib , File lib
, Param $ "@executable_path" ++ lib , Param $ "@executable_path" ++ (dropFileName lib)
, File binary , File binary
] ]
unless ok $ unless ok $