propellor spin
This commit is contained in:
parent
3620f070be
commit
7c5188b202
|
@ -11,14 +11,18 @@ import Utility.LinuxMkLibs
|
||||||
import Utility.SafeCommand
|
import Utility.SafeCommand
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
import Utility.FileMode
|
import Utility.FileMode
|
||||||
|
import Utility.FileSystemEncoding
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
import System.Posix.Files
|
import System.Posix.Files
|
||||||
|
|
||||||
-- | Sets up a shimmed version of the program, in a directory, and
|
-- | Sets up a shimmed version of the program, in a directory, and
|
||||||
-- returns its path.
|
-- returns its path.
|
||||||
|
--
|
||||||
|
-- Propellor may be running from an existing shim, in which case it's
|
||||||
|
-- simply reused.
|
||||||
setup :: FilePath -> FilePath -> IO FilePath
|
setup :: FilePath -> FilePath -> IO FilePath
|
||||||
setup propellorbin dest = do
|
setup propellorbin dest = checkAlreadyShimmed propellorbin $ do
|
||||||
createDirectoryIfMissing True dest
|
createDirectoryIfMissing True dest
|
||||||
|
|
||||||
libs <- parseLdd <$> readProcess "ldd" [propellorbin]
|
libs <- parseLdd <$> readProcess "ldd" [propellorbin]
|
||||||
|
@ -36,7 +40,7 @@ setup propellorbin dest = do
|
||||||
let linkerparams = ["--library-path", intercalate ":" libdirs ]
|
let linkerparams = ["--library-path", intercalate ":" libdirs ]
|
||||||
let shim = file propellorbin dest
|
let shim = file propellorbin dest
|
||||||
writeFile shim $ unlines
|
writeFile shim $ unlines
|
||||||
[ "#!/bin/sh"
|
[ shebang
|
||||||
, "GCONV_PATH=" ++ shellEscape gconvdir
|
, "GCONV_PATH=" ++ shellEscape gconvdir
|
||||||
, "export GCONV_PATH"
|
, "export GCONV_PATH"
|
||||||
, "exec " ++ unwords (map shellEscape $ linker : linkerparams) ++
|
, "exec " ++ unwords (map shellEscape $ linker : linkerparams) ++
|
||||||
|
@ -45,6 +49,17 @@ setup propellorbin dest = do
|
||||||
modifyFileMode shim (addModes executeModes)
|
modifyFileMode shim (addModes executeModes)
|
||||||
return shim
|
return shim
|
||||||
|
|
||||||
|
shebang :: String
|
||||||
|
shebang = "#!/bin/sh"
|
||||||
|
|
||||||
|
checkAlreadyShimmed :: FilePath -> IO FilePath -> IO FilePath
|
||||||
|
checkAlreadyShimmed f nope = withFile f ReadMode $ \h -> do
|
||||||
|
fileEncoding h
|
||||||
|
s <- hGetLine h
|
||||||
|
if s == shebang
|
||||||
|
then return f
|
||||||
|
else nope
|
||||||
|
|
||||||
-- Called when the shimmed propellor is running, so that commands it runs
|
-- Called when the shimmed propellor is running, so that commands it runs
|
||||||
-- don't see it.
|
-- don't see it.
|
||||||
cleanEnv :: IO ()
|
cleanEnv :: IO ()
|
||||||
|
|
Loading…
Reference in New Issue