xref: /OK3568_Linux_fs/yocto/poky/meta/classes/go-mod.bbclass (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Handle Go Modules support
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# When using Go Modules, the the current working directory MUST be at or below
4*4882a593Smuzhiyun# the location of the 'go.mod' file when the go tool is used, and there is no
5*4882a593Smuzhiyun# way to tell it to look elsewhere.  It will automatically look upwards for the
6*4882a593Smuzhiyun# file, but not downwards.
7*4882a593Smuzhiyun#
8*4882a593Smuzhiyun# To support this use case, we provide the `GO_WORKDIR` variable, which defaults
9*4882a593Smuzhiyun# to `GO_IMPORT` but allows for easy override.
10*4882a593Smuzhiyun#
11*4882a593Smuzhiyun# Copyright 2020 (C) O.S. Systems Software LTDA.
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun# The '-modcacherw' option ensures we have write access to the cached objects so
14*4882a593Smuzhiyun# we avoid errors during clean task as well as when removing the TMPDIR.
15*4882a593SmuzhiyunGOBUILDFLAGS:append = " -modcacherw"
16*4882a593Smuzhiyun
17*4882a593Smuzhiyuninherit go
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunGO_WORKDIR ?= "${GO_IMPORT}"
20*4882a593Smuzhiyundo_compile[dirs] += "${B}/src/${GO_WORKDIR}"
21