4 Star 6 Fork 3

王军/golib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gobuild.sh 4.56 KB
一键复制 编辑 原始数据 按行查看 历史
王军 提交于 2024-11-10 17:53 . 清理仓库历史
#!/bin/bash -e
#$1 当前的工作目录,必须传递的参数
#这行代码兼容windows
PATH="/d/Program Files/Git/bin":$PATH
#===========================以下代码勿动===============================
DIR=$1
OS=$(uname -s)
BuildDate=$(date "+%Y-%m-%d")
BuildTime=$(date "+%H:%M:%S")
PluginDate=$(date "+%Y%m%d")
PluginOS="linux"
#结束调用此函数
end(){
echo "======================== END ========================"
#exit
}
if [ $# -lt 1 ]; then
#echo " LOST PARAMTERS"
DIR=$(pwd)
echo $DIR
#end
fi
#切换到工作目录
cd $DIR
set +e
output=$(git log -1 --pretty=format:'OK: %H %ci')
set -e
array=(${output/// })
IsOK=${array[0]}
GitDate=
GitCommit=
if [ "$IsOK" == "OK:" ]; then
GitCommit=${array[1]}
GitDate=${array[2]}" "${array[3]}
fi
PluginPath=$(basename $DIR)
#运行程序
test(){
#切换到工作目录
echo go test -v $DIR
go test -v $DIR
end
}
#运行程序
run(){
#切换到工作目录
cd $DIR
echo $DIR
#echo $(basename $1)
#binName=$(basename($1))
#echo $binName
./$(basename $DIR)
end
}
#编译程序
build(){
if [ -n "$GitCommit" ]; then
#echo go build -ldflags "-X goversion.buildDate=$BuildDate -X 'goversion.gitDate=$GitDate' -X goversion.gitCommit=$GitCommit"
# -extldflags -static
go build -tags jsoniter -ldflags "-X goversion.buildDate=$BuildDate -X 'goversion.gitDate=$GitDate' -X goversion.gitCommit=$GitCommit -X goversion.buildTime=$BuildTime"
else
go build -tags jsoniter -ldflags "-X goversion.buildDate=$BuildDate -X goversion.buildTime=$BuildTime "
fi
if [ -f "main.go" ]; then
which swag >/dev/null 2>&1 && swag init
rm -f docs/docs.go
fi
end
}
#编译远程版本
build_remote(){
if [ -f "build.sh" ]; then
if [ -x "build.sh" ]; then
chmod +x build.sh
fi
../build.sh
else
echo "Not found build.sh"
fi
}
#编译插件
buildPlugin(){
go build -buildmode=plugin -ldflags "-X main.buildDate=$BuildDate"
echo $PluginPath
if [ ! -d "$PluginPath" ]; then
mkdir $PluginPath
fi
mv "${PluginPath}.so" $PluginPath
tar zcvf "${PluginPath}.${PluginDate}.${PluginOS}.tar.gz" $PluginPath
end
}
export CGO_ENABLED=1
case $# in
0)
export GOARCH=
export GOOS=
export CC=
export CXX=
if [ "$OS" == "Linux" ]; then
echo "================ BUILD LINUX VERSION ================"
else
echo "=============== BUILD WINDOWS VERSION ==============="
fi
build
;;
1)
export GOARCH=
export GOOS=
export CC=
export CXX=
if [ "$OS" == "Linux" ]; then
echo "================ BUILD LINUX VERSION ================"
else
echo "=============== BUILD WINDOWS VERSION ==============="
fi
build
;;
2)
case $2 in
"win32")
export GOARCH=386
export CC=
export CXX=
export CGO_ENABLED=0
build
;;
"remote")
build_remote
;;
"buildRun")
set +e
echo "================ BUILD ================"
build
echo "================ RUN ================"
run
;;
"linuxNoCgo")
echo "============ BUILD LINUX WITHOUT CGO VERSION ============="
export GOARCH=
export GOOS=linux
export CC=
export CXX=
export CGO_ENABLED=0
build
;;
"linux")
echo "============ BUILD LINUX VERSION ============="
export GOARCH=
export GOOS=linux
export CC=
export CXX=
build
;;
"run")
echo "======================== RUN ========================"
run
;;
"test")
echo "======================== TEST ======================="
test
;;
"arm")
export GOARCH=arm
export GOARM=6
export GOOS=linux
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
echo "================ BUILD ARM VERSION =================="
build
;;
"plugin")
echo "============ BUILD LINUX PLUGIN VERSION ============="
export GOARCH=
export GOOS=
export CC=
export CXX=
buildPlugin
;;
"plugin_arm")
echo "============= BUILD ARM PLUGIN VERSION =============="
export GOARCH=arm
export GOARM=6
export GOOS=linux
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
PluginOS="arm"
buildPlugin
;;
"arm5")
export GOARCH=arm
export GOARM=5
export GOOS=linux
export CC=
export CXX=
export CGO_ENABLED=
echo "=============== BUILD ARM 5 VERSION ================="
build
;;
*)
echo "ERROR PARAMTERS $2"
echo "Usage: $0 dir [arm|plugin|plugin_arm]"
end
;;
esac
;;
*)
echo "ERROR PARAMTERS"
echo "Usage: $0 dir [arm]"
end
;;
esac
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/haodreams/golib.git
[email protected]:haodreams/golib.git
haodreams
golib
golib
master

搜索帮助