diff options
Diffstat (limited to 'eclass/golang-base.eclass')
-rw-r--r-- | eclass/golang-base.eclass | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/eclass/golang-base.eclass b/eclass/golang-base.eclass index 5fabff6..a605038 100644 --- a/eclass/golang-base.eclass +++ b/eclass/golang-base.eclass @@ -159,7 +159,7 @@ GOLANG_PKG_TAGS="${GOLANG_PKG_TAGS:-}" # Sets additional standard Go workspaces to be appended to the environment # variable GOPATH, as described in http://golang.org/doc/code.html. # This eclass defaults to an empty list. -GOLANG_PKG_VENDOR="${GOLANG_PKG_VENDOR:-}" +GOLANG_PKG_VENDOR=() # @ECLASS-VARIABLE: GOLANG_PKG_STATIK # @DESCRIPTION: @@ -242,6 +242,7 @@ if [[ ${GOLANG_PKG_ARCHIVESUFFIX/.*} == "xz" ]]; then fi # Enables USE 'test' when required by GOLANG_PKG_HAVE_TEST. +IUSE="${IUSE} debug" if [[ -n ${GOLANG_PKG_HAVE_TEST} ]]; then IUSE+=" test" fi @@ -369,6 +370,10 @@ golang_setup() { einfo "Found statik version: ${STATIK_VERSION}" fi + # Enable/Disable frame pointers + local GOEXPERIMENT="noframepointer" + use debug && GOEXPERIMENT="framepointer" + # Sets the build environment inside Portage's WORKDIR. ebegin "Setting up GoLang build environment" @@ -389,6 +394,8 @@ golang_setup() { export GOPATH="$_GOPATH" export GOBIN="$_GOBIN" export CGO_ENABLED + export GOEXPERIMENT + export GO15VENDOREXPERIMENT=0 debug-print "${FUNCNAME}: GOPATH = ${GOPATH}" debug-print "${FUNCNAME}: GOBIN = ${GOBIN}" @@ -514,6 +521,7 @@ golang-base_src_prepare() { local VENDOR="${S}/vendor" if [[ -d "${VENDOR}" ]]; then golang_add_vendor "${VENDOR}" + export GO15VENDOREXPERIMENT=1 fi # Auto-detects the presence of Go's vendored @@ -541,7 +549,7 @@ golang-base_src_prepare() { # (see github.com/tools/godep for more infos). VENDOR="${S}/Godeps/_workspace" if [[ -d "${VENDOR}" ]]; then - GOLANG_PKG_VENDOR+=" ${VENDOR}" + golang_add_vendor "${VENDOR}" fi @@ -670,22 +678,19 @@ golang-base_src_compile() { [[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)." # Populates env variable GOPATH with vendored workspaces (if present). - if [[ -n ${GOLANG_PKG_VENDOR} || "1" == ${GO15VENDOREXPERIMENT} ]]; then + if [[ -n ${GOLANG_PKG_VENDOR} ]]; then einfo "Using vendored dependencies from:" - # Prints Go's vendored directory. - if [[ "1" == ${GO15VENDOREXPERIMENT} ]]; then - einfo "- vendor" - fi - fi - - # Prints user defined vendored directories. - if [[ -n ${GOLANG_PKG_VENDOR} ]]; then for path in "${GOLANG_PKG_VENDOR[@]}"; do [ -d ${path} ] || continue + if [[ ${path//${S}\//} == "vendor" ]]; then + einfo "- vendor/ (native vendoring support)" + continue + fi + debug-print "$FUNCNAME: GOPATH: Adding vendor path ${path}" - ebegin "- ${path//${WORKDIR}\//}" + ebegin "- ${path//${S}\//}" GOPATH="${GOPATH}:$( echo ${path} )" eend done @@ -774,10 +779,10 @@ golang-base_src_install() { # Executes the pre-install phase (go install). if [[ -n ${GOLANG_PKG_IS_MULTIPLE} ]]; then - einfo "${EGO} install -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' ${EGO_BUILD_FLAGS}" + einfo "${EGO} install -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' ${EGO_BUILD_FLAGS} ${EGO_SUBPACKAGES}" ${EGO} install \ - -ldflags "-s -w $( echo ${GOLANG_PKG_LDFLAGS} )" \ - -tags "$( echo ${GOLANG_PKG_TAGS} )" \ + -ldflags "${GOLANG_PKG_LDFLAGS}" \ + -tags "${GOLANG_PKG_TAGS}" \ ${EGO_BUILD_FLAGS} \ "${EGO_SUBPACKAGES}" \ || die @@ -826,7 +831,7 @@ golang-base_src_test() { # Defines sub-packages. local EGO_SUBPACKAGES="${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${GOLANG_PKG_BUILDPATH}" - [[ -n ${GOLANG_PKG_IS_MULTIPLE} ]] || EGO_SUBPACKAGES="./..." + [[ -z ${GOLANG_PKG_IS_MULTIPLE} ]] || EGO_SUBPACKAGES="./..." # Runs the unit tests. einfo "${EGO} test ${EGO_BUILD_FLAGS} ${EGO_SUBPACKAGES}" @@ -854,18 +859,25 @@ golang_do_build() { [[ ${GOLANG_VERSION} ]] || die "No GoLang implementation set (golang_setup not called?)." - # Filters "=" chars from ldflags declaration - # NOTE: from go1.5+ linker syntax is no more compatible with <go1.4; this hack - # ensures that the old behaviour is honoured. + # Filters "=" chars from ldflags declaration. + # NOTE: from go1.5+ linker syntax is no more compatible with <go1.4; + # this hack ensures that the old behaviour is honoured. if [[ $( get_version_component_range 1-2 ${GOLANG_VERSION} ) == "1.4" ]]; then GOLANG_PKG_LDFLAGS="${GOLANG_PKG_LDFLAGS//=/ }" fi + # Disables debug symbols (DWARF) when not required. + ! use debug && GOLANG_PKG_LDFLAGS="-s -w ${GOLANG_PKG_LDFLAGS}" + + # Sanitizes vars from entra white spaces. + GOLANG_PKG_LDFLAGS="$( echo ${GOLANG_PKG_LDFLAGS} )" + GOLANG_PKG_TAGS="$( echo ${GOLANG_PKG_TAGS} )" + einfo "${EGO} build -ldflags '$GOLANG_PKG_LDFLAGS' -tags '$GOLANG_PKG_TAGS' $*" ${EGO} build \ - -ldflags "-s -w $( echo ${GOLANG_PKG_LDFLAGS} )" \ - -tags "$( echo ${GOLANG_PKG_TAGS} )" \ - $* \ + -ldflags "${GOLANG_PKG_LDFLAGS}" \ + -tags "${GOLANG_PKG_TAGS}" \ + $( echo $* ) \ || die } @@ -888,22 +900,16 @@ golang_add_vendor() { [[ ${GOLANG_VERSION} ]] || die "No Golang implementation set (golang_setup not called?)." - case $( get_version_component_range 1-2 ${GOLANG_VERSION} ) in - 1.4*) - # TODO: traverse $1 and expose all the bundled /vendor - # sub-directories to GOLANG_PKG_VENDOR - if [[ ! -d "${1}"/src ]]; then - ebegin "Fixing $1" - ln -s "${1}" "${1}"/src || die - eend - fi + [[ ! -d "${1}" ]] && return - GOLANG_PKG_VENDOR+=" ${1}" - ;; - 1.5*) - export GO15VENDOREXPERIMENT=1 - ;; - esac + # NOTE: this hack is required by Go v1.4 and older versions. + if [[ ! -d "${1}"/src ]]; then + ebegin "Fixing $1" + ln -s "${1}" "${1}"/src || die + eend + fi + + GOLANG_PKG_VENDOR+=(${1}) } |