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 svn_prefix = os.getenv("SVN_PREFIX")
90 if svn_prefix is None:
91 basedirs = ["/usr/local", "/usr"]
92 for basedir in basedirs:
93 includedir = os.path.join(basedir, "include/subversion-1")
94 if os.path.isdir(includedir):
97 if svn_prefix is not None:
98 return ([os.path.join(basedir, "include/subversion-1")],
99 [os.path.join(basedir, "lib")], [])
100 raise Exception("Subversion development files not found. "
101 "Please set SVN_PREFIX environment variable. ")
103 # Windows versions - we use environment variables to locate the directories
104 # and hard-code a list of libraries.
106 # just clobber the functions above we can't use
107 # for simplicitly, everything is done in the 'svn' one
108 def apr_build_data():
111 def svn_build_data():
112 # environment vars for the directories we need.
113 svn_dev_dir = os.environ.get("SVN_DEV")
114 if not svn_dev_dir or not os.path.isdir(svn_dev_dir):
116 "Please set SVN_DEV to the location of the svn development "
117 "packages.\nThese can be downloaded from:\n"
118 "http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91")
119 svn_bdb_dir = os.environ.get("SVN_BDB")
120 if not svn_bdb_dir or not os.path.isdir(svn_bdb_dir):
122 "Please set SVN_BDB to the location of the svn BDB packages "
123 "- see README.txt in the SV_DEV dir")
124 svn_libintl_dir = os.environ.get("SVN_LIBINTL")
125 if not svn_libintl_dir or not os.path.isdir(svn_libintl_dir):
127 "Please set SVN_LIBINTL to the location of the svn libintl "
128 "packages - see README.txt in the SV_DEV dir")
132 os.path.join(svn_dev_dir, r"include\apr"),
133 os.path.join(svn_dev_dir, r"include\apr-utils"),
134 os.path.join(svn_dev_dir, r"include\apr-iconv"),
136 os.path.join(svn_dev_dir, "include"),
139 os.path.join(svn_dev_dir, "lib"),
140 os.path.join(svn_dev_dir, "lib", "apr"),
141 os.path.join(svn_dev_dir, "lib", "apr-iconv"),
142 os.path.join(svn_dev_dir, "lib", "apr-util"),
143 os.path.join(svn_dev_dir, "lib", "neon"),
144 os.path.join(svn_bdb_dir, "lib"),
145 os.path.join(svn_libintl_dir, "lib"),
147 libs = """libapr libapriconv libaprutil libneon
148 libsvn_subr-1 libsvn_client-1 libsvn_ra-1
149 libsvn_ra_dav-1 libsvn_ra_local-1 libsvn_ra_svn-1
150 libsvn_repos-1 libsvn_wc-1 libsvn_delta-1 libsvn_diff-1
151 libsvn_fs-1 libsvn_repos-1 libsvn_fs_fs-1 libsvn_fs_base-1
154 advapi32 shell32 ws2_32 zlibstat
157 return includes, lib_dirs, libs,
159 (apr_includedir, apr_ldflags) = apr_build_data()
160 (svn_includedirs, svn_libdirs, extra_libs) = svn_build_data()
162 def SvnExtension(name, *args, **kwargs):
163 kwargs["include_dirs"] = [apr_includedir] + svn_includedirs
164 kwargs["library_dirs"] = svn_libdirs
165 kwargs["extra_link_args"] = apr_ldflags
167 # on windows, just ignore and overwrite the libraries!
168 kwargs["libraries"] = extra_libs
169 # APR needs WIN32 defined.
170 kwargs["define_macros"] = [("WIN32", None)]
171 return Extension("bzrlib.plugins.svn.%s" % name, *args, **kwargs)
173 # On Windows, we install the apr binaries too.
174 class install_lib_with_dlls(install_lib):
176 # return a list of of (FQ-in-name, relative-out-name) tuples.
178 apr_bins = "libaprutil.dll libapriconv.dll libapr.dll".split()
179 look_dirs = os.environ.get("PATH","").split(os.pathsep)
180 look_dirs.insert(0, os.path.join(os.environ["SVN_DEV"], "bin"))
183 for look in look_dirs:
184 f = os.path.join(look, bin)
185 if os.path.isfile(f):
186 target = os.path.join(self.install_dir, "bzrlib",
187 "plugins", "svn", bin)
188 ret.append((f, target))
191 log.warn("Could not find required DLL %r to include", bin)
192 log.debug("(looked in %s)", look_dirs)
196 install_lib.run(self)
199 # On Windows we package up the apr dlls with the plugin.
200 for s, d in self._get_dlls():
203 def get_outputs(self):
204 ret = install_lib.get_outputs()
206 ret.extend([info[1] for info in self._get_dlls()])
209 setup(name='bzr-svn',
210 description='Support for Subversion branches in Bazaar',
211 keywords='plugin bzr svn',
213 url='http://bazaar-vcs.org/BzrForeignBranches/Subversion',
214 download_url='http://bazaar-vcs.org/BzrSvn',
216 author='Jelmer Vernooij',
217 author_email='jelmer@samba.org',
219 This plugin adds support for branching off and
220 committing to Subversion repositories from
223 package_dir={'bzrlib.plugins.svn':'.',
224 'bzrlib.plugins.svn.tests':'tests'},
225 packages=['bzrlib.plugins.svn',
226 'bzrlib.plugins.svn.mapping3',
227 'bzrlib.plugins.svn.tests'],
229 SvnExtension("client", ["client.c", "editor.c", "util.c", "ra.c", "wc.c"], libraries=["svn_client-1", "svn_subr-1"]),
230 SvnExtension("ra", ["ra.c", "util.c", "editor.c"], libraries=["svn_ra-1", "svn_delta-1", "svn_subr-1"]),
231 SvnExtension("repos", ["repos.c", "util.c"], libraries=["svn_repos-1", "svn_subr-1"]),
232 SvnExtension("wc", ["wc.c", "util.c", "editor.c"], libraries=["svn_wc-1", "svn_subr-1"]),
234 cmdclass = { 'install_lib': install_lib_with_dlls },