きりかノート 3冊め

おあそびプログラミング

port:rb19-nokogiriがエラーになるとか言われたので対処した

単にバージョン更新すればいいかと思いきや、あれこれありましたよ。

いつからかわからないのだけれど、nokogiriは

  • システムやパッケージシステムで提供されてるlibxmlやlibxsltを使う
  • 自前でビルドする

が選べるようになっており、前者を選ぶときには環境変数 NOKOGIRI_USE_SYSTEM_LIBRARIES を設定してやればよい。で、gemのビルドはMacPortsではdestroot時に行われるので、destroot.env指定してやればよいね、と思ったら期待したとおりにならない。

その理由は、PortGroup rubyの中で

   destroot {
       system -W ${worksrcpath} "${ruby.gem} install \
           --local --force --install-dir ${destroot}${ruby.gemdir} \
           ${distpath}/${distname}.gem"
       :
   }

のように直にgemコマンドが書かれていて、destroot.cmd経由で実行したときと異なり、destroot.envが設定されない。おそらく、destroot.cmdを使っていないのはdestroot.argsなどで"${distpath}/${distname}.gem"のdistpathやdistnameが指定しづらいから。これらの値は一度Portfileを処理してから設定されるので、その後に処理されるbuild {}やdestroot {}の中では値が取得できるが、素で

  destroot.args ${distpath}/${distname}.gem

としてもエラーになってしまう。考えた結果、

   destroot.cmd    ${ruby.gem}
   destroot.target install
   destroot.args   --local --force --install-dir ${destroot}${ruby.gemdir}

   destroot {
       # note: port cannot read $distpath and $distname
       #       outside of destroot {}
       destroot.post_args ${distpath}/${distname}.gem
       command_exec destroot
       :
   }

のようにして、

  • destroot {}の中で、destroot.post_argsの指定を行う。
  • コマンドの実行はcommand_execを経由して行う。

として対応することにした(r112446)。今回調べててcommand_exec知ったのだけど、これはいろいろ便利そうだね。ターゲットを変えて繰り返し実行しなきゃいけないときとか役に立ちそう。

あとnokogiriの依存で追加になってたgem、mini_portileを新規portとして追加して(r112448)おしまいっ。