Exemplo n.º 1
0
// NAME
//    clean - Clean all generated files
//
// DESCRIPTION
//    Clean all generated files and paths.
//
// OPTIONS
//    --backup, -b
//        clean all backup files (*~, #*)
//    --verbose, -v
//        run in verbose mode
func TaskClean(t *tasking.T) {
	var paths []string

	paths = append(
		paths,
		ARMBinaryPath,
		"pkg",
		filepath.Join("bin", ProjectName),
		filepath.Join(AndroidPath, "bin"),
		filepath.Join(AndroidPath, "gen"),
		filepath.Join(AndroidPath, "libs"),
		filepath.Join(AndroidPath, "obj"),
	)

	// Actually remove files using rm
	for _, path := range paths {
		err := rm_rf(t, path)
		if err != nil {
			t.Error(err)
		}
	}

	if t.Flags.Bool("backup") {
		err := t.Exec(`sh -c`, `"find ./ -name '*~' -print0 | xargs -0 rm -f"`)
		if err != nil {
			t.Error(err)
		}
	}

	if t.Failed() {
		t.Fatalf("%-20s %s\n", status(t.Failed()), "Clean all generated files and paths.")
	}
	t.Logf("%-20s %s\n", status(t.Failed()), "Clean all generated files and paths.")
}
Exemplo n.º 2
0
// NAME
//    cross-compile - cross-compiles gh for current platform.
//
// DESCRIPTION
//    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)
	t.Logf("GOPATH=%s\n", os.Getenv("GOPATH"))
	err := t.Exec("goxc", "-wd=.", "-os="+runtime.GOOS, "-c="+runtime.GOOS)
	if err != nil {
		t.Fatalf("Can't cross-compile gh: %s\n", err)
	}
}
Exemplo n.º 3
0
func deployAndroid(t *tasking.T) {
	buildAndroid(t)
	err := t.Exec("ant -f android/build.xml clean debug")
	if err != nil {
		t.Error(err)
	}
	uploadAndroid(t)
}
Exemplo n.º 4
0
func runXorg(t *tasking.T) {
	err := t.Exec(
		filepath.Join("bin", LibName),
		t.Flags.String("flags"),
	)
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 5
0
func runXorg(t *tasking.T, flags string) {
	err := t.Exec(
		filepath.Join("bin", LibName),
		flags,
	)
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 6
0
func runXorg(t *tasking.T) {
	buildXorg(t)
	err := t.Exec(
		filepath.Join("bin", ProjectName),
		t.Flags.String("flags"),
	)
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 7
0
func buildXorg(t *tasking.T) {
	err := t.Exec(
		`sh -c "`,
		"GOPATH=`pwd`:$GOPATH",
		`go get`, t.Flags.String("flags"),
		LibName, `"`,
	)
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 8
0
func buildXorg(t *tasking.T) {
	err := t.Exec(
		`sh -c "`,
		"GOPATH=`pwd`:$GOPATH",
		`go install`, t.Flags.String("buildflags"),
		ProjectName, `"`,
	)
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 9
0
// NAME
//    install-deps - install dependencies with go get
//
// DESCRIPTION
//    Install dependencies with go get.
func TaskInstallDeps(t *tasking.T) {
	deps := []string{
		"github.com/laher/goxc",
	}

	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)
		}
	}
}
Exemplo n.º 10
0
// NAME
//    bottle - build homebrew bottle for gh
//
// DESCRIPTION
//    Build homebrew bottle for gh into PWD/target.
func TaskBottle(t *tasking.T) {
	pwd, err := os.Getwd()
	if err != nil {
		t.Fatal(err)
	}

	target := filepath.Join(pwd, "target")
	err = mkdirAll(target)
	if err != nil {
		t.Fatal(err)
	}

	err = t.Exec("brew", "list", "gh")
	if err == nil {
		err := t.Exec("brew", "uninstall", "gh")
		if err != nil {
			t.Fatal(err)
		}
	}

	err = t.Exec("brew", "install", "--build-from-source", "--build-bottle", "gh")
	if err != nil {
		t.Fatal(err)
	}

	err = os.Chdir(target)
	if err != nil {
		t.Fatal(err)
	}

	err = t.Exec("brew", "bottle", "gh")
	if err != nil {
		t.Fatal(err)
	}
}
Exemplo n.º 11
0
// Cross-compiles gh for current operating system.
//
// Cross-compiles gh for current operating system. The build artifacts will be in target/VERSION
func TaskCrossCompile(t *tasking.T) {
	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
	}

	t.Logf("Cross-compiling gh for %s...\n", runtime.GOOS)
	err = t.Exec("goxc", "-wd=.", "-os="+runtime.GOOS, "-c="+runtime.GOOS)
	if err != nil {
		t.Errorf("Can't cross-compile gh: %s\n", err)
		return
	}
}
Exemplo n.º 12
0
func buildXorg(t *tasking.T, buildAll bool) {
	allFlagString := ""
	if buildAll {
		allFlagString = "-a"
	}
	err := t.Exec(
		`sh -c "`,
		"GOPATH=`pwd`:$GOPATH",
		`go install`, allFlagString,
		LibName, `"`,
	)
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 13
0
func runAndroid(t *tasking.T) {
	buildAndroid(t)
	deployAndroid(t)
	err := t.Exec(
		fmt.Sprintf(
			"adb shell am start -a android.intent.action.MAIN -n net.mandala.%s/android.app.NativeActivity",
			ProjectName,
		))
	if err != nil {
		t.Error(err)
	}
	err = t.Exec("adb shell logcat", "Mandala:* stdout:* stderr:* *:S")
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 14
0
func runAndroid(t *tasking.T) {
	deployAndroid(t)
	err := t.Exec(
		fmt.Sprintf(
			"adb shell am start -a android.intent.action.MAIN -n %s.%s/android.app.NativeActivity",
			Domain,
			LibName,
		))
	if err != nil {
		t.Error(err)
	}
	if tags := t.Flags.String("logcat"); tags != "" {
		err = t.Exec("adb", "shell", "logcat", tags)
		if err != nil {
			t.Error(err)
		}
	}
}
Exemplo n.º 15
0
func runAndroid(t *tasking.T, flags string) {
	deployAndroid(t)
	err := t.Exec(
		fmt.Sprintf(
			"adb shell am start -a android.intent.action.MAIN -n %s.%s/android.app.NativeActivity",
			Domain,
			LibName,
		))
	if err != nil {
		t.Error(err)
	}
	if t.Flags.Bool("logcat") {
		err = t.Exec("adb shell logcat")
		if err != nil {
			t.Error(err)
		}
	}
}
Exemplo n.º 16
0
// 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
	}

	// for current
	t.Logf("Compiling for %s...\n", runtime.GOOS)
	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
	}
}
Exemplo n.º 17
0
func buildAndroid(t *tasking.T, buildMode ...bool) {
	// Build mode for ant:
	// buildMode not specified or false => ant debug
	// buildMode true => ant release
	antBuildParam := "debug"
	if len(buildMode) > 0 && buildMode[0] == true {
		antBuildParam = "release"
	}

	// Generate AdmobActivity using the UnitId in admob.json
	err := generateAdmobActivity()
	if err != nil {
		t.Error(err)
	}

	os.MkdirAll("android/libs/armeabi-v7a", 0777)
	os.MkdirAll("android/obj/local/armeabi-v7a", 0777)

	err = t.Exec(`sh -c "`,
		`CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc"`,
		"GOPATH=`pwd`:$GOPATH",
		`GOROOT=""`,
		"GOOS=linux",
		"GOARCH=arm",
		"GOARM=7",
		"CGO_ENABLED=1",
		"$GOANDROID/go get", t.Flags.String("flags"),
		"$GOFLAGS",
		`-ldflags=\"-android -shared -extld $NDK_ROOT/bin/arm-linux-androideabi-gcc -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'\"`,
		"-tags android",
		LibName, `"`,
	)

	if err != nil {
		t.Error(err)
	}

	for _, path := range SharedLibraryPaths {
		err := t.Exec(
			"cp",
			filepath.Join(ARMBinaryPath, LibName),
			filepath.Join(path, "lib"+LibName+".so"),
		)

		if err != nil {
			t.Error(err)
		}
	}

	if err == nil {
		err = t.Exec("ant -f android/build.xml clean", antBuildParam)
		if err != nil {
			t.Error(err)
		}
	}

}
Exemplo n.º 18
0
func buildAndroid(t *tasking.T) {
	os.MkdirAll("android/libs/armeabi-v7a", 0777)
	os.MkdirAll("android/obj/local/armeabi-v7a", 0777)

	err := t.Exec(`sh -c "`,
		`CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc"`,
		"GOPATH=`pwd`:$GOPATH",
		`GOROOT=""`,
		"GOOS=linux",
		"GOARCH=arm",
		"GOARM=7",
		"CGO_ENABLED=1",
		"$GOANDROID/go install", t.Flags.String("flags"),
		"$GOFLAGS",
		`-ldflags=\"-android -shared -extld $NDK_ROOT/bin/arm-linux-androideabi-gcc -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'\"`,
		"-tags android",
		ProjectName, `"`,
	)

	if err != nil {
		t.Error(err)
	}

	os.MkdirAll(ARMBinaryPath, 0777)

	for _, path := range SharedLibraryPaths {
		err := t.Exec(
			"cp",
			filepath.Join(ARMBinaryPath, ProjectName),
			filepath.Join(path, "lib"+ProjectName+".so"),
		)

		if err != nil {
			t.Error(err)
		}
	}
}
Exemplo n.º 19
0
func buildAndroid(t *tasking.T, buildAll bool) {
	allFlagString := ""

	os.MkdirAll("android/libs/armeabi-v7a", 0777)
	os.MkdirAll("android/obj/local/armeabi-v7a", 0777)

	if buildAll {
		allFlagString = "-a"
	}

	err := t.Exec(`sh -c "`,
		`CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc"`,
		"GOPATH=`pwd`:$GOPATH",
		`GOROOT=""`,
		"GOOS=linux",
		"GOARCH=arm",
		"GOARM=7",
		"CGO_ENABLED=1",
		"$GOANDROID/go install", allFlagString,
		"$GOFLAGS",
		`-ldflags=\"-android -shared -extld $NDK_ROOT/bin/arm-linux-androideabi-gcc -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'\"`,
		"-tags android",
		LibName, `"`,
	)

	if err != nil {
		t.Error(err)
	}

	for _, path := range SharedLibraryPaths {
		err := t.Exec(
			"cp",
			filepath.Join(ARMBinaryPath, LibName),
			filepath.Join(path, "lib"+LibName+".so"),
		)

		if err != nil {
			t.Error(err)
		}
	}

	if err == nil {
		err = t.Exec("ant -f android/build.xml clean debug")
		if err != nil {
			t.Error(err)
		}
	}

}
Exemplo n.º 20
0
// Sign and zipalign Android application.
func signAndroid(t *tasking.T) {
	unsignedAppPath := fmt.Sprintf("android/bin/%s-release-unsigned.apk", LibName)
	// Sign app
	cmdJarsigner := "jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore %s %s %s"
	if err := t.Exec(fmt.Sprintf(cmdJarsigner, KeyStore, unsignedAppPath, KeyAlias)); err != nil {
		t.Error(err)
	}
	// Verify sign
	cmdJarsignerVerify := "jarsigner -verify -verbose -certs %s"
	if err := t.Exec(fmt.Sprintf(cmdJarsignerVerify, unsignedAppPath)); err != nil {
		t.Error(err)
	}
	// Align app
	cmdZipAlign := "zipalign -v 4 %s android/bin/%s.apk"
	if err := t.Exec(fmt.Sprintf(cmdZipAlign, unsignedAppPath, LibName)); err != nil {
		t.Error(err)
	}
}
Exemplo n.º 21
0
func rm_rf(t *tasking.T, path string) error {
	return t.Exec("rm -rf", path)
}
Exemplo n.º 22
0
func cp(t *tasking.T, src, dest string) error {
	return t.Exec("cp", src, dest)
}
Exemplo n.º 23
0
func deployAndroid(t *tasking.T) {
	err := t.Exec(fmt.Sprintf("adb install -r android/bin/%s-debug.apk", LibName))
	if err != nil {
		t.Error(err)
	}
}
Exemplo n.º 24
0
func mv(t *tasking.T, src, dest string) error {
	return t.Exec("mv", src, dest)
}
Exemplo n.º 25
0
func uploadAndroid(t *tasking.T) {
	err := t.Exec(fmt.Sprintf("adb install -r android/bin/%s-debug.apk", ProjectName))
	if err != nil {
		t.Error(err)
	}
}