choosenimを読む - Day0 -


What's this?

これはchoosenimのコードリーディングのログです。執筆は遅めです。
Nimのスキルアップとchoosenimの開発に貢献することを目的としてコードリーディングを始めました。
choosenimの選定理由はNimに多大な貢献をしているdom96さんのコードなら、学ぶことが多いだろうしNimらしい書き方とかも学べそうだなと思ったから。
あとこのissueを見て興味を持った
ログなので言葉が足りないこともあると思います。その際はぜひ修正依頼を投げてください。

What's choosenim?

choosenimはNimコンパイラのバージョンスイッチツールでありツールチェインインストーラーです。
厳密には違いますが、今はPythonのpyenvみたいな感じだと思ってくれればいいです。
https://github.com/dom96/choosenim
下記は、公式リポジトリの説明。

0日目は下準備

0日目はchoosenimを知らない人向けの解説をします。
まず、choosenimのhelpを読んでみましょう。

$ choosenim --help
choosenim: The Nim toolchain installer.

Choose a job. Choose a mortgage. Choose life. Choose Nim.

Usage:
  choosenim <version/path/channel>

Example:
  choosenim 0.16.0
    Installs (if necessary) and selects version 0.16.0 of Nim.
  choosenim stable
    Installs (if necessary) Nim from the stable channel (latest stable release)
    and then selects it.
  choosenim #head
    Installs (if necessary) and selects the latest current commit of Nim.
    Warning: Your shell may need quotes around `#head`: choosenim "#head".
  choosenim ~/projects/nim
    Selects the specified Nim installation.
  choosenim update stable
    Updates the version installed on the stable release channel.
  choosenim versions [--installed]
    Lists the available versions of Nim that choosenim has access to.

Channels:
  stable
    Describes the latest stable release of Nim.
  devel
    Describes the latest development (or nightly) release of Nim taken from
    the devel branch.

Commands:
  update    <version/channel>    Installs the latest release of the specified
                                 version or channel.
  show                           Displays the selected version and channel.
  update    self                 Updates choosenim itself.
  versions  [--installed]        Lists available versions of Nim, passing
                                 `--installed` only displays versions that
                                 are installed locally (no network requests).

Options:
  -h --help             Show this output.
  -y --yes              Agree to every question.
  --version             Show version.
  --verbose             Show low (and higher) priority output.
  --debug               Show debug (and higher) priority output.
  --noColor             Don't colorise output.

  --choosenimDir:<dir>  Specify the directory where toolchains should be
                        installed. Default: ~/.choosenim.
  --nimbleDir:<dir>     Specify the Nimble directory where binaries will be
                        placed. Default: ~/.nimble.
  --firstInstall        Used by install script.

このchoosenimの仕様を大体覚えておきましょう。
たぶんコードを読んでいくうちに、パーサーあたりで出会います。
その時、この引数はなにをするためなのか理解していると読みやすくなると思います(多分)

この仕様を読んだ今のお気持ち

  • [推察]updateがあるので外部との通信が発生するんだろうね
  • [疑問]バージョンスイッチはどうやるんだろう?
    • [補足]ちなみにchoosenimでは~/.choosenim/toolchains/<version>/にツールチェインが置かれる
    • [推察]シンボリックリンクでswitchしてそう。

明日からコードを読む前にsrc配下のファイルを見てみる。

今のお気持ち

  • [感想]choosenim.nimがエントリのやつやな。
  • [疑問]choosenim.nimsはたしかビルドオプションとかconfig.nimsと同じ役割だった気がする
  • [感想]choosenimpkgに色々と分割されてるんだな

今日のまとめ

なんとなくchoosenimの仕様がわかった(小並感)

明日に向けて

  • 明日はいよいよコードを読んでいくぞい!