2012-12-14 19:52:44 +00:00
|
|
|
{- Makes standalone bundle.
|
|
|
|
-
|
2019-10-17 15:01:41 +00:00
|
|
|
- Copyright 2012-2019 Joey Hess <id@joeyh.name>
|
2012-12-14 19:52:44 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-12-14 19:52:44 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2013-04-17 15:57:46 +00:00
|
|
|
module Main where
|
|
|
|
|
2012-12-14 19:52:44 +00:00
|
|
|
import Control.Monad.IfElse
|
|
|
|
import System.Environment
|
|
|
|
import System.FilePath
|
2019-10-17 15:01:41 +00:00
|
|
|
import System.Posix.Files
|
2012-12-14 19:52:44 +00:00
|
|
|
import Control.Monad
|
2013-05-15 00:59:14 +00:00
|
|
|
import Build.BundledPrograms
|
2019-10-17 16:41:02 +00:00
|
|
|
import qualified Data.ByteString.Lazy as L
|
2012-12-14 19:52:44 +00:00
|
|
|
|
|
|
|
import Utility.SafeCommand
|
2019-10-17 15:01:41 +00:00
|
|
|
import Utility.Process
|
2012-12-14 19:52:44 +00:00
|
|
|
import Utility.Path
|
2016-04-28 19:18:11 +00:00
|
|
|
import Utility.Directory
|
2012-12-14 19:52:44 +00:00
|
|
|
|
|
|
|
progDir :: FilePath -> FilePath
|
|
|
|
#ifdef darwin_HOST_OS
|
|
|
|
progDir topdir = topdir
|
|
|
|
#else
|
|
|
|
progDir topdir = topdir </> "bin"
|
|
|
|
#endif
|
|
|
|
|
2016-02-19 20:19:19 +00:00
|
|
|
extraProgDir :: FilePath -> FilePath
|
|
|
|
extraProgDir topdir = topdir </> "extra"
|
|
|
|
|
2013-04-22 17:33:29 +00:00
|
|
|
installProg :: FilePath -> FilePath -> IO (FilePath, FilePath)
|
2012-12-14 19:52:44 +00:00
|
|
|
installProg dir prog = searchPath prog >>= go
|
|
|
|
where
|
|
|
|
go Nothing = error $ "cannot find " ++ prog ++ " in PATH"
|
2013-04-22 17:33:29 +00:00
|
|
|
go (Just f) = do
|
|
|
|
let dest = dir </> takeFileName f
|
|
|
|
unlessM (boolSystem "install" [File f, File dest]) $
|
|
|
|
error $ "install failed for " ++ prog
|
|
|
|
return (dest, f)
|
2012-12-14 19:52:44 +00:00
|
|
|
|
2019-10-17 15:01:41 +00:00
|
|
|
installGitLibs :: FilePath -> IO ()
|
|
|
|
installGitLibs topdir = do
|
|
|
|
-- install git-core programs; these are run by the git command
|
|
|
|
createDirectoryIfMissing True gitcoredestdir
|
|
|
|
execpath <- getgitpath "exec-path"
|
|
|
|
cfs <- dirContents execpath
|
|
|
|
forM_ cfs $ \f -> do
|
|
|
|
destf <- (gitcoredestdir </>)
|
|
|
|
<$> relPathDirToFile execpath f
|
|
|
|
createDirectoryIfMissing True (takeDirectory destf)
|
2019-10-17 15:55:51 +00:00
|
|
|
issymlink <- isSymbolicLink <$> getSymbolicLinkStatus f
|
2019-10-17 15:01:41 +00:00
|
|
|
if issymlink
|
|
|
|
then do
|
|
|
|
-- many git-core files may symlink to eg
|
2019-11-14 19:08:23 +00:00
|
|
|
-- ../../bin/git, which is located outside
|
|
|
|
-- the git-core directory. The target of
|
2019-11-14 20:15:42 +00:00
|
|
|
-- such links is installed into the progDir
|
|
|
|
-- (if not already there), and the links
|
|
|
|
-- repointed to it.
|
2019-11-14 19:08:23 +00:00
|
|
|
--
|
|
|
|
-- Other git-core files symlink to a file
|
|
|
|
-- beside them in the directory. Those
|
|
|
|
-- links can be copied as-is.
|
2019-10-17 15:01:41 +00:00
|
|
|
linktarget <- readSymbolicLink f
|
2019-11-14 19:08:23 +00:00
|
|
|
if takeFileName linktarget == linktarget
|
|
|
|
then cp f destf
|
|
|
|
else do
|
2019-11-14 20:34:13 +00:00
|
|
|
let linktarget' = progDir topdir </> takeFileName linktarget
|
2019-11-14 20:15:42 +00:00
|
|
|
unlessM (doesFileExist linktarget') $ do
|
|
|
|
createDirectoryIfMissing True (takeDirectory linktarget')
|
|
|
|
L.readFile f >>= L.writeFile linktarget'
|
2019-11-14 19:08:23 +00:00
|
|
|
nukeFile destf
|
|
|
|
rellinktarget <- relPathDirToFile (takeDirectory destf) linktarget'
|
|
|
|
createSymbolicLink rellinktarget destf
|
2019-10-17 15:01:41 +00:00
|
|
|
else cp f destf
|
|
|
|
|
|
|
|
-- install git's template files
|
|
|
|
-- git does not have an option to get the path of these,
|
|
|
|
-- but they're architecture independent files, so are located
|
|
|
|
-- next to the --man-path, in eg /usr/share/git-core
|
|
|
|
manpath <- getgitpath "man-path"
|
|
|
|
let templatepath = manpath </> ".." </> "git-core" </> "templates"
|
|
|
|
tfs <- dirContents templatepath
|
|
|
|
forM_ tfs $ \f -> do
|
|
|
|
destf <- (templatedestdir </>)
|
|
|
|
<$> relPathDirToFile templatepath f
|
|
|
|
createDirectoryIfMissing True (takeDirectory destf)
|
|
|
|
cp f destf
|
|
|
|
where
|
|
|
|
gitcoredestdir = topdir </> "git-core"
|
|
|
|
templatedestdir = topdir </> "templates"
|
|
|
|
|
|
|
|
getgitpath v = do
|
|
|
|
let opt = "--" ++ v
|
|
|
|
ls <- lines <$> readProcess "git" [opt]
|
|
|
|
case ls of
|
|
|
|
[] -> error $ "git " ++ opt ++ "did not output a location"
|
|
|
|
(p:_) -> return p
|
|
|
|
|
2019-10-17 15:55:51 +00:00
|
|
|
cp src dest = do
|
|
|
|
nukeFile dest
|
2019-10-17 15:01:41 +00:00
|
|
|
unlessM (boolSystem "cp" [Param "-a", File src, File dest]) $
|
|
|
|
error "cp failed"
|
|
|
|
|
2013-12-30 17:19:22 +00:00
|
|
|
main :: IO ()
|
2012-12-14 19:52:44 +00:00
|
|
|
main = getArgs >>= go
|
|
|
|
where
|
|
|
|
go [] = error "specify topdir"
|
2014-10-09 19:09:26 +00:00
|
|
|
go (topdir:_) = do
|
2016-02-19 20:19:19 +00:00
|
|
|
installed <- forM
|
|
|
|
[ (progDir topdir, preferredBundledPrograms)
|
|
|
|
, (extraProgDir topdir, extraBundledPrograms) ] $ \(dir, progs) -> do
|
|
|
|
createDirectoryIfMissing True dir
|
|
|
|
forM progs $ installProg dir
|
|
|
|
writeFile "tmp/standalone-installed" (show (concat installed))
|
2019-10-17 15:01:41 +00:00
|
|
|
installGitLibs topdir
|