天天看點

cockroach(v20.2)源碼編譯1.下載下傳代碼以及依賴環境2. 下載下傳子子產品3. 設定環境變量,下載下傳依賴包4. 編譯5. 錯誤

1.下載下傳代碼以及依賴環境

1) 由于github.com國内通路較慢,克隆gitee的鏡像

cd /media/lynn/disk_d/codes/database/cockroach
mkdir -p src/github.com/cockroachdb/
mv CockroachDB cockroach
git clone https://gitee.com/mirrors/CockroachDB.git           

2)下載下傳golang-1.15

下載下傳位址

mv go1.15.linux-amd64.tar.gz /usr/lib
tar -zxvf go1.15.linux-amd64.tar.gz           

2. 下載下傳子子產品

1) 修改子子產品位址: .gitmodules

[submodule "vendor"]
    path = vendor
    url = https://gitee.com/jianyun/vendored.git
[submodule "c-deps/jemalloc"]
    path = c-deps/jemalloc
    url = https://gitee.com/jianyun/jemalloc.git
[submodule "c-deps/protobuf"]
    path = c-deps/protobuf
    url = https://gitee.com/jianyun/protobuf.git
[submodule "pkg/ui/yarn-vendor"]
    path = pkg/ui/yarn-vendor
    url = https://gitee.com/jianyun/yarn-vendored.git
[submodule "c-deps/krb5"]
    path = c-deps/krb5
    url = https://gitee.com/jianyun/krb5.git
[submodule "c-deps/libedit"]
    path = c-deps/libedit
    url = https://gitee.com/lynninspur/libedit.git
[submodule "c-deps/geos"]
    path = c-deps/geos
    url = https://gitee.com/lynninspur/geos.git
[submodule "c-deps/proj"]
    path = c-deps/proj
    url = https://gitee.com/jianyun/PROJ.git           

執行指令

cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
git submodule init
git submodule update
git submodule sync           

2) 修改c-deps/protobuf的子子產品位址(c-deps/protobuf/.gitmodules)

[submodule "third_party/benchmark"]
    path = third_party/benchmark
    url = https://gitee.com/lynninspur/benchmark.git
[submodule "third_party/googletest"]
    path = third_party/googletest
    url = https://gitee.com/lynninspur/googletest.git
    ignore = dirty           

3. 設定環境變量,下載下傳依賴包

export GOPATH=/media/lynn/disk_d/codes/database/cockroach
cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
export GOPROXY=https://goproxy.io
export GO111MODULE=on
export GO_HOME=/usr/lib/go-1.15/
export PATH=/usr/lib/go-1.15/bin:$PATH
#下載下傳Go依賴packages
go mod tidy
go mod vendor           

4. 編譯

cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
make -j4 build           

5. 錯誤

1) 編譯錯誤

CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory           

閱讀Makefile (139行)

pkg/ui/distccl/bindata.go: $(UI_CCL_DLLS) $(UI_CCL_MANIFESTS) $(UI_JS_CCL) $(shell find pkg/ui/ccl -type f)
pkg/ui/distoss/bindata.go: $(UI_OSS_DLLS) $(UI_OSS_MANIFESTS) $(UI_JS_OSS)
pkg/ui/dist%/bindata.go: pkg/ui/webpack.app.js $(shell find pkg/ui/src pkg/ui/styl -type f) | bin/.bootstrap
   find pkg/ui/dist$* -mindepth 1 -not -name dist$*.go -delete
   set -e; shopt -s extglob; for dll in $(notdir $(filter %.dll.js,$^)); do \
     ln -s ../dist/$$dll pkg/ui/dist$*/$${dll/@(.ccl|.oss)}; \
   done
   $(NODE_RUN) -C pkg/ui $(WEBPACK) --config webpack.app.js --env.dist=$*
   go-bindata -pkg dist$* -o $@ -prefix pkg/ui/dist$* pkg/ui/dist$*/...
   echo 'func init() { ui.Asset = Asset; ui.AssetDir = AssetDir; ui.AssetInfo = AssetInfo }' >> $@
   gofmt -s -w $@
   goimports -w $@           

出錯指令

node ./node_modules/.bin/webpack --config webpack.app.js --env.dist=ccl           

手工執行

cd pkg/ui
node --max-old-space-size=4096 ./node_modules/.bin/webpack --config webpack.app.js --env.dist=ccl           

重新編譯

cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
make -j4 build           

2) GoLand Debug時報錯

GOROOT=/usr/lib/go-1.15 #gosetup
GOPATH=/media/lynn/disk_d/codes/database/cockroach:/home/lynn/go #gosetup
/usr/lib/go-1.15/bin/go build -o /tmp/___cockroach -gcflags "all=-N -l" github.com/cockroachdb/cockroach/pkg/cmd/cockroach #gosetup
/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux/dlv --listen=localhost:45269 --headless=true --api-version=2 exec /tmp/___cockroach -- start-single-node --insecure --store=/tmp/crdb --listen-addr=localhost #gosetup
API server listening at: 127.0.0.1:45269
Version of Delve is too old for this version of Go (maximum supported version 1.13, suppress this error with --check-go-version=false)           

解決辦法

# 下載下傳最新版本dlv
export GOPATH=/media/lynn/disk_d/codes/database/cockroach
go get -u github.com/go-delve/delve/cmd/dlv

# 查找dlv所在位置
lynn@lynn-ubuntu:/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux$ echo `go env | grep GOPATH | cut -d "\"" -f 2`/bin/dlv
/media/lynn/disk_d/codes/database/cockroach/bin/dlv

#檢視版本
lynn@lynn-ubuntu:/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux$ /media/lynn/disk_d/codes/database/cockroach/bin/dlv version
Delve Debugger
Version: 1.5.1
Build: $Id: bca418ea7ae2a4dcda985e623625da727d4525b5 $
lynn@lynn-ubuntu:/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux$ /opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux/dlv version
Delve Debugger
Version: 1.3.0
Build: a82e6d69875ed11a0bb3b80d15efba4b4722106e           

設定GoLand

在 GoLand 中 Help -> Edit Custom Properties(之前沒編輯過會提示建立)
新增一項 dlv.path={你複制的路徑},比如我的:
dlv.path=/media/lynn/disk_d/codes/database/cockroach/bin/dlv
重新啟動GoLand,即可解決該問題           

3)編譯時找不到依賴

GOPATH set to /codes/database/crdb
cannot find package "github.com/client9/misspell/cmd/misspell" in any of:
    /usr/lib/go-1.15/src/github.com/client9/misspell/cmd/misspell (from $GOROOT)
    /codes/database/crdb/src/github.com/client9/misspell/cmd/misspell (from $GOPATH)
cannot find package "github.com/cockroachdb/crlfmt" in any of:
    /usr/lib/go-1.15/src/github.com/cockroachdb/crlfmt (from $GOROOT)
    /codes/database/crdb/src/github.com/cockroachdb/crlfmt (from $GOPATH)
cannot find package "github.com/cockroachdb/gostdlib/cmd/gofmt" in any of:
    /usr/lib/go-1.15/src/github.com/cockroachdb/gostdlib/cmd/gofmt (from $GOROOT)
    /codes/database/crdb/src/github.com/cockroachdb/gostdlib/cmd/gofmt (from $GOPATH)
cannot find package "github.com/cockroachdb/gostdlib/x/tools/cmd/goimports" in any of:
    /usr/lib/go-1.15/src/github.com/cockroachdb/gostdlib/x/tools/cmd/goimports (from $GOROOT)
    /codes/database/crdb/src/github.com/cockroachdb/gostdlib/x/tools/cmd/goimports (from $GOPATH)
cannot find package "github.com/cockroachdb/stress" in any of:
    /usr/lib/go-1.15/src/github.com/cockroachdb/stress (from $GOROOT)
    /codes/database/crdb/src/github.com/cockroachdb/stress (from $GOPATH)
cannot find package "github.com/goware/modvendor" in any of:
    /usr/lib/go-1.15/src/github.com/goware/modvendor (from $GOROOT)
    /codes/database/crdb/src/github.com/goware/modvendor (from $GOPATH)
cannot find package "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway" in any of:
    /usr/lib/go-1.15/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway (from $GOROOT)
    /codes/database/crdb/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway (from $GOPATH)
cannot find package "github.com/kevinburke/go-bindata/go-bindata" in any of:
    /usr/lib/go-1.15/src/github.com/kevinburke/go-bindata/go-bindata (from $GOROOT)
    /codes/database/crdb/src/github.com/kevinburke/go-bindata/go-bindata (from $GOPATH)
cannot find package "github.com/kisielk/errcheck" in any of:
    /usr/lib/go-1.15/src/github.com/kisielk/errcheck (from $GOROOT)
    /codes/database/crdb/src/github.com/kisielk/errcheck (from $GOPATH)
cannot find package "github.com/mattn/goveralls" in any of:
    /usr/lib/go-1.15/src/github.com/mattn/goveralls (from $GOROOT)
    /codes/database/crdb/src/github.com/mattn/goveralls (from $GOPATH)
cannot find package "github.com/mibk/dupl" in any of:
    /usr/lib/go-1.15/src/github.com/mibk/dupl (from $GOROOT)
    /codes/database/crdb/src/github.com/mibk/dupl (from $GOPATH)
cannot find package "github.com/mmatczuk/go_generics/cmd/go_generics" in any of:
    /usr/lib/go-1.15/src/github.com/mmatczuk/go_generics/cmd/go_generics (from $GOROOT)
    /codes/database/crdb/src/github.com/mmatczuk/go_generics/cmd/go_generics (from $GOPATH)
cannot find package "github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc" in any of:
    /usr/lib/go-1.15/src/github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc (from $GOROOT)
    /codes/database/crdb/src/github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc (from $GOPATH)
cannot find package "github.com/wadey/gocovmerge" in any of:
    /usr/lib/go-1.15/src/github.com/wadey/gocovmerge (from $GOROOT)
    /codes/database/crdb/src/github.com/wadey/gocovmerge (from $GOPATH)
cannot find package "golang.org/x/lint/golint" in any of:
    /usr/lib/go-1.15/src/golang.org/x/lint/golint (from $GOROOT)
    /codes/database/crdb/src/golang.org/x/lint/golint (from $GOPATH)
cannot find package "golang.org/x/perf/cmd/benchstat" in any of:
    /usr/lib/go-1.15/src/golang.org/x/perf/cmd/benchstat (from $GOROOT)
    /codes/database/crdb/src/golang.org/x/perf/cmd/benchstat (from $GOPATH)
cannot find package "golang.org/x/tools/cmd/goyacc" in any of:
    /usr/lib/go-1.15/src/golang.org/x/tools/cmd/goyacc (from $GOROOT)
    /codes/database/crdb/src/golang.org/x/tools/cmd/goyacc (from $GOPATH)
cannot find package "golang.org/x/tools/cmd/stringer" in any of:
    /usr/lib/go-1.15/src/golang.org/x/tools/cmd/stringer (from $GOROOT)
    /codes/database/crdb/src/golang.org/x/tools/cmd/stringer (from $GOPATH)
cannot find package "golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow" in any of:
    /usr/lib/go-1.15/src/golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow (from $GOROOT)
    /codes/database/crdb/src/golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow (from $GOPATH)
cannot find package "honnef.co/go/tools/cmd/staticcheck" in any of:
    /usr/lib/go-1.15/src/honnef.co/go/tools/cmd/staticcheck (from $GOROOT)
    /codes/database/crdb/src/honnef.co/go/tools/cmd/staticcheck (from $GOPATH)
Makefile:374: recipe for target 'bin/.bootstrap' failed
make: *** [bin/.bootstrap] Error 1           
export GO111MODULE=on
make -j1 bin/.bootstrap --trace           
go mod tidy

warning: ignoring symlink /media/os/go/src/github.com/cockroachdb/cockroach/c-deps/libedit/include/editline
go: downloading golang.org/x/exp v0.0.0-20200513190911-00229845015e
go: downloading github.com/klauspost/compress v1.12.2
go: downloading golang.org/x/text v0.3.6
go: downloading golang.org/x/mod v0.4.2
go: downloading github.com/russross/blackfriday/v2 v2.0.1
go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0
github.com/cockroachdb/cockroach/pkg/acceptance imports
    github.com/cockroachdb/errors imports
    github.com/cockroachdb/errors/errbase imports
    io/fs: package io/fs is not in GOROOT (/usr/lib/go-1.15/src/io/fs)
           

繼續閱讀