More Related Content Similar to 実践Go ツールの作成から配布まで (20) 実践Go ツールの作成から配布まで9. ʕ◔ϖ◔ʔ < Go!
$ go run xxx.go # コンパイル&実行(main関数を含むgoファイルを指定)
$ go test ./... # すべてのパッケージのテストを実行
$ go build # コンパイル
14. bin/
go-ls # 実行コマンド (mainパッケージ)
pkg/
darwin_amd64/ # アーキテクチャ
github.com/user/
go-ls.a # パッケージオブジェクト (自作パッケージ)
• go installはsrc配下からパッケージを探してコンパイルする
ʕ◔ϖ◔ʔ < Go!
18. $ go get
github.com/user/package_name
• go get は src配下にリポジトリからソースを取得後、コンパ
イルを行う
21. $ brew tap user/formula
$ brew install formula
• 独自formulaをつくって、tapで追加する
• 依存関係に`go`を入れておけば、Goの開発環境も一緒に構築
してくれる
22. require 'formula'
!
HOMEBREW_PT_VERSION='1.7.1'
class Pt < Formula # Formulaクラスを継承
homepage 'https://github.com/monochromegane/the_platinum_searcher'
url ‘https://github.com/monochromegane/the_platinum_searcher.git',
:tag => "v#{HOMEBREW_PT_VERSION}"
version HOMEBREW_PT_VERSION
!
depends_on 'go' => :build # ビルド時のみGoをインストール
depends_on 'hg' => :build # 外部パッケージがcode.google.comの場合Mercurialが必要
!
def install
ENV['GOPATH'] = buildpath
system 'go', 'get', ‘github.com/jessevdk/go-flags'
mkdir_p buildpath/'src/github.com/monochromegane'
ln_s buildpath, buildpath/'src/github.com/monochromegane/the_platinum_searcher'
system 'go', 'build', '-o', 'pt', 'cmd/pt/main.go'
bin.install 'pt'
end
end
formula
25. $ cd go/src
$ GOOS=linux GOARCH=amd64
./make.bash
$ GOOS=linux GOARCH=amd64
go build
• Homebrewの場合、/usr/local/Cellar/go/1.3/libexec
Basic
27. $ gox
$ gox
Number of parallel builds: 4
!
--> darwin/386: go-ls
--> darwin/amd64: go-ls
--> linux/386: go-ls
• 並行コンパイル
• オプションで対象OS/ARCH指定可能 -osarch=“linux/amd64"
mitchellh/gox
28. $ goxc
$ goxc
...
!
[goxc:archive-tar-gz] 2014/08/10 21:35:38
Artifact(s) archived to /Users/miyakey/bin/go-ls-
xc/snapshot/go-ls_linux_amd64.tar.gz
• コンパイル結果を圧縮できるので、同じ実行ファイル名にできる
• オプションで対象OS/ARCH指定可能 -bc="linux,!arm darwin"
laher/goxc
31. http://icons8.com/
push
configure hook
Docker Images
build & test
Docker Container
deploydownload
heroku, Dotcloud, GAE,
S3, SSH
C, C++, Dart, Go,
Haskell, Groovy, Java,
Node.js, PHP, Python,
Ruby, Scala
37. require 'formula'
!
HOMEBREW_PT_VERSION='1.7.1'
class Pt < Formula
homepage 'https://github.com/monochromegane/the_platinum_searcher'
url "https://github.com/monochromegane/the_platinum_searcher/
releases/download/v#{HOMEBREW_PT_VERSION}/pt_darwin_amd64.zip"
sha1 '00844c339ca864bdae77fe4481a103456760181e'
!
version HOMEBREW_PT_VERSION
def install
bin.install 'pt'
end
end
formula
• URL指定でzipファイルを指定するとコンパイル済みのファイ
ルからインストールできてインストール時間を短縮できる