gh_task.go 1.6 KB
Newer Older
J
Jingwen Owen Ou 已提交
1 2 3 4 5 6 7 8 9 10
// +build gotask

package main

import (
	"github.com/jingweno/gotask/tasking"
	"os"
	"runtime"
)

11 12 13 14 15 16 17 18 19 20 21 22
// Cross-compiles gh for all supported platforms.
//
// Cross-compiles gh for all supported platforms. The 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
	}

23 24
	// for current
	t.Logf("Compiling for %s...\n", runtime.GOOS)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
	TaskCrossCompile(t)
	if t.Failed() {
		return
	}

	// for linux
	t.Log("Compiling for linux...")
	err = t.Exec("vagrant ssh -c 'cd ~/src/github.com/jingweno/gh && git pull origin master && gotask cross-compile'")
	if err != nil {
		t.Errorf("Can't compile on linux: %s\n", err)
		return
	}
}

// Cross-compiles gh for current operating system.
J
Jingwen Owen Ou 已提交
40
//
J
Jingwen Owen Ou 已提交
41 42
// Cross-compiles gh for current operating system. The build artifacts will be in target/VERSION
func TaskCrossCompile(t *tasking.T) {
J
Jingwen Owen Ou 已提交
43 44 45 46 47 48 49
	t.Log("Updating goxc...")
	err := t.Exec("go get -u github.com/laher/goxc")
	if err != nil {
		t.Errorf("Can't update goxc: %s\n", err)
		return
	}

50
	// TODO: use a dependency manager that has versioning
J
Jingwen Owen Ou 已提交
51 52 53 54 55 56 57
	if runtime.GOOS != "windows" {
		t.Log("Updating dependencies...")
		err = t.Exec("go get -u ./...")
		if err != nil {
			t.Errorf("Can't update goxc: %s\n", err)
			return
		}
58 59
	}

60
	t.Logf("Cross-compiling gh for %s...\n", runtime.GOOS)
J
Jingwen Owen Ou 已提交
61 62
	err = t.Exec("goxc", "-wd=.", "-os="+runtime.GOOS, "-c="+runtime.GOOS)
	if err != nil {
J
Jingwen Owen Ou 已提交
63
		t.Errorf("Can't cross-compile gh: %s\n", err)
J
Jingwen Owen Ou 已提交
64 65 66
		return
	}
}