Skip to content

Commit

Permalink
dev: enhance version format
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhai committed Dec 30, 2023
1 parent cb68b5b commit f5d6732
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 37 deletions.
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ ip=$(shell hostname -I)
memory=$(shell free -m | awk 'NR==2{printf "%.2fGB\n", $$2/1000}')
disk=$(shell df -h | awk '$$NF=="/"{printf "%s\n", $$2}')
arch=$(uname -m)

version=$(shell git describe --tags $(git rev-list --tags --max-count=1))
shortVersion=-X 'github.com/hootrhino/rulex/typex.MainVersion=$(version)'
.PHONY: all
all:
@echo "\e[41m[*] Distro \e[0m: \e[36m ${distro} \e[0m"
@echo "\e[41m[*] Arch \e[0m: \e[36m ${arch} \e[0m"
@echo "\e[41m[*] Arch \e[0m: \e[36m ${arch} \e[0m"
@echo "\e[41m[*] Kernel \e[0m: \e[36m ${kernel} \e[0m"
@echo "\e[41m[*] Cpu \e[0m: \e[36m ${cpu} \e[0m"
@echo "\e[41m[*] Memory \e[0m: \e[36m ${memory} \e[0m"
Expand All @@ -26,51 +27,51 @@ all:
build:
CGO_ENABLED=1 GOOS=linux
go generate
go build -v -ldflags "-s -w" -o ${APP}
go build -ldflags "$(shortVersion) -s -w" -v -o ${APP}

.PHONY: x64linux
x64linux:
go generate
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=gcc\
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-x64linux
go build -ldflags "$(shortVersion) -s -w" -v -o ${APP}-x64linux

.PHONY: windows
windows:
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc\
go build -ldflags "-s -w" -o ${APP}-windows.exe
go build -ldflags "$(shortVersion) -s -w" -o ${APP}-windows.exe

.PHONY: arm32
arm32:
go generate
CGO_ENABLED=1 GOOS=linux GOARCH=arm CC=arm-linux-gnueabi-gcc\
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-arm32linux
go build -ldflags "$(shortVersion) -s -w -linkmode external -extldflags -static" -o ${APP}-arm32linux

.PHONY: arm64
arm64:
go generate
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc\
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-arm64linux
go build -ldflags "$(shortVersion) -s -w -linkmode external -extldflags -static" -o ${APP}-arm64linux

.PHONY: mips32
mips32:
go generate
# sudo apt-get install gcc-mips-linux-gnu
GOOS=linux GOARCH=mips CGO_ENABLED=1 CC=mips-linux-gnu-gcc\
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-mips32linux
go build -ldflags "$(shortVersion) -s -w -linkmode external -extldflags -static" -o ${APP}-mips32linux

.PHONY: mips64
mips64:
go generate
# sudo apt-get install gcc-mips-linux-gnu
GOOS=linux GOARCH=mips64 CGO_ENABLED=1 CC=mips-linux-gnu-gcc\
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-mips64linux
go build -ldflags "$(shortVersion) -s -w -linkmode external -extldflags -static" -o ${APP}-mips64linux

.PHONY: mipsel
mipsle:
go generate
# sudo apt-get install gcc-mipsel-linux-gnu
GOOS=linux GOARCH=mipsle CGO_ENABLED=1 GOMIPS=softfloat CC=mipsel-linux-gnu-gcc\
go build -ldflags "-s -w -linkmode external -extldflags -static" -o ${APP}-mipslelinux
go build -ldflags "$(shortVersion) -s -w -linkmode external -extldflags -static" -o ${APP}-mipslelinux

.PHONY: release
release:
Expand Down
4 changes: 2 additions & 2 deletions component/rulex_api_server/apis/system_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ func System(c *gin.Context, ruleEngine typex.RuleX) {
// ip, err0 := utils.HostNameI()
memPercent, _ := service.GetMemPercent()
hardWareInfo := map[string]interface{}{
"version": ruleEngine.Version().Version,
"version": typex.MainVersion,
"diskInfo": calculateDiskInfo(diskInfo),
"memPercent": memPercent,
"cpuPercent": calculateCpuPercent(cpuPercent),
"osArch": ruleEngine.Version().Arch,
"osDist": ruleEngine.Version().Dist,
"product": typex.DefaultVersion.Product,
"product": typex.DefaultVersionInfo.Product,
"startedAt": __StartedAt,
"osUpTime": func() string {
result, err := ossupport.GetUptime()
Expand Down
4 changes: 2 additions & 2 deletions component/rulex_api_server/service/hw_intrerface_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func InitHwPortConfig() error {
Description: portName,
}
// 兼容代码,识别H3网关的参数
if typex.DefaultVersion.Product == "EEKIIH3" {
if typex.DefaultVersionInfo.Product == "EEKIIH3" {
if portName == "/dev/ttyS1" {
Port.Alias = "RS485接口1(A1B1)"
Port.Name = "RS4851(A1B1)"
Expand Down Expand Up @@ -153,7 +153,7 @@ func GetOsPort() []string {
}
List := []string{}
for _, port := range ports {
if typex.DefaultVersion.Product == "EEKIIH3" {
if typex.DefaultVersionInfo.Product == "EEKIIH3" {
// H3的下列串口被系统占用
if utils.SContains([]string{
"/dev/ttyS0",
Expand Down
6 changes: 3 additions & 3 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (e *RuleEngine) AllPlugins() *sync.Map {
return e.Plugins
}

func (e *RuleEngine) Version() typex.Version {
return typex.DefaultVersion
func (e *RuleEngine) Version() typex.VersionInfo {
return typex.DefaultVersionInfo
}

func (e *RuleEngine) GetConfig() *typex.RulexConfig {
Expand Down Expand Up @@ -401,7 +401,7 @@ func (e *RuleEngine) SnapshotDump() string {
runtime.ReadMemStats(&m)

system := map[string]interface{}{
"version": e.Version().Version,
"version": typex.MainVersion,
"diskInfo": int(diskInfo.UsedPercent),
"system": utils.BToMb(m.Sys),
"alloc": utils.BToMb(m.Alloc),
Expand Down
8 changes: 4 additions & 4 deletions gen_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ cat >./typex/version.go <<EOF
// This file is generated by go compiler, don't change it!!!
package typex
type Version struct {
Version string
var MainVersion string
type VersionInfo struct {
ReleaseTime string
Arch string
Product string
Dist string
}
var DefaultVersion = Version{
var DefaultVersionInfo = VersionInfo{
Product: "COMMON",
Version: \`${VERSION}\`,
ReleaseTime: "$(echo $(date "+%Y-%m-%d %H:%M:%S"))",
}
var Banner = \`
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ func init() {
}()
env := os.Getenv("ARCHSUPPORT")
if env == "EEKITT507" {
typex.DefaultVersion.Product = env
typex.DefaultVersionInfo.Product = env
}
if env == "EEKITH3" {
typex.DefaultVersion.Product = env
typex.DefaultVersionInfo.Product = env
}
if env == "WKYS805" {
typex.DefaultVersion.Product = env
typex.DefaultVersionInfo.Product = env
}
if env == "RPI4B" {
typex.DefaultVersion.Product = env
typex.DefaultVersionInfo.Product = env
}
dist, err := utils.GetOSDistribution()
if err != nil {
panic(err)
}
typex.DefaultVersion.Dist = dist
arch := fmt.Sprintf("%s-%s", typex.DefaultVersion.Dist, runtime.GOARCH)
typex.DefaultVersion.Arch = arch
typex.DefaultVersionInfo.Dist = dist
arch := fmt.Sprintf("%s-%s", typex.DefaultVersionInfo.Dist, runtime.GOARCH)
typex.DefaultVersionInfo.Arch = arch
}

// @title Rulex API
Expand Down Expand Up @@ -275,7 +275,7 @@ func main() {
},
Action: func(*cli.Context) error {
version := fmt.Sprintf("[%v-%v-%v]",
runtime.GOOS, runtime.GOARCH, typex.DefaultVersion.Version)
runtime.GOOS, runtime.GOARCH, typex.MainVersion)
utils.CLog("[*] Rulex Version: " + version)
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion plugin/net_discover/net_boardcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (dm *NetDiscover) Start(typex.RuleX) error {
var m runtime.MemStats
runtime.ReadMemStats(&m)
hardWareInfo := map[string]interface{}{
"version": typex.DefaultVersion,
"version": typex.MainVersion,
"diskInfo": int(diskInfo.UsedPercent),
"systemMem": bToMb(m.Sys),
"allocMem": bToMb(m.Alloc),
Expand Down
2 changes: 1 addition & 1 deletion typex/rulex.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type RuleX interface {
//
// 获取版本
//
Version() Version
Version() VersionInfo

//
// 停止规则引擎
Expand Down
12 changes: 6 additions & 6 deletions typex/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
// This file is generated by go compiler, don't change it!!!
package typex

type Version struct {
Version string
var MainVersion string

type VersionInfo struct {
ReleaseTime string
Arch string
Product string
Dist string
}

var DefaultVersion = Version{
var DefaultVersionInfo = VersionInfo{
Product: "COMMON",
Version: `v0.6.4`,
ReleaseTime: "2023-12-30 19:09:35",
ReleaseTime: "2023-12-30 22:38:41",
}
var Banner = `
** Welcome to RULEX framework world <'_'>
** Version: v0.6.4-49970fe540c38a6
** Version: v0.6.5-cb68b5b9df7ae04
** Document: https://hootrhino.github.io
`

0 comments on commit f5d6732

Please sign in to comment.