Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
90b7d804
H
hub
项目概览
github
/
hub
10 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
90b7d804
编写于
12月 17, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add package task
上级
334a5ae1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
112 addition
and
32 deletion
+112
-32
Vagrantfile
Vagrantfile
+2
-1
gh_task.go
gh_task.go
+110
-31
未找到文件。
Vagrantfile
浏览文件 @
90b7d804
...
...
@@ -49,6 +49,7 @@ def bootstrap(box)
echo '
#{
profile
}
' >> /home/vagrant/.profile
chown -R vagrant:vagrant /home/vagrant/gocode
go get github.com/jingweno/gotask
echo "
\n
Run: vagrant ssh
#{
box
}
-c 'cd project/path; go test ./...'"
SCRIPT
...
...
@@ -59,7 +60,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config
.
vm
.
define
"linux"
do
|
linux
|
linux
.
vm
.
box
=
"precise64"
linux
.
vm
.
box_url
=
"http://files.vagrantup.com/precise64.box"
linux
.
vm
.
synced_folder
"
#{
src_path
}
/src/github.com/jingweno/gh
/target"
,
"/home/vagrant/target
"
linux
.
vm
.
synced_folder
"
#{
src_path
}
/src/github.com/jingweno/gh
"
,
"/home/vagrant/gocode/src/github.com/jingweno/gh
"
linux
.
vm
.
provision
:shell
,
:inline
=>
bootstrap
(
"linux"
)
end
...
...
gh_task.go
浏览文件 @
90b7d804
...
...
@@ -3,54 +3,79 @@
package
main
import
(
"fmt"
"github.com/jingweno/gotask/tasking"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
)
// NAME
//
cross-compile-all - cross-compiles gh for all supported platforms.
//
install-deps - install dependencies with go get
//
// DESCRIPTION
// Cross-compiles gh for all supported platforms. Build artifacts will be in target/VERSION.
// This only works on darwin with Vagrant setup.
func
TaskCrossCompileAll
(
t
*
tasking
.
T
)
{
t
.
Log
(
"Removing build target..."
)
err
:=
os
.
RemoveAll
(
"target"
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't remove build target: %s
\n
"
,
err
)
return
// Install dependencies with go get.
func
TaskInstallDeps
(
t
*
tasking
.
T
)
{
deps
:=
[]
string
{
"github.com/kr/godep"
,
"github.com/laher/goxc"
,
"github.com/jingweno/gh"
,
}
// for current
t
.
Logf
(
"Compiling for %s...
\n
"
,
runtime
.
GOOS
)
TaskCrossCompile
(
t
)
if
t
.
Failed
()
{
return
for
_
,
dep
:=
range
deps
{
t
.
Logf
(
"Installing %s
\n
"
,
dep
)
err
:=
t
.
Exec
(
"go get"
,
dep
)
if
err
!=
nil
{
t
.
Fatalf
(
"Can't download dependency %s"
,
err
)
}
}
}
// NAME
// package - cross compile gh and package it
//
// DESCRIPTION
// Cross compile gh and package it into PWD/target
func
TaskPackage
(
t
*
tasking
.
T
)
{
gopath
,
err
:=
ioutil
.
TempDir
(
""
,
"gh-build"
)
os
.
Setenv
(
"GOPATH"
,
gopath
)
t
.
Logf
(
"GOPATH=%s
\n
"
,
gopath
)
// for linux
t
.
Log
(
"Compiling for linux..."
)
t
.
Log
(
"Downloading gh..."
)
err
=
t
.
Exec
(
"vagrant ssh -c 'rm -rf ~/gocode && go get github.com/jingweno/gh'"
)
pwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
t
.
Errorf
(
"Can't download gh on linux: %s
\n
"
,
err
)
return
t
.
Fatal
(
err
)
}
t
.
Log
(
"Cross-compiling gh..."
)
err
=
t
.
Exec
(
"vagrant ssh -c 'cd ~/gocode/src/github.com/jingweno/gh && ./script/bootstrap && GOPATH=`godep path`:$GOPATH gotask cross-compile'"
)
t
.
Logf
(
"Packaging for %s...
\n
"
,
runtime
.
GOOS
)
t
.
Log
(
"Installing dependencies..."
)
TaskInstallDeps
(
t
)
ghPath
:=
filepath
.
Join
(
gopath
,
"src"
,
"github.com"
,
"jingweno"
,
"gh"
)
err
=
os
.
Chdir
(
ghPath
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't cross-compile gh on linux: %s
\n
"
,
err
)
return
t
.
Fatal
(
err
)
}
t
.
Log
(
"Moving build artifacts..."
)
err
=
t
.
Exec
(
"vagrant ssh -c 'cp -R ~/gocode/src/github.com/jingweno/gh/target/* ~/target/'"
)
t
.
Log
(
"Cross-compiling..."
)
godepPath
:=
filepath
.
Join
(
ghPath
,
"Godeps"
,
"_workspace"
)
os
.
Setenv
(
"GOPATH"
,
fmt
.
Sprintf
(
"%s:%s"
,
godepPath
,
gopath
))
TaskCrossCompile
(
t
)
source
:=
filepath
.
Join
(
ghPath
,
"target"
)
target
:=
filepath
.
Join
(
pwd
,
"target"
)
t
.
Logf
(
"Copying build artifacts from %s to %s...
\n
"
,
source
,
target
)
_
,
err
=
os
.
Stat
(
target
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't cross-compile gh on linux: %s
\n
"
,
err
)
return
err
=
os
.
Mkdir
(
target
,
0777
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
t
.
Args
=
append
(
t
.
Args
,
source
,
target
)
TaskCopyBuildArtifacts
(
t
)
}
// NAME
...
...
@@ -60,9 +85,63 @@ func TaskCrossCompileAll(t *tasking.T) {
// Cross-compiles gh for current platform. Build artifacts will be in target/VERSION
func
TaskCrossCompile
(
t
*
tasking
.
T
)
{
t
.
Logf
(
"Cross-compiling gh for %s...
\n
"
,
runtime
.
GOOS
)
err
:=
t
.
Exec
(
"goxc"
,
"-wd=."
,
"-os="
+
runtime
.
GOOS
,
"-c="
+
runtime
.
GOOS
)
err
:=
t
.
Exec
(
"goxc"
,
"-wd=."
,
"-os="
+
runtime
.
GOOS
,
"-c="
+
runtime
.
GOOS
)
if
err
!=
nil
{
t
.
Fatalf
(
"Can't cross-compile gh: %s
\n
"
,
err
)
}
}
// NAME
// copy-build-artifacts - copy build artifacts from source to target
//
// DESCRIPTION
// Copy build artifacts from source to target.
// For example, `gotask copy-build-artifacts src dest`
func
TaskCopyBuildArtifacts
(
t
*
tasking
.
T
)
{
if
len
(
t
.
Args
)
<
2
{
t
.
Fatal
(
"Missing source or target"
)
}
srcDir
:=
t
.
Args
[
0
]
destDir
:=
t
.
Args
[
1
]
artifacts
:=
findBuildArtifacts
(
srcDir
)
for
_
,
artifact
:=
range
artifacts
{
target
:=
filepath
.
Join
(
destDir
,
filepath
.
Base
(
artifact
))
t
.
Logf
(
"Copying %s to %s
\n
"
,
artifact
,
target
)
err
:=
copyFile
(
artifact
,
target
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
func
copyFile
(
src
,
dst
string
)
error
{
sf
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't cross-compile gh: %s
\n
"
,
err
)
return
return
err
}
defer
sf
.
Close
()
df
,
err
:=
os
.
Create
(
dst
)
if
err
!=
nil
{
return
err
}
defer
df
.
Close
()
_
,
err
=
io
.
Copy
(
df
,
sf
)
return
err
}
func
findBuildArtifacts
(
root
string
)
(
artifacts
[]
string
)
{
filepath
.
Walk
(
root
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
ext
:=
filepath
.
Ext
(
path
)
if
ext
==
".deb"
||
ext
==
".zip"
||
ext
==
".gz"
{
artifacts
=
append
(
artifacts
,
path
)
}
return
nil
})
return
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录