文系プログラマによるTIPSブログ

文系プログラマ脳の私が開発現場で学んだ事やプログラミングのTIPSをまとめています。

macのsvnにhomebrewで--unicode-pathを適用する際の罠

以前、以下の記事を書きました。

これは、macでjdk1.7を入れると、JAVA_HOMEや文字コードの設定が効かなくな話題です。
今回はそれに関連し、
macのeclipseでsvnチェックアウトしたファイルの濁点がおかしい
点についての話題です。

ネットで検索してみると、以下のサイトがヒットしました。
MacでのUTF-8-MAC問題を解決する - selflearn @ ウィキ - アットウィキ
要約すると、winとmacで濁点の扱いが違うからファイルの扱いがおかしくなるのです。
これはsvnにパッチを当てると解決するのですが、色々と問題がある事が解りました。
それについて記述していきます。

※ 記事の最後に驚愕の事実が判明します。ご注意下さい。

svnに--unicode-pathを適用する

macには標準でsvnが入っていますが、それはパッチが当たっていないので、
別途パッチを当てたsvnをインストールする事になります。

brew updateする

今回はHomeBrewを使います。MacPortsは重複してアプリがインストールされたりして無駄が多いので、
HomeBrewにします。

まずはbrew updateしてformulaを最新化しましょう。

localhost:~ tree$ brew update
Updated Homebrew from 24ae3a86 to 8acc7e6e.
==> New Formulae
alembic         dmalloc     gupnp         libxc     mussh         rbenv-binstubs    suricata        xml-security-c
・・・略・・・
==> Updated Formulae
abcl          chruby      eina          glib      hwloc         libglademm      lua         nickle
・・・略・・・
==> Deleted Formulae
clojure      fastri       libpurple      perforce       perforce-proxy       perforce-server        ruby-odbc          v8cgi      yubikey-personalization

これでOKです。

brew installしてみる

何も考えずにいきなりパッチ済みsvnをinstallしてみます。

localhost:~ tree$ brew install --unicode-path --java subversion
==> Downloading http://archive.apache.org/dist/subversion/subversion-1.8.0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/subversion-1.8.0.tar.bz2
==> Patching
patching file subversion/bindings/swig/perl/native/Makefile.PL.in
patching file Makefile.in
Error: The --unicode-path patch is not supported on Subversion 1.8.

Upgrading from a 1.7 version built with this patch is not supported.

You should stay on 1.7, install 1.7 from homebrew-versions, or
  brew rm subversion && brew install subversion
to build a new version of 1.8 without this patch.

ver1.8は対応してないよ、だから1.7系にしてね、だそうです。

ver1.7系最新のsvnをインストールする

バージョン指定でインストールするコマンドはHomeBrewが教えてくれます。

localhost:~ tree$ brew versions svn
1.8.0    git checkout d6209c6 /usr/local/Library/Formula/subversion.rb
1.8.1    git checkout 55577bb /usr/local/Library/Formula/subversion.rb
1.7.10   git checkout 0060dc3 /usr/local/Library/Formula/subversion.rb
1.7.9    git checkout b0e6223 /usr/local/Library/Formula/subversion.rb
1.7.8    git checkout f7a42d2 /usr/local/Library/Formula/subversion.rb
1.7.7    git checkout a6dcc41 /usr/local/Library/Formula/subversion.rb
1.7.6    git checkout 6b8d25f /usr/local/Library/Formula/subversion.rb
1.7.5    git checkout 5d5cd70 /usr/local/Library/Formula/subversion.rb
1.7.4    git checkout dc4245c /usr/local/Library/Formula/subversion.rb
1.7.3    git checkout eb97154 /usr/local/Library/Formula/subversion.rb
1.7.2    git checkout d89bf83 /usr/local/Library/Formula/subversion.rb
1.6.17   git checkout 6e2d550 /usr/local/Library/Formula/subversion.rb
1.6.16   git checkout 83ed494 /usr/local/Library/Formula/subversion.rb
1.6.15   git checkout 809a18a /usr/local/Library/Formula/subversion.rb
1.6.13   git checkout 7871a99 /usr/local/Library/Formula/subversion.rb
1.6.12   git checkout c99b3ac /usr/local/Library/Formula/subversion.rb
1.6.6    git checkout 8774131 /usr/local/Library/Formula/subversion.rb

例えば1.7.10をインストールしたい場合は↓こうです。

git checkout 0060dc3 /usr/local/Library/Formula/subversion.rb

先ほど1.8系はダメと怒られたので、1.7.10をインストールしてみます。
gitはmacに標準インストールされているので、そのままコマンドを実行します。

localhost:~ tree$ git checkout 0060dc3 /usr/local/Library/Formula/subversion.rb
fatal: Not a git repository (or any of the parent directories): .git

あら?なんか怒られました。調べてみると、Formulaフォルダに移動してから実行する必要があるそうです。

localhost:~ tree$ cd /usr/local/Library/Formula
localhost:Formula tree$ git checkout 0060dc3 /usr/local/Library/Formula/subversion.rb

パッと見何も変わっていませんが、subversion.rbがバージョン毎に中身が書き換わります。
今はインストールスクリプトであるsubversion.rbを1.7.10に切り替えたので
早速インストールしてみます。

localhost:Formula tree$ brew install --unicode-path --java subversion
==> Installing subversion dependency: neon
==> Downloading http://www.webdav.org/neon/neon-0.29.6.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/neon/0.29.6 --enable-shared --disable-static --disable-nls --with-ssl
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Compiling newer versions of Subversion on 10.6 require this newer neon.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/neon/lib
    CPPFLAGS: -I/usr/local/opt/neon/include

==> Summary
🍺  /usr/local/Cellar/neon/0.29.6: 174 files, 1.4M, built in 21 seconds
==> Installing subversion dependency: readline
==> Downloading http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz
######################################################################## 100.0%
==> Patching
patching file callback.c
patching file input.c
patching file patchlevel
patching file support/shobj-conf
patching file vi_mode.c
==> ./configure --prefix=/usr/local/Cellar/readline/6.2.4 --mandir=/usr/local/Cellar/readline/6.2.4/share/man --infodir=/usr/local/Cellar/readline/6.2.4/share/info --enable-multibyte
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
🍺  /usr/local/Cellar/readline/6.2.4: 31 files, 1.6M, built in 16 seconds
==> Installing subversion dependency: sqlite
==> Downloading http://sqlite.org/2013/sqlite-autoconf-3071700.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sqlite/3.7.17 --enable-dynamic-extensions
==> make install
^@==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/sqlite/lib
    CPPFLAGS: -I/usr/local/opt/sqlite/include

==> Summary
🍺  /usr/local/Cellar/sqlite/3.7.17: 9 files, 2.0M, built in 33 seconds
==> Installing subversion dependency: serf
==> Downloading http://serf.googlecode.com/files/serf-1.2.1.tar.bz2
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/serf/1.2.1 --with-apr=/usr/local/Library/ENV/4.3
==> make install
🍺  /usr/local/Cellar/serf/1.2.1: 11 files, 356K, built in 6 seconds
==> Installing subversion
==> Downloading http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.7.10.tar.bz2
==> Best Mirror http://ftp.riken.jp/net/apache/subversion/subversion-1.7.10.tar.bz2

curl: (22) The requested URL returned error: 404
Error: Download failed: http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.7.10.tar.bz2
localhost:Formula tree$

ファッ!?
404ってなんだ・・・

svnのDownloadの404を修正する

ミラーサイト含めて404とかふざけた事を言われたので、インストールスクリプトを修正します。

vi /usr/local/Library/Formula/subversion.rb

  url 'http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.7.10.tar.bz2'
  sha1 'a4f3de0a13b034b0eab4d35512c6c91a4abcf4f5'

↓↓↓ 以下のように修正 ↓↓↓

#  url 'http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.7.10.tar.bz2'
#  sha1 'a4f3de0a13b034b0eab4d35512c6c91a4abcf4f5'
  url "http://mirror.symnds.com/software/Apache/subversion/subversion-1.7.11.tar.bz2"
  sha1 'd82e187803043b74c072cd5a861ac02e4a027684'

urlとsha1は http://archive.apache.org/dist/subversion/ 等から選択して下さい。
(さり気なくversion1.7.11にしていますが動きます)
修正したのでインストールしてみます。

localhost:Formula tree$ brew install --unicode-path --java subversion
==> Downloading http://mirror.symnds.com/software/Apache/subversion/subversion-1.7.11.tar.bz2
Already downloaded: /Library/Caches/Homebrew/subversion-1.7.11.tar.bz2
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file subversion/libsvn_subr/path.c
Warning: A non-Universal Java build was requested.
To use Java bindings with various Java IDEs, you might need a universal build:
  brew install subversion --universal --java
Warning: JAVA_HOME is set. Try unsetting it if JNI headers cannot be found.
Error: undefined local variable or method `superbin' for subversion:Subversion
Please report this bug:
    https://github.com/mxcl/homebrew/wiki/troubleshooting
/usr/local/Library/Formula/subversion.rb:57:in `apr_bin'
/usr/local/Library/Formula/subversion.rb:84:in `install'
/usr/local/Library/Homebrew/build.rb:172:in `install'
/usr/local/Library/Homebrew/formula.rb:239:in `brew'
/usr/local/Library/Homebrew/formula.rb:600:in `stage'
/usr/local/Library/Homebrew/extend/fileutils.rb:21:in `mktemp'
/usr/local/Library/Homebrew/formula.rb:596:in `stage'
/usr/local/Library/Homebrew/formula.rb:234:in `brew'
/usr/local/Library/Homebrew/build.rb:151:in `install'
/usr/local/Library/Homebrew/build.rb:44:in `main'
/usr/local/Library/Homebrew/build.rb:12
/usr/local/Library/Formula/subversion.rb:164

(#^ω^) ・・・・
もはやキレる寸前です。
なんか「superbinっていう変数は未定義だぞコラ!」だそうです。
subversion.rb は単なるrubyスクリプトなので、superbinとやらを何とかします。

vi /usr/local/Library/Formula/subversion.rb

  def apr_bin
#    superbin or "/usr/bin" ← このsuperbinが存在しない
    "/usr/bin" # こう修正します
  end

superbinとやらは抹殺しました。では再チャレンジ。

localhost:Formula tree$ brew install --unicode-path --java subversion
==> Downloading http://mirror.symnds.com/software/Apache/subversion/subversion-1.7.11.tar.bz2
Already downloaded: /Library/Caches/Homebrew/subversion-1.7.11.tar.bz2
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file subversion/libsvn_subr/path.c
Warning: A non-Universal Java build was requested.
To use Java bindings with various Java IDEs, you might need a universal build:
  brew install subversion --universal --java
Warning: JAVA_HOME is set. Try unsetting it if JNI headers cannot be found.
==> ./configure --prefix=/usr/local/Cellar/subversion/1.7.11 --with-apr=/usr/bin --with-ssl --with-zlib=/usr --with-sqlite=/usr/local/opt/sqlite --with-serf=/usr/local/opt/serf --disable-neon-version-check --disable-mod-activati
==> make
^@^@==> make install
==> make tools
==> make install-tools
==> make javahl
^@==> make install-javahl
==> Caveats
You may need to link the Java bindings into the Java Extensions folder:
  sudo mkdir -p /Library/Java/Extensions
  sudo ln -s /usr/local/lib/libsvnjavahl-1.dylib /Library/Java/Extensions/libsvnjavahl-1.dylib

This unicode-path version implements a hack to deal with composed/decomposed
unicode handling on Mac OS X which is different from linux and windows.
It is an implementation of solution 1 from
http://svn.collab.net/repos/svn/trunk/notes/unicode-composition-for-filenames
which _WILL_ break some setups. Please be sure you understand what you
are asking for when you install this version.


Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
Warning: Could not link subversion. Unlinking...
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link subversion'

Possible conflicting files are:
/usr/local/bin/svnversion
/usr/local/bin/svnsync
/usr/local/bin/svnserve
/usr/local/bin/svnlook
/usr/local/bin/svndumpfilter
/usr/local/bin/svnadmin
/usr/local/bin/svn
/usr/local/include/subversion-1/svn_xml.h
/usr/local/include/subversion-1/svn_wc.h
/usr/local/include/subversion-1/svn_version.h
/usr/local/include/subversion-1/svn_utf.h
/usr/local/include/subversion-1/svn_user.h
/usr/local/include/subversion-1/svn_types.h
/usr/local/include/subversion-1/svn_time.h
/usr/local/include/subversion-1/svn_subst.h
/usr/local/include/subversion-1/svn_string.h
/usr/local/include/subversion-1/svn_sorts.h
/usr/local/include/subversion-1/svn_repos.h
/usr/local/include/subversion-1/svn_ra_svn.h
/usr/local/include/subversion-1/svn_ra.h
/usr/local/include/subversion-1/svn_quoprint.h
/usr/local/include/subversion-1/svn_props.h
/usr/local/include/subversion-1/svn_pools.h
/usr/local/include/subversion-1/svn_path.h
/usr/local/include/subversion-1/svn_opt.h
/usr/local/include/subversion-1/svn_nls.h
/usr/local/include/subversion-1/svn_mergeinfo.h
/usr/local/include/subversion-1/svn_md5.h
/usr/local/include/subversion-1/svn_iter.h
/usr/local/include/subversion-1/svn_io.h
/usr/local/include/subversion-1/svn_hash.h
/usr/local/include/subversion-1/svn_fs.h
/usr/local/include/subversion-1/svn_error_codes.h
/usr/local/include/subversion-1/svn_error.h
/usr/local/include/subversion-1/svn_dso.h
/usr/local/include/subversion-1/svn_dirent_uri.h
/usr/local/include/subversion-1/svn_diff.h
/usr/local/include/subversion-1/svn_delta.h
/usr/local/include/subversion-1/svn_dav.h
/usr/local/include/subversion-1/svn_ctype.h
/usr/local/include/subversion-1/svn_config.h
/usr/local/include/subversion-1/svn_compat.h
/usr/local/include/subversion-1/svn_cmdline.h
/usr/local/include/subversion-1/svn_client.h
/usr/local/include/subversion-1/svn_checksum.h
/usr/local/include/subversion-1/svn_base64.h
/usr/local/include/subversion-1/svn_auth.h
/usr/local/include/subversion-1/svn-revision.txt
/usr/local/include/subversion-1/mod_dav_svn.h
/usr/local/include/subversion-1/mod_authz_svn.h
/usr/local/share/man/man8/svnserve.8
/usr/local/share/man/man5/svnserve.conf.5
/usr/local/share/man/man1/svnversion.1
/usr/local/share/man/man1/svnsync.1
/usr/local/share/man/man1/svnlook.1
/usr/local/share/man/man1/svndumpfilter.1
/usr/local/share/man/man1/svnadmin.1
/usr/local/share/man/man1/svn.1
/usr/local/lib/libsvn_wc-1.dylib -> /usr/local/lib/libsvn_wc-1.0.0.0.dylib
/usr/local/lib/libsvn_wc-1.a
/usr/local/lib/libsvn_wc-1.0.dylib -> /usr/local/lib/libsvn_wc-1.0.0.0.dylib
/usr/local/lib/libsvn_subr-1.dylib -> /usr/local/lib/libsvn_subr-1.0.0.0.dylib
/usr/local/lib/libsvn_subr-1.a
/usr/local/lib/libsvn_subr-1.0.dylib -> /usr/local/lib/libsvn_subr-1.0.0.0.dylib
/usr/local/lib/libsvn_repos-1.dylib -> /usr/local/lib/libsvn_repos-1.0.0.0.dylib
/usr/local/lib/libsvn_repos-1.a
/usr/local/lib/libsvn_repos-1.0.dylib -> /usr/local/lib/libsvn_repos-1.0.0.0.dylib
/usr/local/lib/libsvn_ra_svn-1.dylib -> /usr/local/lib/libsvn_ra_svn-1.0.0.0.dylib
/usr/local/lib/libsvn_ra_svn-1.a
/usr/local/lib/libsvn_ra_svn-1.0.dylib -> /usr/local/lib/libsvn_ra_svn-1.0.0.0.dylib
/usr/local/lib/libsvn_ra_local-1.dylib -> /usr/local/lib/libsvn_ra_local-1.0.0.0.dylib
/usr/local/lib/libsvn_ra_local-1.a
/usr/local/lib/libsvn_ra_local-1.0.dylib -> /usr/local/lib/libsvn_ra_local-1.0.0.0.dylib
/usr/local/lib/libsvn_ra-1.dylib -> /usr/local/lib/libsvn_ra-1.0.0.0.dylib
/usr/local/lib/libsvn_ra-1.a
/usr/local/lib/libsvn_ra-1.0.dylib -> /usr/local/lib/libsvn_ra-1.0.0.0.dylib
/usr/local/lib/libsvn_fs_util-1.dylib -> /usr/local/lib/libsvn_fs_util-1.0.0.0.dylib
/usr/local/lib/libsvn_fs_util-1.a
/usr/local/lib/libsvn_fs_util-1.0.dylib -> /usr/local/lib/libsvn_fs_util-1.0.0.0.dylib
/usr/local/lib/libsvn_fs_fs-1.dylib -> /usr/local/lib/libsvn_fs_fs-1.0.0.0.dylib
/usr/local/lib/libsvn_fs_fs-1.a
/usr/local/lib/libsvn_fs_fs-1.0.dylib -> /usr/local/lib/libsvn_fs_fs-1.0.0.0.dylib
/usr/local/lib/libsvn_fs-1.dylib -> /usr/local/lib/libsvn_fs-1.0.0.0.dylib
/usr/local/lib/libsvn_fs-1.a
/usr/local/lib/libsvn_fs-1.0.dylib -> /usr/local/lib/libsvn_fs-1.0.0.0.dylib
/usr/local/lib/libsvn_diff-1.dylib -> /usr/local/lib/libsvn_diff-1.0.0.0.dylib
/usr/local/lib/libsvn_diff-1.a
/usr/local/lib/libsvn_diff-1.0.dylib -> /usr/local/lib/libsvn_diff-1.0.0.0.dylib
/usr/local/lib/libsvn_delta-1.dylib -> /usr/local/lib/libsvn_delta-1.0.0.0.dylib
/usr/local/lib/libsvn_delta-1.a
/usr/local/lib/libsvn_delta-1.0.dylib -> /usr/local/lib/libsvn_delta-1.0.0.0.dylib
/usr/local/lib/libsvn_client-1.dylib -> /usr/local/lib/libsvn_client-1.0.0.0.dylib
/usr/local/lib/libsvn_client-1.a
/usr/local/lib/libsvn_client-1.0.dylib -> /usr/local/lib/libsvn_client-1.0.0.0.dylib
==> Summary
🍺  /usr/local/Cellar/subversion/1.7.11: 109 files, 8.5M, built in 3.8 minutes
localhost:Formula tree$

(#^ω^) タヒね
今度は
You can try again using `brew link subversion'
とのことなのでbrew link subversionを実行してみます。

localhost:Formula tree$ brew link subversion
Linking /usr/local/Cellar/subversion/1.7.11... Warning: Could not link subversion. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/subversion/1.7.11/bin/svnversion
Target /usr/local/bin/svnversion already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
  brew link --overwrite formula_name

To list all files that would be deleted:
  brew link --overwrite --dry-run formula_name

(#^ω^) タヒね
/usr/local/bin/svnversion already exists だそうです。
brew link --overwrite --dry-run formula_name ともあるので、上書きオプション付けて再実行。

localhost:Formula tree$ brew link --overwrite subversion
Linking /usr/local/Cellar/subversion/1.7.11... 114 symlinks created

ようやく完了です!
このsymlinkでsvnコマンドが実行できるようになります!

localhost:Formula tree$ which svn
/usr/bin/svn
localhost:Formula tree$ svn --version
svn, version 1.6.18 (r1303927)
   compiled Aug  4 2012, 19:46:53

(#^ω^)ver1.6のままじゃねえか

インストールしたsvnに切り替える

HomeBrewでインストールしたソフトへのパスを通します。

localhost:~ tree$ vi ~/.bash_profile

if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi

export JAVA_HOME=/usr/local/java
export HUDSON_HOME=/var/lib/jenkins
export JENKINS_HOME=/var/lib/jenkins

export PATH=$PATH:/usr/local/mysql/bin
export PATH=$PATH:/usr/local/groovy/bin
export PATH=$PATH:/usr/local/gradle/bin
export PATH=$PATH:/usr/local/bin

このままだと/usr/local/binは最後に読み込まれてしまうので、
/usr/binより先に読み込まれるように /etc/paths を以下のように編集します。

sudo vi /etc/paths

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

/etc/paths編集後、macを再起動して、再度svnのバージョンを確認します。

localhost:~ tree$ svn --version
svn, version 1.7.11 (r1503888)
   compiled Aug 20 2013, 21:51:22

( ^ω^)ついにやったか・・・

おめでとうございます!ようやく--unicode-path適用済のsvnをインストールできました!

eclipseに戻る

これで準備が整いました。ではeclipse経由でsvnチェックアウトして濁点問題を確認してみましょう。

再度eclipseからsvn checkoutしてみよう

一旦前削除して、再度チェックアウトしてみます。
・・
・・・
・・・・
(;^ω^)あ、アレ・・・?
解決してない。あれ???
あそうか、eclipseに内蔵されたsvnクライアントはさっきインストールしたsvn使わず内蔵svn使ってるからかな。
(;^ω^)あ・・・ハイ・・・

最終的に

さて、ここまできてeclipse経由だと濁点問題が回避できない事が解りました。
subclipseもsubversiveも、使用するsvnのバイナリパスを指定する事ができません。
従ってeclipseに内蔵されたsvnクライアントが使用されてしまい、どうにもなりません。

これはつまり、
svnのパスを指定できるクライアントがあれば問題解決なのでは?
ということで早速以下をインストールしました。
Google Code Archive - Long-term storage for Google Code Project Hosting.
これをクライアントとして使用したところ、ようやく濁点問題は解決できました。疲れました・・・



このままではeclipse上で作業できず非常に効率が悪いのですが、
どなたかこの問題が解決できた方がいらっしゃったら是非解決方法教えて下さい!!
Eclipse 4.2 完全攻略

Eclipse 4.2 完全攻略

Eclipse4.2ではじめるJavaプログラミング入門Eclipse4.2Juno対応

Eclipse4.2ではじめるJavaプログラミング入門Eclipse4.2Juno対応