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
9 class CommandException(Exception):
10 """Encapsulate exit status of apr-config execution"""
11 def __init__(self, msg, cmd, arg, status, val):
12 self.message = msg % (cmd, val)
13 super(CommandException, self).__init__(self.message)
18 return os.WIFEXITED(self.status) and os.WEXITSTATUS(self.status) == 127
20 def run_cmd(cmd, arg):
21 """Run specified command with given arguments, handling status"""
22 f = os.popen("'%s' %s" % (cmd, arg))
23 dir = f.read().rstrip("\n")
27 if os.WIFEXITED(status):
28 code = os.WEXITSTATUS(status)
31 raise CommandException("%s exited with status %d",
32 cmd, arg, status, code)
33 if os.WIFSIGNALED(status):
34 signal = os.WTERMSIG(status)
35 raise CommandException("%s killed by signal %d",
36 cmd, arg, status, signal)
37 raise CommandException("%s terminated abnormally (%d)",
38 cmd, arg, status, status)
41 apr_config_cmd = os.getenv("APR_CONFIG")
42 if apr_config_cmd is None:
43 cmds = ["apr-config", "apr-1-config", "/usr/local/apr/bin/apr-config",
44 "/usr/local/bin/apr-config"]
47 res = run_cmd(cmd, arg)
50 except CommandException, e:
54 raise Exception("apr-config not found."
55 " Please set APR_CONFIG environment variable")
57 res = run_cmd(apr_config_cmd, arg)
61 """Determine the APR header file location."""
62 includedir = apr_config("--includedir")
63 if not os.path.isdir(includedir):
64 raise Exception("APR development headers not found")
65 ldflags = filter(lambda x: x != "", apr_config("--link-ld").split(" "))
66 return (includedir, ldflags)
69 """Determine the Subversion header file location."""
70 basedirs = ["/usr/local", "/usr"]
71 for basedir in basedirs:
72 includedir = os.path.join(basedir, "include/subversion-1")
73 if os.path.isdir(includedir):
74 return (includedir, os.path.join(basedir, "lib"))
75 raise Exception("Subversion development files not found")
77 (apr_includedir, apr_ldflags) = apr_build_data()
78 (svn_includedir, svn_libdir) = svn_build_data()
80 def SvnExtension(*args, **kwargs):
81 kwargs["include_dirs"] = [apr_includedir, svn_includedir]
82 kwargs["library_dirs"] = [svn_libdir]
83 kwargs["extra_link_args"] = apr_ldflags
84 return Extension(*args, **kwargs)
88 description='Support for Subversion branches in Bazaar',
89 keywords='plugin bzr svn',
91 url='http://bazaar-vcs.org/BzrForeignBranches/Subversion',
92 download_url='http://bazaar-vcs.org/BzrSvn',
94 author='Jelmer Vernooij',
95 author_email='jelmer@samba.org',
97 This plugin adds support for branching off and
98 committing to Subversion repositories from
101 package_dir={'bzrlib.plugins.svn':'.',
102 'bzrlib.plugins.svn.tests':'tests'},
103 packages=['bzrlib.plugins.svn',
104 'bzrlib.plugins.svn.mapping3',
105 'bzrlib.plugins.svn.tests'],
107 SvnExtension("client", ["client.c", "editor.c", "util.c", "ra.c", "wc.c"], libraries=["svn_client-1", "svn_subr-1"]),
108 SvnExtension("ra", ["ra.c", "util.c", "editor.c"], libraries=["svn_ra-1", "svn_delta-1", "svn_subr-1"]),
109 SvnExtension("repos", ["repos.c", "util.c"], libraries=["svn_repos-1", "svn_subr-1"]),
110 SvnExtension("wc", ["wc.c", "util.c", "editor.c"], libraries=["svn_wc-1", "svn_subr-1"]),