File: Dist.lhs

package info (click to toggle)
darcs 1.0.9~rc1-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,248 kB
  • ctags: 565
  • sloc: haskell: 19,148; perl: 4,320; sh: 1,626; ansic: 1,137; makefile: 55; xml: 14
file content (116 lines) | stat: -rw-r--r-- 4,170 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%  Copyright (C) 2003 David Roundy
%
%  This program is free software; you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published by
%  the Free Software Foundation; either version 2, or (at your option)
%  any later version.
%
%  This program is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.
%
%  You should have received a copy of the GNU General Public License
%  along with this program; if not, write to the Free Software Foundation,
%  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\subsection{darcs dist}
\begin{code}
module Dist ( dist ) where
import Directory ( setCurrentDirectory )
import Workaround ( getCurrentDirectory )
import System ( ExitCode(..), system )
import Monad ( when )

import DarcsCommands
import DarcsArguments
import Repository ( amInRepository, withRepoLock )
import DarcsRepo
import RepoPrefs ( get_prefval )
import Lock ( withTemp, withTempDir, readBinFile )
import Exec ( exec, Redirect(..) )
\end{code}

\options{dist}

\haskell{dist_description}

\begin{code}
dist_description :: String
dist_description =
 "Create a distribution tarball."
\end{code}

\haskell{dist_help} Basically, you will typically use it in a makefile
rule such as
\begin{verbatim}
dist:
    darcs dist --dist-name darcs-`./darcs --version`
\end{verbatim}
\verb!darcs dist! then simply creates a clean copy of the source tree,
which it then tars and gzips.  If you use programs such as autoconf or
automake, you really should run them on the clean tree before tarring it up
and distributing it.  You can do this using the pref value ``predist'',
which is a shell command that is run prior to tarring up the distribution:
\begin{verbatim}
% darcs setpref predist "autoconf && automake"
\end{verbatim}

\begin{code}
dist_help :: String
dist_help =
 "Dist is a handy tool for implementing a \"make dist\" target in your\n"++
 "makefile.  It creates a tarball of the recorded edition of your tree.\n"
\end{code}

\begin{code}
dist :: DarcsCommand
dist = DarcsCommand {command_name = "dist",
                     command_help = dist_help,
                     command_description = dist_description,
                     command_extra_args = 0,
                     command_extra_arg_help = [],
                     command_command = dist_cmd,
                     command_prereq = amInRepository,
                     command_get_arg_possibilities = return [],
                     command_argdefaults = nodefaults,
                     command_darcsoptions = [distname_option, verbose, working_repo_dir]}
\end{code}

\begin{code}
dist_cmd :: [DarcsFlag] -> [String] -> IO ()
dist_cmd opts _ = withRepoLock opts $ \_ -> do
  dn <- get_dist_name opts
  verb <- return $ Verbose `elem` opts
  predist <- get_prefval "predist"
  formerdir <- getCurrentDirectory
  withTemp $ \tarfile ->
   withTempDir "darcsdist" $ \tempdir -> do
    setCurrentDirectory (formerdir)
    withRecorded (withTempDir (tempdir++"/"++dn)) $ \ddir -> do
     case predist of Nothing -> return ExitSuccess
                     Just pd -> system pd
     setCurrentDirectory (tempdir)
     exec "tar" ["-cf", "-", reverse $ takeWhile (/='/') $ reverse ddir]
                (Null, File tarfile, Stdout)
     when verb $ withTemp $ \tar_listing -> do
                   exec "tar" ["-tf", "-"]
                        (File tarfile, File tar_listing, Stdout)
                   to <- readBinFile tar_listing
                   putStr to
     exec "gzip" ["-c"]
          (File tarfile, File (formerdir++"/"++dn++".tar.gz"), Stdout)
     putStrLn $ "Created dist as "++dn++".tar.gz"

guess_repo_name :: IO String
guess_repo_name = do
  pwd <- getCurrentDirectory
  if '/' `elem` pwd
     then return $ reverse $ takeWhile (/='/') $ reverse pwd
     else return "cantguessreponame"

get_dist_name :: [DarcsFlag] -> IO String
get_dist_name (DistName dn:_) = return dn
get_dist_name (_:fs) = get_dist_name fs
get_dist_name _ = guess_repo_name
\end{code}