From 1fe6d4a0f5040ffcae19489287a8a7aabd8f6ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Thu, 12 Feb 2026 22:00:15 +0800 Subject: [PATCH] core/core.go: Replace "Custom" with vcs info if available (#5665) https://github.com/XTLS/Xray-core/pull/5665#issuecomment-3890500863 --- core/core.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/core.go b/core/core.go index b35bef59..e5dbf7d7 100644 --- a/core/core.go +++ b/core/core.go @@ -12,6 +12,7 @@ package core import ( "fmt" "runtime" + "runtime/debug" "github.com/xtls/xray-core/common/serial" ) @@ -28,6 +29,34 @@ var ( intro = "A unified platform for anti-censorship." ) +func init() { + // Manually injected + if build != "Custom" { + return + } + info, ok := debug.ReadBuildInfo() + if !ok { + return + } + var isDirty bool + var foundBuild bool + for _, setting := range info.Settings { + switch setting.Key { + case "vcs.revision": + if len(setting.Value) < 7 { + return + } + build = setting.Value[:7] + foundBuild = true + case "vcs.modified": + isDirty = setting.Value == "true" + } + } + if isDirty && foundBuild { + build += "-dirty" + } +} + // Version returns Xray's version as a string, in the form of "x.y.z" where x, y and z are numbers. // ".z" part may be omitted in regular releases. func Version() string {