Search code examples
gogithubbuild-systemgo-getgo-build

go build does not compile local changes into main


I am relatively new to go, and I am having some trouble with the go build system.

GO Environment:

(base) ngadre-mbp:github.com ngadre$ go version
go version go1.14.5 darwin/amd64

(base) ngadre-mbp:github.com ngadre$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ngadre/Library/Caches/go-build"
GOENV="/Users/ngadre/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ngadre/Desktop/Workspace/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5g/59l0__050lg6p4hv1wv7mhw40000gn/T/go-build110012391=/tmp/go-build -gno-record-gcc-switches -fno-common"

My directory structure is as below:

pwd: /Users/ngadre/Desktop/Workspace/go/src/github.com
.
├── coredhcp
│   ├── LICENSE
│   ├── README.md
│   ├── cmds
│   │   ├── client
│   │   ├── coredhcp
│   │   └── coredhcp-generator
│   ├── config
│   │   ├── config.go
│   │   ├── config_test.go
│   │   └── errors.go
│   ├── go.mod
│   ├── go.sum
│   ├── handler
│   │   └── handler.go
│   ├── logger
│   │   └── logger.go
│   ├── plugins
│   │   ├── dns
│   │   ├── example
│   │   ├── file
│   │   ├── leasetime
│   │   ├── nbp
│   │   ├── netmask
│   │   ├── plugin.go
│   │   ├── range
│   │   ├── router
│   │   └── serverid
│   └── server
│       ├── handle.go
│       └── serve.go
├── go-immutable-radix
│   ├── CHANGELOG.md
│   ├── LICENSE
│   ├── README.md
│   ├── edges.go
│   ├── go.mod
│   ├── go.sum
│   ├── iradix.go
│   ├── iradix_test.go
│   ├── iter.go
│   ├── node.go
│   └── raw_iter.go

Both the projects "coredhcp" and "go-immutable-radix" I have cloned using git clone

I did some changes to the "go-immutable-radix" project and added logs, however, I am not able to build my local changes into the "coredhcp" project which uses this "go-immutable-radix" project.

go build cmds/coredhcp/main.go

Any suggestions how I can compile local changes in "A" project into "X" project through go build.


Solution

  • If you have a locally cloned version of another go module, use the replace directive in the go.mod (the go.mod for the coredhcp package) to point the local copy:

    replace github.com/.../go-immutable-radix => ../go-immutable-radix