浏览代码

Print release date in version command

V2Ray 10 年之前
父节点
当前提交
c097e6a3c6
共有 4 个文件被更改,包括 29 次插入5 次删除
  1. 13 1
      core.go
  2. 1 1
      proxy/socks/udp.go
  3. 13 2
      release/release.sh
  4. 2 1
      release/server/main.go

+ 13 - 1
core.go

@@ -1,8 +1,20 @@
 // Package core provides common definitions and functionalities of V2Ray.
 package core
 
+var (
+	version = "0.6.2"
+	build   = "Custom"
+)
+
 const (
-	Version  = "0.6"
 	Codename = "Post Apocalypse"
 	Intro    = "A stable and unbreakable connection for everyone."
 )
+
+func Version() string {
+	return version
+}
+
+func Build() string {
+	return build
+}

+ 1 - 1
proxy/socks/udp.go

@@ -86,7 +86,7 @@ func (server *SocksServer) ListenUDP(port uint16) error {
 	}
 
 	go server.AcceptPackets(conn)
-  udpConn = conn
+	udpConn = conn
 	return nil
 }
 

+ 13 - 2
release/release.sh

@@ -1,6 +1,17 @@
 #!/bin/bash
 
-VERSION=$(sed -n 's/.*Version.*=.*\"\([^"]*\)\".*/\1/p' $GOPATH/src/github.com/v2ray/v2ray-core/core.go)
+GIT_REV=$(git rev-parse HEAD)
+VERSION=$(git name-rev --tags --name-only $GIT_REV)
+
+LD_FLAGS="-s"
+
+if [ "$VERSION" != "undefined" ]; then
+  VERSION=${VERSION%^0}
+  TODAY="$(date -u +%Y%m%d)"
+  LD_FLAGS="${LD_FLAGS} -X github.com/v2ray/v2ray-core.version=${VERSION} -X github.com/v2ray/v2ray-core.build=${TODAY}"
+else
+  VERSION="custom"
+fi
 
 BIN_PATH=$GOPATH/bin
 mkdir -p $BIN_PATH
@@ -18,7 +29,7 @@ function build {
   fi
   mkdir -p $REL_PATH/config
   cp -R $GOPATH/src/github.com/v2ray/v2ray-core/release/config/* $REL_PATH/config/
-  GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${TARGET} -compiler gc -ldflags "-s" github.com/v2ray/v2ray-core/release/server
+  GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${TARGET} -compiler gc -ldflags "${LD_FLAGS}" github.com/v2ray/v2ray-core/release/server
   
   ZIP_FILE=$BIN_PATH/v2ray${SUFFIX}.zip
   if [ -f $ZIP_FILE ]; then

+ 2 - 1
release/server/main.go

@@ -24,8 +24,9 @@ func main() {
 	flag.Parse()
 
 	if *version {
-		fmt.Printf("V2Ray version %s (%s): %s", core.Version, core.Codename, core.Intro)
+		fmt.Printf("V2Ray %s (%s) %s", core.Version(), core.Codename, core.Build())
 		fmt.Println()
+		fmt.Println(core.Intro)
 		return
 	}