comparison recipes/wince/gnupg/base.py @ 322:278abafc2d86

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