comparison recipes/gnupg/base.py @ 134:605f6784aae7

Add recipes for gnupg and related packages
author Bernhard Herzog <bh@intevation.de>
date Mon, 26 May 2008 15:01:00 +0000
parents
children 93fcd0b9e82c
comparison
equal deleted inserted replaced
133:a13850c3be85 134:605f6784aae7
1 # Copyright (C) 2007, 2008 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <bh@intevation.de>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """Base classes for all gnupg packagers"""
9
10 import os
11 import re
12 import inspect
13 import new
14
15 import treepkg.util
16 import treepkg.packager
17 import treepkg.run as run
18 from treepkg.cmdexpand import cmdexpand
19
20
21 class BaseSourcePackager(treepkg.packager.SourcePackager):
22
23 def orig_source_version(self, directory):
24 """Determines the version from the configure.ac file in directory"""
25 filename = os.path.join(directory, "configure.ac")
26 for line in open(filename):
27
28 # Matches lines like
29 # m4_define(my_version, [1.1.7])
30 # used by most of the gnupg packages
31 match = re.match(r"m4_define\(\[?my_version\]?, \[([0-9.]+)\]\)",
32 line)
33 if match:
34 return match.group(1)
35
36 # Matches lines like.
37 # AC_INIT(pinentry, 0.7.6-cvs, [gnupg-devel@gnupg.org])
38 # pinentry is the GnuPG package that actually needs this
39 match = re.match(r"AC_INIT\([a-zA-Z_]+, ([0-9.]+)", line)
40 if match:
41 return match.group(1)
42
43 raise RuntimeError("Could not determine the version number from %s"
44 % filename)
45
46 def determine_package_version(self, directory):
47 return "%s+svn%d" % (self.orig_source_version(directory), self.revision)
48
49 def do_package(self):
50 pkgbaseversion, pkgbasedir = self.export_sources()
51
52 run.call(cmdexpand("/bin/sh autogen.sh"), cwd=pkgbasedir,
53 suppress_output=True)
54 orig_version = self.orig_source_version(pkgbasedir)
55
56 # patch the version number in the newly generated configure
57 # file. autogen.sh normally determines it from svn, but here it
58 # ran on a copy that did not include the .svn subdirectories and
59 # thus could not find the svn revision.
60 treepkg.util.replace_in_file(os.path.join(pkgbasedir, "configure"),
61 re.escape(orig_version) + "-svn0",
62 orig_version + "-svn%d" % self.revision)
63
64 pkgbasename = self.pkg_basename + "_" + pkgbaseversion
65 origtargz = os.path.join(self.work_dir,
66 pkgbasename + ".orig.tar.gz")
67 self.create_tarball(origtargz, self.work_dir,
68 os.path.basename(pkgbasedir))
69
70 changemsg = ("Update to SVN rev. %d" % (self.revision,))
71 self.copy_debian_directory(pkgbasedir, pkgbaseversion,
72 changemsg)
73
74 self.create_source_package(pkgbasedir, origtargz)
75 self.move_source_package(pkgbasename)
76
77
78 class SmartSourcePackager(BaseSourcePackager):
79
80 """SourcePackager that uses pbuilder to create the source tarball.
81
82 We try to create source tarballs that are as close to the tarballs
83 created by the upstream maintainers. For the gnupg software this
84 means need to run 'make dist' in a configured SVN working copy with
85 some additional software installed like autoconf and texinfo. We
86 want to avoid running code from a working copy outside of the
87 pbuilder environment and to have to install recipe specific
88 additional software packages in the treepkg host system. Therefore
89 we create the source tarball using 'pbuilder execute' with a script.
90 """
91
92 createtarball_script = """\
93 #! /bin/bash
94 set -e
95
96 apt-get --assume-yes --force-yes install %(builddeps)s
97
98 # copy the source tree to a directory that's under pbuilder control so
99 # that it gets removed along with the build environment. Otherwise we
100 # end up with a directory containing files that cannot be removed by
101 # treepkg
102 workdir=/tmp/work
103 cp -a %(basedir)s $workdir
104 cd $workdir
105
106 # tweak autoconf settings so that make dist produces a tar.gz, not a
107 # tar.bz2. Removing all options whose names contain 'dist' should
108 # achieve that.
109 cp Makefile.am Makefile.am.orig
110 sed -e '/AUTOMAKE_OPTIONS/ s/[a-zA-Z0-9-]*dist[a-zA-Z0-9-]*//g' \
111 Makefile.am.orig > Makefile.am
112
113 ./autogen.sh
114 ./configure --enable-maintainer-mode
115
116 # revert autoconf changes, so that the original Makefile.am ends up in
117 # the tarball
118 mv Makefile.am.orig Makefile.am
119
120 %(make_dist_command)s
121
122 mv *.tar.gz %(origtargz)s
123 """
124
125 make_dist_command = "make dist"
126
127 def __init__(self, *args):
128 super(SmartSourcePackager, self).__init__(*args)
129 self.pkgbasename = None
130 self.pkgbaseversion = None
131 self.origtargz = None
132
133 def copy_workingcopy(self, dest):
134 treepkg.util.copytree(self.track.checkout_dir, dest)
135
136 def create_original_tarball(self):
137 copied_working_copy = os.path.join(self.work_dir, "copied_working_copy")
138 self.copy_workingcopy(copied_working_copy)
139
140 self.pkgbaseversion = \
141 self.determine_package_version(copied_working_copy)
142 self.pkgbasename = self.pkg_basename + "_" + self.pkgbaseversion
143 self.origtargz = os.path.join(self.work_dir,
144 self.pkgbasename + ".orig.tar.gz")
145
146 script = (self.createtarball_script
147 % dict(builddeps=" ".join(self.track.dependencies_required()
148 | self.tarball_dependencies),
149 basedir=copied_working_copy,
150 origtargz=self.origtargz,
151 make_dist_command=self.make_dist_command))
152 script_name = os.path.join(self.work_dir, "createtarball")
153 treepkg.util.writefile(script_name, script, 0755)
154
155 treepkg.util.ensure_directory(self.src_dir)
156 self.track.builder.run_script(script_name,
157 logfile=os.path.join(self.src_dir,
158 "tarball.log"),
159 bindmounts=[self.work_dir, self.src_dir])
160
161 def create_orig_dir(self):
162 """Unpacks the tarball created by create_original_tarball into work_dir
163 """
164 unpack_dir = os.path.join(self.work_dir, "unpack")
165 treepkg.util.ensure_directory(unpack_dir)
166 run.call(cmdexpand("tar xzf $origtargz -C $unpack_dir",
167 unpack_dir=unpack_dir, origtargz=self.origtargz))
168 unpacked_files = treepkg.util.listdir_abs(unpack_dir)
169 if len(unpacked_files) != 1:
170 raise RuntimeError("%s should have extracted to a single directory",
171 origtargz)
172 unpacked_dir = unpacked_files[0]
173
174 orig_dir = os.path.join(self.work_dir, os.path.basename(unpacked_dir))
175 os.rename(unpacked_dir, orig_dir)
176 return orig_dir
177
178 def do_package(self):
179 self.create_original_tarball()
180 orig_dir = self.create_orig_dir()
181
182 changemsg = ("Update to SVN rev. %d" % (self.revision,))
183 self.copy_debian_directory(orig_dir, self.pkgbaseversion, changemsg)
184
185 self.create_source_package(orig_dir, self.origtargz)
186 self.move_source_package(self.pkgbasename)
187
188
189 def define_gnupg_packager(pkg_basename,
190 tarball_dependencies=("autoconf", "automake",
191 "texinfo", "subversion"),
192 make_dist_command=None):
193 """Create a SourcePackager for a GnuPG package in the caller's globals().
194 This is a helper function for the modules in the recipe.gnupg package.
195 """
196 base_class = BaseSourcePackager
197 class_attributes = dict(pkg_basename=pkg_basename)
198 if tarball_dependencies is not None:
199 base_class = SmartSourcePackager
200 class_attributes["tarball_dependencies"] = set(tarball_dependencies)
201 if make_dist_command is not None:
202 base_class = SmartSourcePackager
203 class_attributes["make_dist_command"] = make_dist_command
204
205 caller_globals = inspect.currentframe().f_back.f_globals
206 caller_globals["SourcePackager"] = new.classobj("SourcePackager",
207 (base_class,),
208 class_attributes)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)