LoginSignup
6
6

More than 5 years have passed since last update.

Go for Windows: ビルド時に「Git の」バージョン情報を埋め込みたい

Posted at

よーし、おじさんも、Git のリビジョン番号を埋め込んじゃうぞー!

Makefile
build :
    for /F %%V IN ('git log -1 --pretty^=format:%%H') DO go build -ldflags "-X main.version [SNAPSHOT-%DATE:/=%-%%V]"

すまない、nmake 以外は帰ってくれないか?

  • これで main.version という変数に [SNAPSHOT-(ビルド日付)-(gitのリビジョン)] という値が設定される
  • git のオプションは--pretty=format:%H なんだけど、%で囲まれた範囲に = があると置換だと CMD.EXE が判断してしまうので、^= をエスケープする。

なお、Go側のコードについては、元記事を読んだ方が身のためだ。

まぁ、それにしても Go タグがついてるけど、Go のコード全然出てこないね!どちらかというとバッチ芸…

以上

6
6
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
6
6