Fix: fix cli build bug

Signed-off-by: zhuzhengyi1 <zhuzhengyi@jd.com>
This commit is contained in:
zhuzhengyi1 2020-07-24 16:04:57 +08:00
parent ef58331084
commit 4277d441c7
3 changed files with 26 additions and 17 deletions

View File

@ -16,7 +16,7 @@ CLIENT2_SRC := $(wildcard clientv2/*.go clientv2/fs/*.go sdk/*.go)
AUTHTOOL_SRC := $(wildcard authtool/*.go)
CLI_SRC := $(wildcard cli/*.go)
RM := $(shell [ -x /bin/rm ] && echo "/bin/rm -rf" || echo "/usr/bin/rm -rf" )
RM := $(shell [ -x /bin/rm ] && echo "/bin/rm" || echo "/usr/bin/rm" )
default: all
@ -31,7 +31,7 @@ server: $(BIN_SERVER)
client: $(BIN_CLIENT)
client2: $(BIN_CLIENT2)
authtool: $(BIN_AUTHTOOL)
cli: $(BIN_CLI)
@ -44,7 +44,7 @@ $(BIN_CLIENT): $(COMMON_SRC) $(CLIENT_SRC)
$(BIN_CLIENT2): $(COMMON_SRC) $(CLIENT2_SRC)
@build/build.sh client2
$(BIN_AUTHTOOL): $(COMMON_SRC) $(AUTHTOOL_SRC)
@build/build.sh authtool
@ -53,12 +53,12 @@ $(BIN_CLI): $(COMMON_SRC) $(CLI_SRC)
phony += clean
clean:
@$(RM) build/bin
@$(RM) -rf build/bin
phony += dist_clean
phony += dist-clean
dist-clean:
@$(RM) build/bin
@$(RM) build/out
@$(RM) -rf build/bin
@$(RM) -rf build/out
phony += test
test:

View File

@ -281,7 +281,8 @@ build_cli() {
pre_build
pushd $SrcPath >/dev/null
echo -n "build cfs-cli "
go build $MODFLAGS -ldflags "${LDFlags}" -o ${BuildBinPath}/cfs-cli ${SrcPath}/cli/*.go && echo "success" || echo "failed"
#go build $MODFLAGS -ldflags "${LDFlags}" -o ${BuildBinPath}/cfs-cli ${SrcPath}/cli/*.go && echo "success" || echo "failed"
sh cli/build.sh ${BuildBinPath}/cfs-cli && echo "success" || echo "failed"
popd >/dev/null
}

View File

@ -1,14 +1,22 @@
#!/usr/bin/env bash
Version=`git describe --abbrev=0 --tags`
BranchName=`git rev-parse --abbrev-ref HEAD`
CommitID=`git rev-parse HEAD`
RootPath=$(cd $(dirname $0)/..; pwd)
Version=`git describe --abbrev=0 --tags 2>/dev/null`
BranchName=`git rev-parse --abbrev-ref HEAD 2>/dev/null`
CommitID=`git rev-parse HEAD 2>/dev/null`
BuildTime=`date +%Y-%m-%d\ %H:%M`
SrcPath=${RootPath}/cli
TargetFile=${1:-$RootPath/cli/cfs-cli}
[[ "-$GOPATH" == "-" ]] && { echo "GOPATH not set"; exit 1; }
go build -ldflags "\
-X github.com/chubaofs/chubaofs/proto.Version=${Version} \
-X github.com/chubaofs/chubaofs/proto.CommitID=${CommitID} \
-X github.com/chubaofs/chubaofs/proto.BranchName=${BranchName} \
-X 'github.com/chubaofs/chubaofs/proto.BuildTime=${BuildTime}'" \
-o cfs-cli
LDFlags="-X github.com/chubaofs/chubaofs/proto.Version=${Version} \
-X github.com/chubaofs/chubaofs/proto.CommitID=${CommitID} \
-X github.com/chubaofs/chubaofs/proto.BranchName=${BranchName} \
-X 'github.com/chubaofs/chubaofs/proto.BuildTime=${BuildTime}' "
go build \
-ldflags "${LDFLAGS}" \
-o $TargetFile \
${SrcPath}/*.go