Skip to content

Commit

Permalink
Merge pull request #1244 from apernet/better-version
Browse files Browse the repository at this point in the history
feat: add toolchain & quic-go to version info
  • Loading branch information
tobyxdd authored Nov 5, 2024
2 parents a52b02b + d4a1c2b commit c34f237
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
20 changes: 12 additions & 8 deletions app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@ const (

var (
// These values will be injected by the build system
appVersion = "Unknown"
appDate = "Unknown"
appType = "Unknown" // aka channel
appCommit = "Unknown"
appPlatform = "Unknown"
appArch = "Unknown"
appVersion = "Unknown"
appDate = "Unknown"
appType = "Unknown" // aka channel
appToolchain = "Unknown"
appCommit = "Unknown"
appPlatform = "Unknown"
appArch = "Unknown"
libVersion = "Unknown"

appVersionLong = fmt.Sprintf("Version:\t%s\n"+
"BuildDate:\t%s\n"+
"BuildType:\t%s\n"+
"Toolchain:\t%s\n"+
"CommitHash:\t%s\n"+
"Platform:\t%s\n"+
"Architecture:\t%s",
appVersion, appDate, appType, appCommit, appPlatform, appArch)
"Architecture:\t%s\n"+
"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)
)
Expand Down
41 changes: 39 additions & 2 deletions hyperbole.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,33 @@ def get_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():
d_os = subprocess.check_output(["go", "env", "GOOS"]).decode().strip()
d_arch = subprocess.check_output(["go", "env", "GOARCH"]).decode().strip()
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():
platforms = os.environ.get("HY_APP_PLATFORMS")
if not platforms:
Expand All @@ -176,8 +197,12 @@ def cmd_build(pprof=False, release=False, race=False):
os.makedirs(BUILD_DIR, exist_ok=True)

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()
lib_version = get_lib_version()

ldflags = [
"-X",
Expand All @@ -190,7 +215,11 @@ def cmd_build(pprof=False, release=False, race=False):
+ ("release" if release else "dev")
+ ("-pprof" if pprof else ""),
"-X",
'"' + APP_SRC_CMD_PKG + ".appToolchain=" + app_toolchain + '"',
"-X",
APP_SRC_CMD_PKG + ".appCommit=" + app_commit,
"-X",
APP_SRC_CMD_PKG + ".libVersion=" + lib_version,
]
if release:
ldflags.append("-s")
Expand Down Expand Up @@ -267,8 +296,12 @@ def cmd_run(args, pprof=False, race=False):
return

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()
lib_version = get_lib_version()

current_os, current_arch = get_current_os_arch()

Expand All @@ -280,11 +313,15 @@ def cmd_run(args, pprof=False, race=False):
"-X",
APP_SRC_CMD_PKG + ".appType=dev-run",
"-X",
'"' + APP_SRC_CMD_PKG + ".appToolchain=" + app_toolchain + '"',
"-X",
APP_SRC_CMD_PKG + ".appCommit=" + app_commit,
"-X",
APP_SRC_CMD_PKG + ".appPlatform=" + current_os,
"-X",
APP_SRC_CMD_PKG + ".appArch=" + current_arch,
"-X",
APP_SRC_CMD_PKG + ".libVersion=" + lib_version,
]

cmd = ["go", "run", "-ldflags", " ".join(ldflags)]
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ is_hysteria1_version() {
get_installed_version() {
if is_hysteria_installed; 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
# hysteria 1
"$EXECUTABLE_INSTALL_PATH" -v | cut -d ' ' -f 3
Expand Down

0 comments on commit c34f237

Please sign in to comment.