mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-03 20:47:38 +03:00
Merge pull request #1244 from apernet/better-version
feat: add toolchain & quic-go to version info
This commit is contained in:
commit
c34f23755a
3 changed files with 52 additions and 11 deletions
|
@ -32,17 +32,21 @@ var (
|
||||||
appVersion = "Unknown"
|
appVersion = "Unknown"
|
||||||
appDate = "Unknown"
|
appDate = "Unknown"
|
||||||
appType = "Unknown" // aka channel
|
appType = "Unknown" // aka channel
|
||||||
|
appToolchain = "Unknown"
|
||||||
appCommit = "Unknown"
|
appCommit = "Unknown"
|
||||||
appPlatform = "Unknown"
|
appPlatform = "Unknown"
|
||||||
appArch = "Unknown"
|
appArch = "Unknown"
|
||||||
|
libVersion = "Unknown"
|
||||||
|
|
||||||
appVersionLong = fmt.Sprintf("Version:\t%s\n"+
|
appVersionLong = fmt.Sprintf("Version:\t%s\n"+
|
||||||
"BuildDate:\t%s\n"+
|
"BuildDate:\t%s\n"+
|
||||||
"BuildType:\t%s\n"+
|
"BuildType:\t%s\n"+
|
||||||
|
"Toolchain:\t%s\n"+
|
||||||
"CommitHash:\t%s\n"+
|
"CommitHash:\t%s\n"+
|
||||||
"Platform:\t%s\n"+
|
"Platform:\t%s\n"+
|
||||||
"Architecture:\t%s",
|
"Architecture:\t%s\n"+
|
||||||
appVersion, appDate, appType, appCommit, appPlatform, appArch)
|
"LibVersion:\t%s",
|
||||||
|
appVersion, appDate, appType, appToolchain, appCommit, appPlatform, appArch, libVersion)
|
||||||
|
|
||||||
appAboutLong = fmt.Sprintf("%s\n%s\n%s\n\n%s", appLogo, appDesc, appAuthors, appVersionLong)
|
appAboutLong = fmt.Sprintf("%s\n%s\n%s\n\n%s", appLogo, appDesc, appAuthors, appVersionLong)
|
||||||
)
|
)
|
||||||
|
|
41
hyperbole.py
41
hyperbole.py
|
@ -145,12 +145,33 @@ def get_app_commit():
|
||||||
return app_commit
|
return app_commit
|
||||||
|
|
||||||
|
|
||||||
|
def get_toolchain():
|
||||||
|
try:
|
||||||
|
output = subprocess.check_output(["go", "version"]).decode().strip()
|
||||||
|
if output.startswith("go version "):
|
||||||
|
output = output[11:]
|
||||||
|
return output
|
||||||
|
except Exception:
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
|
||||||
def get_current_os_arch():
|
def get_current_os_arch():
|
||||||
d_os = subprocess.check_output(["go", "env", "GOOS"]).decode().strip()
|
d_os = subprocess.check_output(["go", "env", "GOOS"]).decode().strip()
|
||||||
d_arch = subprocess.check_output(["go", "env", "GOARCH"]).decode().strip()
|
d_arch = subprocess.check_output(["go", "env", "GOARCH"]).decode().strip()
|
||||||
return (d_os, d_arch)
|
return (d_os, d_arch)
|
||||||
|
|
||||||
|
|
||||||
|
def get_lib_version():
|
||||||
|
try:
|
||||||
|
with open(CORE_SRC_DIR + "/go.mod") as f:
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
if line.startswith("github.com/apernet/quic-go"):
|
||||||
|
return line.split(" ")[1].strip()
|
||||||
|
except Exception:
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
|
||||||
def get_app_platforms():
|
def get_app_platforms():
|
||||||
platforms = os.environ.get("HY_APP_PLATFORMS")
|
platforms = os.environ.get("HY_APP_PLATFORMS")
|
||||||
if not platforms:
|
if not platforms:
|
||||||
|
@ -176,8 +197,12 @@ def cmd_build(pprof=False, release=False, race=False):
|
||||||
os.makedirs(BUILD_DIR, exist_ok=True)
|
os.makedirs(BUILD_DIR, exist_ok=True)
|
||||||
|
|
||||||
app_version = get_app_version()
|
app_version = get_app_version()
|
||||||
app_date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
app_date = datetime.datetime.now(datetime.timezone.utc).strftime(
|
||||||
|
"%Y-%m-%dT%H:%M:%SZ"
|
||||||
|
)
|
||||||
|
app_toolchain = get_toolchain()
|
||||||
app_commit = get_app_commit()
|
app_commit = get_app_commit()
|
||||||
|
lib_version = get_lib_version()
|
||||||
|
|
||||||
ldflags = [
|
ldflags = [
|
||||||
"-X",
|
"-X",
|
||||||
|
@ -190,7 +215,11 @@ def cmd_build(pprof=False, release=False, race=False):
|
||||||
+ ("release" if release else "dev")
|
+ ("release" if release else "dev")
|
||||||
+ ("-pprof" if pprof else ""),
|
+ ("-pprof" if pprof else ""),
|
||||||
"-X",
|
"-X",
|
||||||
|
'"' + APP_SRC_CMD_PKG + ".appToolchain=" + app_toolchain + '"',
|
||||||
|
"-X",
|
||||||
APP_SRC_CMD_PKG + ".appCommit=" + app_commit,
|
APP_SRC_CMD_PKG + ".appCommit=" + app_commit,
|
||||||
|
"-X",
|
||||||
|
APP_SRC_CMD_PKG + ".libVersion=" + lib_version,
|
||||||
]
|
]
|
||||||
if release:
|
if release:
|
||||||
ldflags.append("-s")
|
ldflags.append("-s")
|
||||||
|
@ -267,8 +296,12 @@ def cmd_run(args, pprof=False, race=False):
|
||||||
return
|
return
|
||||||
|
|
||||||
app_version = get_app_version()
|
app_version = get_app_version()
|
||||||
app_date = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
app_date = datetime.datetime.now(datetime.timezone.utc).strftime(
|
||||||
|
"%Y-%m-%dT%H:%M:%SZ"
|
||||||
|
)
|
||||||
|
app_toolchain = get_toolchain()
|
||||||
app_commit = get_app_commit()
|
app_commit = get_app_commit()
|
||||||
|
lib_version = get_lib_version()
|
||||||
|
|
||||||
current_os, current_arch = get_current_os_arch()
|
current_os, current_arch = get_current_os_arch()
|
||||||
|
|
||||||
|
@ -280,11 +313,15 @@ def cmd_run(args, pprof=False, race=False):
|
||||||
"-X",
|
"-X",
|
||||||
APP_SRC_CMD_PKG + ".appType=dev-run",
|
APP_SRC_CMD_PKG + ".appType=dev-run",
|
||||||
"-X",
|
"-X",
|
||||||
|
'"' + APP_SRC_CMD_PKG + ".appToolchain=" + app_toolchain + '"',
|
||||||
|
"-X",
|
||||||
APP_SRC_CMD_PKG + ".appCommit=" + app_commit,
|
APP_SRC_CMD_PKG + ".appCommit=" + app_commit,
|
||||||
"-X",
|
"-X",
|
||||||
APP_SRC_CMD_PKG + ".appPlatform=" + current_os,
|
APP_SRC_CMD_PKG + ".appPlatform=" + current_os,
|
||||||
"-X",
|
"-X",
|
||||||
APP_SRC_CMD_PKG + ".appArch=" + current_arch,
|
APP_SRC_CMD_PKG + ".appArch=" + current_arch,
|
||||||
|
"-X",
|
||||||
|
APP_SRC_CMD_PKG + ".libVersion=" + lib_version,
|
||||||
]
|
]
|
||||||
|
|
||||||
cmd = ["go", "run", "-ldflags", " ".join(ldflags)]
|
cmd = ["go", "run", "-ldflags", " ".join(ldflags)]
|
||||||
|
|
|
@ -872,7 +872,7 @@ is_hysteria1_version() {
|
||||||
get_installed_version() {
|
get_installed_version() {
|
||||||
if is_hysteria_installed; then
|
if is_hysteria_installed; then
|
||||||
if "$EXECUTABLE_INSTALL_PATH" version > /dev/null 2>&1; then
|
if "$EXECUTABLE_INSTALL_PATH" version > /dev/null 2>&1; then
|
||||||
"$EXECUTABLE_INSTALL_PATH" version | grep Version | grep -o 'v[.0-9]*'
|
"$EXECUTABLE_INSTALL_PATH" version | grep '^Version' | grep -o 'v[.0-9]*'
|
||||||
elif "$EXECUTABLE_INSTALL_PATH" -v > /dev/null 2>&1; then
|
elif "$EXECUTABLE_INSTALL_PATH" -v > /dev/null 2>&1; then
|
||||||
# hysteria 1
|
# hysteria 1
|
||||||
"$EXECUTABLE_INSTALL_PATH" -v | cut -d ' ' -f 3
|
"$EXECUTABLE_INSTALL_PATH" -v | cut -d ' ' -f 3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue