简体   繁体   English

如何在Mac OS X 10.8上安装hg convert所需的python subversion绑定?

[英]How to install python subversion bindings needed by hg convert on Mac OS X 10.8?

I am looking for a solution, preferably clean and simple, to enable hg convert to work on OS X 10.8 with SVN repositories. 我正在寻找一个解决方案,最好是干净简单,使hg convert能够在带有SVN存储库的OS X 10.8上运行。

Currently, if you try to convert a SVN repository you will get a could not load Subversion python bindings error. 目前,如果您尝试转换SVN存储库,您将could not load Subversion python bindings错误。

Note: Alex Martelli recommended in another answer to install CollabNet subversion distribution for OS X, still it seems that the latest CollabNet version cannot be installed on OS X 10.8 (the installer locks). 注意:Alex Martelli在另一个答案中建议为OS X安装CollabNet subversion发行版,但似乎最新的CollabNet版本无法安装在OS X 10.8上(安装程序锁定)。

Using homebrew 使用自制软件

The easiest way to get this working is to install subversion from source using homebrew and the --with-python flag. 最简单的方法是使用homebrew--with-python标志从源代码安装subversion

First, make sure you have your command-line tools installed. 首先,确保安装了命令行工具。 With Mavericks and Xcode 5, most commands like cc just work even though the command-line tools aren't fully installed. 使用Mavericks和Xcode 5,即使命令行工具未完全安装,大多数命令(如cc也能正常工作。 If you don't have a /usr/include directory, then first you need to run 如果您没有/usr/include目录,那么首先需要运行

$ xcode-select --install

Once your command-line tools are installed, run: 安装命令行工具后,运行:

$ brew install subversion --with-python
$ mkdir -p ~/Library/Python/2.7/lib/python/site-packages
$ echo $(brew --cellar)/subversion/1.8.5/lib/svn-python \
    > ~/Library/Python/2.7/lib/python/site-packages/svn.pth

You can test the bindings by running the unit tests: 您可以通过运行单元测试来测试绑定:

$ svn co http://svn.apache.org/repos/asf/subversion/tags/1.8.5/subversion/bindings/swig/python/tests
$ cd tests && python run_all.py

Using Apple's source code 使用Apple的源代码

This works for Mountain Lion, but needs tweaks for Mavericks and results in failing unit tests; 这适用于Mountain Lion,但需要对Mavericks进行调整并导致单元测试失败; see Simon Wright's answer to this question . 请看Simon Wright对这个问题的回答

It is possible to build the subversion bindings for Python using Apple's version of the subversion source code. 可以使用Apple版本的subversion源代码为Python构建subversion绑定。 The resulting module will be exactly compatible and link against all the system libraries. 生成的模块将完全兼容并链接到所有系统库。 And then hg convert will just work. 然后hg convert将正常工作。

Here's how to do it: 这是怎么做的:

  1. Download the subversion tarball from opensource.apple.com opensource.apple.com下载subversion tarball

  2. Unpack it and configure it: 打开包装并进行配置:

     cd subversion-52/subversion && ./configure 
  3. In subversion/bindings/swig/python , add this Makefile, being sure to change leading whitespace to tabs: subversion/bindings/swig/python ,添加此Makefile,确保将前导空格更改为制表符:

     SHELL = /bin/bash -eu CC = gcc -g -O2 CFLAGS = -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK \\ -I ../proxy \\ -I ../../.. \\ -I ../../../include \\ -I /usr/include/apr-1 \\ -I libsvn_swig_py \\ -I /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 \\ LDFLAGS = \\ /System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib \\ /usr/lib/libsvn_*-1.0.dylib \\ /usr/lib/libapr-1.dylib \\ .PHONY: build egg test clean install test: egg mkdir -p tmp && cd tmp \\ && PYTHONPATH=../egg python -S -m svn.tests.run_all DESTDIR=$(HOME)/Library/Python/2.7/lib/python/site-packages install: egg mkdir -p "${DESTDIR}" rm -rf "$(DESTDIR)/svn.egg" cp -R egg "$(DESTDIR)/svn.egg" echo './svn.egg' > "$(DESTDIR)/svn.pth" egg: build rm -rf egg mkdir egg cp -R svn egg cp -R tests egg/svn touch egg/svn/tests/__init__.py mkdir egg/libsvn cp *.py egg/libsvn cp *.so *.dylib egg/libsvn # https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac for F in egg/libsvn/*.so; do \\ install_name_tool -change libsvn_swig_py.dylib \\ '@loader_path/libsvn_swig_py.dylib' "$$F"; \\ done strip -x egg/libsvn/*.so touch egg/libsvn/__init__.py mkdir -p egg/EGG-INFO echo 'Version: 1.6.8' > egg/EGG-INFO/PKG-INFO build: libsvn_swig_py.dylib _client.so _core.so _delta.so _diff.so _fs.so _ra.so _repos.so _wc.so libsvn_swig_py.dylib: $(CC) $(CFLAGS) -shared -dynamic libsvn_swig_py/swigutil_py.c -o $@ $(LDFLAGS) _client.so: svn_client.c _core.so: core.c _delta.so: svn_delta.c _diff.so: svn_diff.c _fs.so: svn_fs.c _repos.so: svn_repos.c _wc.so: svn_wc.c _%.so: svn_%.c libsvn_swig_py.dylib $(CC) $(CFLAGS) -bundle $^ -o $@ $(LDFLAGS) _%.so: %.c libsvn_swig_py.dylib $(CC) $(CFLAGS) -bundle $^ -o $@ $(LDFLAGS) clean: rm -rf *.o *.so *.dylib *.dSYM 

    Then run make in that directory. 然后在该目录中运行make

  4. If the unit tests passed in the last step, you now have fully-functional Python bindings for subversion! 如果在最后一步中传递了单元测试,那么现在您已经拥有了用于subversion的全功能Python绑定! Run make install if you're happy, and hg convert will start working. 如果你满意的话,运行make installhg convert将开始工作。


As is so often the case, it was easier to rewrite the build system from scratch than to figure out the existing one. 通常情况下,从头开始重写构建系统比找出现有构建系统更容易。

All the scripts from Apple and Subversion really complicate it, but all you really need to do is copy the .py files, build a shared library with the common code, and then build each C-language Python module. 来自Apple和Subversion的所有脚本确实使它复杂化,但您真正需要做的就是复制.py文件,使用公共代码构建共享库,然后构建每个C语言Python模块。 Figuring out which include files and libraries to use is straightforward: try to build it starting without any includes or libraries, and when the build fails, add a reference to the missing include path or library that is causing the build failure. 确定要使用哪些包含文件和库是很简单的:尝试在没有任何包含或库的情况下开始构建它,并且当构建失败时,添加对导致构建失败的缺少包含路径或库的引用。 The tricky part is telling the C-language modules like _core.so where to find the dynamic library of common code. 棘手的部分是告诉C语言模块如_core.so在哪里可以找到公共代码的动态库。

使用MacPorts中的hg,我需要sudo port install subversion-python27bindings

This is an update for Mavericks to andrewdotn's answer above. 这是小牛队对安德鲁多恩上述答案的更新。

Under Mavericks, the only SVN dynamic libraries in /usr/lib (the standard place) are, for example, /usr/lib/libsvn_client-1.0.0.0.dylib . 在Mavericks下, /usr/lib (标准位置)中唯一的SVN动态库是/usr/lib/libsvn_client-1.0.0.0.dylib This library's internal names (find using otool -L ) tell the dynamic loader to look for libsvn_client-1.0.dylib . 该库的内部名称(使用otool -L查找)告诉动态加载程序查找libsvn_client-1.0.dylib Normally this'd also be in /usr/lib as a symlink to the real library. 通常这也是在/usr/lib作为真实库的符号链接。

Try this: 试试这个:

  1. In andrewdotn's Makefile , edit the LDFLAGS (second line) to say 在andrewdotn的Makefile ,编辑LDFLAGS (第二行)来说明

    /Library/Developer/CommandLineTools/usr/lib/libsvn_*-1.0.dylib \\ /Library/Developer/CommandLineTools/usr/lib/libsvn_*-1.0.dylib \\

  2. Set DYLD_LIBRARY_PATH : 设置DYLD_LIBRARY_PATH

    export DYLD_LIBRARY_PATH=/Library/Developer/CommandLineTools/usr/lib export DYLD_LIBRARY_PATH = / Library / Developer / CommandLineTools / usr / lib

then make . 然后make I got 2 errors: 我有2个错误:

======================================================================
ERROR: test_get_pristine_copy_path (svn.tests.wc.SubversionWorkingCopyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../egg/svn/tests/wc.py", line 192, in test_get_pristine_copy_path
    self.assertEqual(path_to_text_base, wc.get_pristine_copy_path(path_to_file))
  File "../egg/libsvn/wc.py", line 2447, in svn_wc_get_pristine_copy_path
    return apply(_wc.svn_wc_get_pristine_copy_path, args)
SubversionException: ("The node '/var/folders/_q/fvnxz46903z9hjh38fz0lyhm0000gs/T/tmp7vMRZu/foo' was not found.", 155010)

======================================================================
ERROR: test_lock (svn.tests.wc.SubversionWorkingCopyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../egg/svn/tests/wc.py", line 48, in test_lock
    lock = wc.add_lock(self.path, core.svn_lock_create(core.Pool()), self.wc)
  File "../egg/libsvn/wc.py", line 2601, in svn_wc_add_lock
    return apply(_wc.svn_wc_add_lock, args)
SubversionException: ('sqlite: LOCK.lock_token may not be NULL', 200035)

----------------------------------------------------------------------

but I installed anyway and hg convert worked fine. 但无论如何我安装和hg convert工作正常。

I suspect you'll need to set DYLD_LIBRARY_PATH as above every time you need to run hg convert ; 我怀疑你每次需要运行hg convert时都需要设置DYLD_LIBRARY_PATH ; hopefully not that often! 希望不是那么经常!

您可以尝试使用带有subvertpy而不是hg convert的hgsubversion。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM