浏览代码

remove git version detection

Darien Raymond 8 年之前
父节点
当前提交
ab78b5a17e
共有 3 个文件被更改,包括 6 次插入91 次删除
  1. 6 10
      tools/build/build.go
  2. 0 58
      tools/git/git.go
  3. 0 23
      tools/git/git_test.go

+ 6 - 10
tools/build/build.go

@@ -7,7 +7,7 @@ import (
 	"path/filepath"
 	"runtime"
 
-	"v2ray.com/core/tools/git"
+	"v2ray.com/core"
 )
 
 var (
@@ -61,16 +61,12 @@ func build(targetOS, targetArch string, archive bool, version string, metadataFi
 	v2rayArch := parseArch(targetArch)
 
 	if len(version) == 0 {
-		headVer, err := git.RepoVersionHead()
-		if headVer == git.VersionUndefined {
-			headVer = "custom"
-		}
-		if err != nil {
-			fmt.Println("Unable to detect V2Ray version: " + err.Error())
-			return
-		}
-		version = headVer
+		version = os.Getenv("TRAVIS_TAG")
 	}
+	if len(version) == 0 {
+		version = core.Version()
+	}
+
 	fmt.Printf("Building V2Ray (%s) for %s %s\n", version, v2rayOS, v2rayArch)
 
 	targetDir, err := createTargetDirectory(version, v2rayOS, v2rayArch)

+ 0 - 58
tools/git/git.go

@@ -1,58 +0,0 @@
-package git
-
-import (
-	"os"
-	"os/exec"
-	"path/filepath"
-	"strings"
-)
-
-const (
-	VersionUndefined = "undefined"
-)
-
-func getRepoRoot() string {
-	GOPATH := os.Getenv("GOPATH")
-	return filepath.Join(GOPATH, "src", "v2ray.com", "core")
-}
-
-func RevParse(args ...string) (string, error) {
-	args = append([]string{"rev-parse"}, args...)
-	cmd := exec.Command("git", args...)
-	cmd.Dir = getRepoRoot()
-	output, err := cmd.Output()
-	if err != nil {
-		return "", err
-	}
-	return strings.TrimSpace(string(output)), nil
-}
-
-func NameRev(args ...string) (string, error) {
-	args = append([]string{"name-rev"}, args...)
-	cmd := exec.Command("git", args...)
-	cmd.Dir = getRepoRoot()
-	output, err := cmd.Output()
-	if err != nil {
-		return "", err
-	}
-	return strings.TrimSpace(string(output)), nil
-}
-
-func RepoVersion(rev string) (string, error) {
-	rev, err := RevParse(rev)
-	if err != nil {
-		return "", err
-	}
-	version, err := NameRev("name-rev", "--tags", "--name-only", rev)
-	if err != nil {
-		return "", err
-	}
-	if strings.HasSuffix(version, "^0") {
-		version = version[:len(version)-2]
-	}
-	return version, nil
-}
-
-func RepoVersionHead() (string, error) {
-	return RepoVersion("HEAD")
-}

+ 0 - 23
tools/git/git_test.go

@@ -1,23 +0,0 @@
-package git
-
-import (
-	"testing"
-
-	"v2ray.com/core/testing/assert"
-)
-
-func TestRevParse(t *testing.T) {
-	assert := assert.On(t)
-
-	rev, err := RevParse("HEAD")
-	assert.Error(err).IsNil()
-	assert.Int(len(rev)).GreaterThan(0)
-}
-
-func TestRepoVersion(t *testing.T) {
-	assert := assert.On(t)
-
-	version, err := RepoVersionHead()
-	assert.Error(err).IsNil()
-	assert.Int(len(version)).GreaterThan(0)
-}