2 # Setup file for bzr-svn
3 # Copyright (C) 2005-2008 Jelmer Vernooij <jelmer@samba.org>
5 from distutils.core import setup
6 from distutils.extension import Extension
7 from distutils.command.install_lib import install_lib
8 from distutils import log
12 # Build instructions for Windows:
13 # * Install the SVN dev kit ZIP for Windows from
14 # http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91
15 # At time of writing, this was svn-win32-1.4.6_dev.zip
16 # * Find the SVN binary ZIP file with the binaries for your dev kit.
17 # At time of writing, this was svn-win32-1.4.6.zip
18 # Unzip this in the *same directory* as the dev kit - README.txt will be
19 # overwritten, but that is all. This is the default location the .ZIP file
20 # will suggest (ie, the directory embedded in both .zip files are the same)
21 # * Set SVN_DEV to point at this directory.
22 # * Install the APR BDB and INTL packages - see README.txt from the devkit
23 # * Set SVN_BDB and SVN_LIBINTL to point at these dirs.
25 # To install into a particular bzr location, use:
26 # % python setup.py install --install-lib=c:\root\of\bazaar
28 class CommandException(Exception):
29 """Encapsulate exit status of apr-config execution"""
30 def __init__(self, msg, cmd, arg, status, val):
31 self.message = msg % (cmd, val)
32 super(CommandException, self).__init__(self.message)
37 return os.WIFEXITED(self.status) and os.WEXITSTATUS(self.status) == 127
39 def run_cmd(cmd, arg):
40 """Run specified command with given arguments, handling status"""
41 f = os.popen("'%s' %s" % (cmd, arg))
42 dir = f.read().rstrip("\n")
46 if os.WIFEXITED(status):
47 code = os.WEXITSTATUS(status)
50 raise CommandException("%s exited with status %d",
51 cmd, arg, status, code)
52 if os.WIFSIGNALED(status):
53 signal = os.WTERMSIG(status)
54 raise CommandException("%s killed by signal %d",
55 cmd, arg, status, signal)
56 raise CommandException("%s terminated abnormally (%d)",
57 cmd, arg, status, status)
60 apr_config_cmd = os.getenv("APR_CONFIG")
61 if apr_config_cmd is None:
62 cmds = ["apr-config", "apr-1-config", "/usr/local/apr/bin/apr-config",
63 "/usr/local/bin/apr-config"]
66 res = run_cmd(cmd, arg)
69 except CommandException, e:
73 raise Exception("apr-config not found."
74 " Please set APR_CONFIG environment variable")
76 res = run_cmd(apr_config_cmd, arg)
80 """Determine the APR header file location."""
81 includedir = apr_config("--includedir")
82 if not os.path.isdir(includedir):
83 raise Exception("APR development headers not found")
84 ldflags = filter(lambda x: x != "", apr_config("--link-ld").split(" "))
85 return (includedir, ldflags)
88 """Determine the Subversion header file location."""
89 if "SVN_HEADER_PATH" in os.environ and "SVN_LIBRARY_PATH" in os.environ:
90 return ([os.getenv("SVN_HEADER_PATH")], [os.getenv("SVN_LIBRARY_PATH")], [])
91 svn_prefix = os.getenv("SVN_PREFIX")
92 if svn_prefix is None:
93 basedirs = ["/usr/local", "/usr"]
94 for basedir in basedirs:
95 includedir = os.path.join(basedir, "include/subversion-1")
96 if os.path.isdir(includedir):
99 if svn_prefix is not None:
100 return ([os.path.join(svn_prefix, "include/subversion-1")],
101 [os.path.join(svn_prefix, "lib")], [])
102 raise Exception("Subversion development files not found. "
103 "Please set SVN_PREFIX or (SVN_LIBRARY_PATH and SVN_HEADER_PATH) environment variable. ")
105 # Windows versions - we use environment variables to locate the directories
106 # and hard-code a list of libraries.
108 # just clobber the functions above we can't use
109 # for simplicitly, everything is done in the 'svn' one
110 def apr_build_data():
113 def svn_build_data():
114 # environment vars for the directories we need.
115 svn_dev_dir = os.environ.get("SVN_DEV")
116 if not svn_dev_dir or not os.path.isdir(svn_dev_dir):
118 "Please set SVN_DEV to the location of the svn development "
119 "packages.\nThese can be downloaded from:\n"
120 "http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91")
121 svn_bdb_dir = os.environ.get("SVN_BDB")
122 if not svn_bdb_dir or not os.path.isdir(svn_bdb_dir):
124 "Please set SVN_BDB to the location of the svn BDB packages "
125 "- see README.txt in the SV_DEV dir")
126 svn_libintl_dir = os.environ.get("SVN_LIBINTL")
127 if not svn_libintl_dir or not os.path.isdir(svn_libintl_dir):
129 "Please set SVN_LIBINTL to the location of the svn libintl "
130 "packages - see README.txt in the SV_DEV dir")
134 os.path.join(svn_dev_dir, r"include\apr"),
135 os.path.join(svn_dev_dir, r"include\apr-utils"),
136 os.path.join(svn_dev_dir, r"include\apr-iconv"),
138 os.path.join(svn_dev_dir, "include"),
141 os.path.join(svn_dev_dir, "lib"),
142 os.path.join(svn_dev_dir, "lib", "apr"),
143 os.path.join(svn_dev_dir, "lib", "apr-iconv"),
144 os.path.join(svn_dev_dir, "lib", "apr-util"),
145 os.path.join(svn_dev_dir, "lib", "neon"),
146 os.path.join(svn_bdb_dir, "lib"),
147 os.path.join(svn_libintl_dir, "lib"),
149 libs = """libapr libapriconv libaprutil libneon
150 libsvn_subr-1 libsvn_client-1 libsvn_ra-1
151 libsvn_ra_dav-1 libsvn_ra_local-1 libsvn_ra_svn-1
152 libsvn_repos-1 libsvn_wc-1 libsvn_delta-1 libsvn_diff-1
153 libsvn_fs-1 libsvn_repos-1 libsvn_fs_fs-1 libsvn_fs_base-1
156 advapi32 shell32 ws2_32 zlibstat
159 return includes, lib_dirs, libs,
161 (apr_includedir, apr_ldflags) = apr_build_data()
162 (svn_includedirs, svn_libdirs, extra_libs) = svn_build_data()
164 def SvnExtension(name, *args, **kwargs):
165 kwargs["include_dirs"] = [apr_includedir] + svn_includedirs
166 kwargs["library_dirs"] = svn_libdirs
167 kwargs["extra_link_args"] = apr_ldflags
169 # on windows, just ignore and overwrite the libraries!
170 kwargs["libraries"] = extra_libs
171 # APR needs WIN32 defined.
172 kwargs["define_macros"] = [("WIN32", None)]
173 return Extension("bzrlib.plugins.svn.%s" % name, *args, **kwargs)
175 # On Windows, we install the apr binaries too.
176 class install_lib_with_dlls(install_lib):
178 # return a list of of (FQ-in-name, relative-out-name) tuples.
180 apr_bins = "libaprutil.dll libapriconv.dll libapr.dll".split()
181 look_dirs = os.environ.get("PATH","").split(os.pathsep)
182 look_dirs.insert(0, os.path.join(os.environ["SVN_DEV"], "bin"))
185 for look in look_dirs:
186 f = os.path.join(look, bin)
187 if os.path.isfile(f):
188 target = os.path.join(self.install_dir, "bzrlib",
189 "plugins", "svn", bin)
190 ret.append((f, target))
193 log.warn("Could not find required DLL %r to include", bin)
194 log.debug("(looked in %s)", look_dirs)
198 install_lib.run(self)
201 # On Windows we package up the apr dlls with the plugin.
202 for s, d in self._get_dlls():
205 def get_outputs(self):
206 ret = install_lib.get_outputs()
208 ret.extend([info[1] for info in self._get_dlls()])
211 setup(name='bzr-svn',
212 description='Support for Subversion branches in Bazaar',
213 keywords='plugin bzr svn',
214 version='0.4.11~rc1',
215 url='http://bazaar-vcs.org/BzrForeignBranches/Subversion',
216 download_url='http://bazaar-vcs.org/BzrSvn',
218 author='Jelmer Vernooij',
219 author_email='jelmer@samba.org',
221 This plugin adds support for branching off and
222 committing to Subversion repositories from
225 package_dir={'bzrlib.plugins.svn':'.',
226 'bzrlib.plugins.svn.tests':'tests'},
227 packages=['bzrlib.plugins.svn',
228 'bzrlib.plugins.svn.mapping3',
229 'bzrlib.plugins.svn.tests'],
231 SvnExtension("client", ["client.c", "editor.c", "util.c", "ra.c", "wc.c"], libraries=["svn_client-1", "svn_subr-1"]),
232 SvnExtension("ra", ["ra.c", "util.c", "editor.c"], libraries=["svn_ra-1", "svn_delta-1", "svn_subr-1"]),
233 SvnExtension("repos", ["repos.c", "util.c"], libraries=["svn_repos-1", "svn_subr-1"]),
234 SvnExtension("wc", ["wc.c", "util.c", "editor.c"], libraries=["svn_wc-1", "svn_subr-1"]),
236 cmdclass = { 'install_lib': install_lib_with_dlls },