2015-10-17 22:50:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2017-02-23 16:59:22 +00:00
|
|
|
func buildV2Ray(targetFile string, version string, goOS GoOS, goArch GoArch, extraLdFlags string) error {
|
2017-02-23 10:59:32 +00:00
|
|
|
goPath := os.Getenv("GOPATH")
|
2017-02-23 16:59:22 +00:00
|
|
|
ldFlags := "-s " + extraLdFlags
|
2015-10-18 11:14:34 +00:00
|
|
|
if version != "custom" {
|
2015-10-17 22:50:51 +00:00
|
|
|
year, month, day := time.Now().UTC().Date()
|
|
|
|
today := fmt.Sprintf("%04d%02d%02d", year, int(month), day)
|
2017-04-21 11:26:54 +00:00
|
|
|
bUser := os.Getenv("V_USER")
|
|
|
|
ldFlags = ldFlags + " -X v2ray.com/core.version=" + version + " -X v2ray.com/core.build=" + today + " -X v2ray.core/core/tools/conf.bUser=" + bUser
|
2015-10-17 22:50:51 +00:00
|
|
|
}
|
2017-02-23 10:59:32 +00:00
|
|
|
cmd := exec.Command(
|
|
|
|
"go", "build",
|
|
|
|
"-tags", "json",
|
|
|
|
"-o", targetFile,
|
|
|
|
"-compiler", "gc",
|
|
|
|
"-ldflags", ldFlags,
|
|
|
|
"-gcflags", "-trimpath="+goPath,
|
|
|
|
"-asmflags", "-trimpath="+goPath,
|
|
|
|
"v2ray.com/core/main")
|
2016-12-01 20:38:13 +00:00
|
|
|
cmd.Env = append(cmd.Env, "GOOS="+string(goOS), "GOARCH="+string(goArch), "CGO_ENABLED=0")
|
2015-10-17 22:50:51 +00:00
|
|
|
cmd.Env = append(cmd.Env, os.Environ()...)
|
2015-10-18 11:14:34 +00:00
|
|
|
output, err := cmd.CombinedOutput()
|
|
|
|
if len(output) > 0 {
|
|
|
|
fmt.Println(string(output))
|
|
|
|
}
|
2015-10-17 22:50:51 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-02-23 13:48:44 +00:00
|
|
|
|
|
|
|
func signFile(file string) error {
|
|
|
|
pass := os.Getenv("GPG_SIGN_PASS")
|
2017-02-23 14:43:11 +00:00
|
|
|
cmd := exec.Command("gpg", "--digest-algo", "SHA512", "--no-tty", "--batch", "--passphrase", pass, "--output", file+".sig", "--detach-sig", file)
|
2017-02-23 13:48:44 +00:00
|
|
|
cmd.Env = append(cmd.Env, os.Environ()...)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
|
|
if len(output) > 0 {
|
|
|
|
fmt.Println(string(output))
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|