LoginSignup
3
4

More than 5 years have passed since last update.

Macでprotoc-gen-docを使う

Last updated at Posted at 2015-06-10

protoc-gen-docのインストール&実行メモです

protoc-gen-docとは

この記事を読んでる人には不要かもしれませんが、protoc-gen-docについて軽く説明しておきます。
https://github.com/estan/protoc-gen-doc
protoc-gen-docとは、ProtocolBuffersの定義ファイル(.proto)からドキュメントを生成してくれるプラグインです。

https://code.google.com/p/protoc-gen-docbook/
ちなみに似たようなprotocプラグインにprotoc-gen-docbookというのがありますが、名前のとおりDocbook形式(PDF)しか出力できない模様。
protoc-gen-docbookは使っていないので、嘘ついてるかもしれません。

前提(環境)

項目 説明
OS MacOSX Yosemite 10.10.3
検証日時 2015.06.10

インストール

Macにインストールする場合はソースからビルドする必要があります。ビルドにはQt5が必要。(これが若干つらいw)

以下インストール手順です。

$ brew install qt5
$ git clone https://github.com/estan/protoc-gen-doc.git
$ cd protoc-gen-doc
$ PROTOBUF_PREFIX=/usr/local/Cellar/protobuf/2.6.1 qmake
$ make && make install

protobufのプレフィクスはバージョンに合わせて変えてください。

実行

protocの使い方は知ってる前提で。
READMEにも書いてるんですが、以下のような形でオプション指定すると使えます。

--doc_out=<出力形式>,<出力ファイル>:<出力ディレクトリ>

$ mkdir docs
$ protoc --doc_out=html,index.html:docs proto/*.proto

.protoファイルの指定とかは適宜変えてください。

出力例は以下にありますね。いい感じです。
https://rawgit.com/estan/protoc-gen-doc/master/examples/doc/example.html

Ex

Q.最終更新日がわからない

A. sed芸を使う

NOW=`date`
sed -i -e "s/<\/body>/<p><hr\/>Last Update: ${NOW}<\/p><\/body>/g" docs/index.html

おわり

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4