diff options
author | 2024-06-09 23:17:15 +0100 | |
---|---|---|
committer | 2024-06-09 23:17:15 +0100 | |
commit | 2620a7e6416b23e8849ab44fe29ef8120f449c38 (patch) | |
tree | 97aeb0fedca00ed8650934bf38b11b9631087198 /eclass | |
parent | Update terraform and golang eclasses (diff) | |
download | ssnb-2620a7e6416b23e8849ab44fe29ef8120f449c38.tar.gz ssnb-2620a7e6416b23e8849ab44fe29ef8120f449c38.tar.bz2 ssnb-2620a7e6416b23e8849ab44fe29ef8120f449c38.zip |
Update terraform provider libvirt and add required golang eclasses
Signed-off-by: Samuel Bernardo <samuelbernardo.mail@gmail.com>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/go-env.eclass | 112 | ||||
-rw-r--r-- | eclass/golang-base.eclass | 94 | ||||
-rw-r--r-- | eclass/golang-build.eclass | 85 | ||||
-rw-r--r-- | eclass/golang-vcs-snapshot.eclass | 129 |
4 files changed, 420 insertions, 0 deletions
diff --git a/eclass/go-env.eclass b/eclass/go-env.eclass new file mode 100644 index 0000000..2cd5506 --- /dev/null +++ b/eclass/go-env.eclass @@ -0,0 +1,112 @@ +# Copyright 2023-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: go-env.eclass +# @MAINTAINER: +# Samuel Bernardo <samuelbernardo.mail@gmail.com> +# @AUTHOR: +# Flatcar Linux Maintainers <infra@flatcar-linux.org> +# @BLURB: Helper eclass for setting the Go compile environment. Required for cross-compiling. +# @DESCRIPTION: +# This eclass includes helper functions for setting the compile environment for Go ebuilds. +# Intended to be called by other Go eclasses in an early build stage, e.g. src_unpack. + +if [[ -z ${_GO_ENV_ECLASS} ]]; then +_GO_ENV_ECLASS=1 + +inherit flag-o-matic toolchain-funcs + +# @FUNCTION: go-env_set_compile_environment +# @DESCRIPTION: +# Set up basic compile environment: CC, CXX, and GOARCH. +# Necessary platform-specific settings such as GOARM or GO386 are also set +# according to the Portage configuration when building for those architectures. +# Also carry over CFLAGS, LDFLAGS and friends. +# Required for cross-compiling with crossdev. +# If not set, host defaults will be used and the resulting binaries are host arch. +# (e.g. "emerge-aarch64-cross-linux-gnu foo" run on x86_64 will emerge "foo" for x86_64 +# instead of aarch64) +go-env_set_compile_environment() { + tc-export CC CXX PKG_CONFIG + + export GOARCH="$(go-env_goarch)" + use arm && export GOARM=$(go-env_goarm) + use x86 && export GO386=$(go-env_go386) + + # XXX: Hack for checking ICE (bug #912152, gcc PR113204) + case ${EAPI} in + 6) + has_version "sys-devel/gcc[debug]" && filter-lto + ;; + *) + has_version -b "sys-devel/gcc[debug]" && filter-lto + ;; + esac + + export CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}" + export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}" + export CGO_CXXFLAGS="${CGO_CXXFLAGS:-$CXXFLAGS}" + export CGO_LDFLAGS="${CGO_LDFLAGS:-$LDFLAGS}" +} + +# @FUNCTION: go-env_goarch +# @USAGE: [toolchain prefix] +# @DESCRIPTION: +# Returns the appropriate GOARCH setting for the target architecture. +go-env_goarch() { + # By chance most portage arch names match Go + local tc_arch=$(tc-arch $@) + case "${tc_arch}" in + x86) echo 386;; + x64-*) echo amd64;; + loong) echo loong64;; + mips) if use abi_mips_o32; then + [[ $(tc-endian $@) = big ]] && echo mips || echo mipsle + elif use abi_mips_n64; then + [[ $(tc-endian $@) = big ]] && echo mips64 || echo mips64le + fi ;; + ppc64) [[ $(tc-endian $@) = big ]] && echo ppc64 || echo ppc64le ;; + riscv) echo riscv64 ;; + s390) echo s390x ;; + *) echo "${tc_arch}";; + esac +} + +# @FUNCTION: go-env_go386 +# @DESCRIPTION: +# Returns the appropriate GO386 setting for the CFLAGS in use. +go-env_go386() { + # Piggy-back off any existing CPU_FLAGS_X86 usage in the ebuild if + # it's there. + if in_iuse cpu_flags_x86_sse2 && use cpu_flags_x86_sse2 ; then + echo 'sse2' + return + fi + + if tc-cpp-is-true "defined(__SSE2__)" ${CFLAGS} ${CXXFLAGS} ; then + echo 'sse2' + return + fi + + # Go 1.16 dropped explicit support for 386 FP and relies on software + # emulation instead in the absence of SSE2. + echo 'softfloat' +} + +# @FUNCTION: go-env_goarm +# @USAGE: [CHOST-value] +# @DESCRIPTION: +# Returns the appropriate GOARM setting for the CHOST given, or the default +# CHOST. +go-env_goarm() { + case "${1:-${CHOST}}" in + armv5*) echo 5;; + armv6*) echo 6;; + armv7*) echo 7;; + *) + die "unknown GOARM for ${1:-${CHOST}}" + ;; + esac +} + +fi diff --git a/eclass/golang-base.eclass b/eclass/golang-base.eclass new file mode 100644 index 0000000..5b3b6fd --- /dev/null +++ b/eclass/golang-base.eclass @@ -0,0 +1,94 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: golang-base.eclass +# @MAINTAINER: +# Samuel Bernardo <samuelbernardo.mail@gmail.com> +# @AUTHORS: +# William Hubbs <williamh@gentoo.org> +# @SUPPORTED_EAPIS: 5 6 7 +# @BLURB: Eclass that provides base functions for Go packages. +# @DEPRECATED: go-module.eclass +# @DESCRIPTION: +# This eclass provides base functions for software written in the Go +# programming language; it also provides the build-time dependency on +# dev-lang/go. + +case "${EAPI:-0}" in + 8) + ;; + *) + die "${ECLASS}: Unsupported EAPI (EAPI=${EAPI})" + ;; +esac + +if [[ -z ${_GOLANG_BASE} ]]; then + +_GOLANG_BASE=1 + +GO_DEPEND=">=dev-lang/go-1.10" +if [[ ${EAPI:-0} == [56] ]]; then + DEPEND="${GO_DEPEND}" +else + BDEPEND="${GO_DEPEND}" +fi + +# Do not complain about CFLAGS etc since go projects do not use them. +QA_FLAGS_IGNORED='.*' + +# Upstream does not support stripping go packages +RESTRICT="strip" + +# force GO111MODULE to be auto for bug https://bugs.gentoo.org/771129 +export GO111MODULE=auto + +# @ECLASS_VARIABLE: EGO_PN +# @REQUIRED +# @DESCRIPTION: +# This is the import path for the go package to build. Please emerge +# dev-lang/go and read "go help importpath" for syntax. +# +# Example: +# @CODE +# EGO_PN=github.com/user/package +# @CODE + +# @FUNCTION: ego_pn_check +# @DESCRIPTION: +# Make sure EGO_PN has a value. +ego_pn_check() { + [[ -z "${EGO_PN}" ]] && + die "${ECLASS}.eclass: EGO_PN is not set" + return 0 +} + +# @FUNCTION: get_golibdir +# @DESCRIPTION: +# Return the non-prefixed library directory where Go packages +# should be installed +get_golibdir() { + echo /usr/lib/go-gentoo +} + +# @FUNCTION: get_golibdir_gopath +# @DESCRIPTION: +# Return the library directory where Go packages should be installed +# This is the prefixed version which should be included in GOPATH +get_golibdir_gopath() { + echo "${EPREFIX}$(get_golibdir)" +} + +# @FUNCTION: golang_install_pkgs +# @DESCRIPTION: +# Install Go packages. +# This function assumes that $cwd is a Go workspace. +golang_install_pkgs() { + debug-print-function ${FUNCNAME} "$@" + + ego_pn_check + insinto "$(get_golibdir)" + insopts -m0644 -p # preserve timestamps for bug 551486 + doins -r pkg src +} + +fi diff --git a/eclass/golang-build.eclass b/eclass/golang-build.eclass new file mode 100644 index 0000000..75e77ce --- /dev/null +++ b/eclass/golang-build.eclass @@ -0,0 +1,85 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: golang-build.eclass +# @MAINTAINER: +# Samuel Bernardo <samuelbernardo.mail@gmail.com> +# @AUTHORS: +# William Hubbs <williamh@gentoo.org> +# @SUPPORTED_EAPIS: 6 7 +# @PROVIDES: golang-base +# @BLURB: Eclass for compiling go packages. +# @DEPRECATED: go-module.eclass +# @DESCRIPTION: +# This eclass provides default src_compile, src_test and src_install +# functions for software written in the Go programming language. + +case ${EAPI} in + 8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +if [[ -z ${_GOLANG_BUILD_ECLASS} ]]; then +_GOLANG_BUILD_ECLASS=1 + +inherit golang-base + +# @ECLASS_VARIABLE: EGO_BUILD_FLAGS +# @DEFAULT_UNSET +# @DESCRIPTION: +# This allows you to pass build flags to the Go compiler. These flags +# are common to the "go build" and "go install" commands used below. +# Please emerge dev-lang/go and run "go help build" for the +# documentation for these flags. +# +# Example: +# @CODE +# EGO_BUILD_FLAGS="-ldflags \"-X main.version ${PV}\"" +# @CODE + +# @ECLASS_VARIABLE: EGO_PN +# @REQUIRED +# @DESCRIPTION: +# This is the import path for the go package(s) to build. Please emerge +# dev-lang/go and read "go help importpath" for syntax. +# +# Example: +# @CODE +# EGO_PN=github.com/user/package +# @CODE + +golang-build_src_compile() { + debug-print-function ${FUNCNAME} "$@" + + ego_pn_check + set -- env GOPATH="${WORKDIR}/${P}:$(get_golibdir_gopath)" \ + GOCACHE="${T}/go-cache" \ + go build -v -work -x ${EGO_BUILD_FLAGS} "${EGO_PN}" + echo "$@" + "$@" || die +} + +golang-build_src_install() { + debug-print-function ${FUNCNAME} "$@" + + ego_pn_check + set -- env GOPATH="${WORKDIR}/${P}:$(get_golibdir_gopath)" \ + go install -v -work -x ${EGO_BUILD_FLAGS} "${EGO_PN}" + echo "$@" + "$@" || die + golang_install_pkgs +} + +golang-build_src_test() { + debug-print-function ${FUNCNAME} "$@" + + ego_pn_check + set -- env GOPATH="${WORKDIR}/${P}:$(get_golibdir_gopath)" \ + go test -v -work -x "${EGO_PN}" + echo "$@" + "$@" || die +} + +fi + +EXPORT_FUNCTIONS src_compile src_install src_test diff --git a/eclass/golang-vcs-snapshot.eclass b/eclass/golang-vcs-snapshot.eclass new file mode 100644 index 0000000..06aabd2 --- /dev/null +++ b/eclass/golang-vcs-snapshot.eclass @@ -0,0 +1,129 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: golang-vcs-snapshot.eclass +# @MAINTAINER: +# Samuel Bernardo <samuelbernardo.mail@gmail.com> +# @AUTHORS: +# William Hubbs <williamh@gentoo.org> +# @SUPPORTED_EAPIS: 8 +# @PROVIDES: golang-base +# @BLURB: eclass to unpack VCS snapshot tarballs for Go software +# @DEPRECATED: go-module.eclass +# @DESCRIPTION: +# This eclass provides a convenience src_unpack() which unpacks the +# first tarball mentioned in SRC_URI to its appropriate location in +# ${WORKDIR}/${P}, treating ${WORKDIR}/${P} as a go workspace. +# Also, it provides a downstream method of vendoring packages. +# +# The location where the tarball is extracted is defined as +# ${WORKDIR}/${P}/src/${EGO_PN}. The location of vendored packages is +# defined as ${WORKDIR}/${P}/src/${EGO_PN%/*}/vendor to match Go's +# vendoring setup. +# +# The typical use case is VCS snapshots coming from github, bitbucket +# and similar services. +# +# Please note that this eclass currently handles only tarballs +# (.tar.gz), but support for more formats may be added in the future. +# +# @EXAMPLE: +# +# @CODE +# EGO_PN=github.com/user/package +# EGO_VENDOR=( +# "github.com/xenolf/lego 6cac0ea7d8b28c889f709ec7fa92e92b82f490dd" +# "golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8 github.com/golang/crypto" +# ) +# +# inherit golang-vcs-snapshot +# +# SRC_URI="https://github.com/example/${PN}/tarball/v${PV} -> ${P}.tar.gz +# ${EGO_VENDOR_URI}" +# @CODE +# +# The above example will extract the tarball to +# ${WORKDIR}/${P}/src/github.com/user/package +# and add the vendored tarballs to ${WORKDIR}/src/${EGO_PN}/vendor + +case ${EAPI} in + 8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +if [[ -z ${_GOLANG_VCS_SNAPSHOT_ECLASS} ]]; then +_GOLANG_VCS_SNAPSHOT_ECLASS=1 + +inherit golang-base go-env + +# @ECLASS_VARIABLE: EGO_VENDOR +# @DESCRIPTION: +# This variable contains a list of vendored packages. +# The items of this array are strings that contain the +# import path and the git commit hash for a vendored package. +# If the import path does not start with github.com, the third argument +# can be used to point to a github repository. + +declare -arg EGO_VENDOR + +_golang-vcs-snapshot_set_vendor_uri() { + EGO_VENDOR_URI= + local lib + for lib in "${EGO_VENDOR[@]}"; do + lib=(${lib}) + if [[ -n ${lib[2]} ]]; then + EGO_VENDOR_URI+=" https://${lib[2]}/archive/${lib[1]}.tar.gz -> ${lib[2]//\//-}-${lib[1]}.tar.gz" + else + EGO_VENDOR_URI+=" https://${lib[0]}/archive/${lib[1]}.tar.gz -> ${lib[0]//\//-}-${lib[1]}.tar.gz" + fi + done + readonly EGO_VENDOR_URI +} + +_golang-vcs-snapshot_set_vendor_uri +unset -f _golang-vcs-snapshot_set_vendor_uri + +_golang-vcs-snapshot_dovendor() { + local VENDOR_PATH=$1 VENDORPN=$2 TARBALL=$3 + rm -rf "${VENDOR_PATH}/${VENDORPN}" || die + mkdir -p "${VENDOR_PATH}/${VENDORPN}" || die + tar -C "${VENDOR_PATH}/${VENDORPN}" -x --strip-components 1\ + -f "${DISTDIR}"/${TARBALL} || die +} + +# @FUNCTION: golang-vcs-snapshot_src_unpack +# @DESCRIPTION: +# Extract the first archive from ${A} to the appropriate location for GOPATH. +# Set compile env via go-env. +golang-vcs-snapshot_src_unpack() { + local lib vendor_path x + ego_pn_check + set -- ${A} + x="$1" + mkdir -p "${WORKDIR}/${P}/src/${EGO_PN%/...}" || die + tar -C "${WORKDIR}/${P}/src/${EGO_PN%/...}" -x --strip-components 1 \ + -f "${DISTDIR}/${x}" || die + + if [[ -n "${EGO_VENDOR}" ]]; then + vendor_path="${WORKDIR}/${P}/src/${EGO_PN%/...}/vendor" + mkdir -p "${vendor_path}" || die + for lib in "${EGO_VENDOR[@]}"; do + lib=(${lib}) + if [[ -n ${lib[2]} ]]; then + einfo "Vendoring ${lib[0]} ${lib[2]//\//-}-${lib[1]}.tar.gz" + _golang-vcs-snapshot_dovendor "${vendor_path}" ${lib[0]} \ + ${lib[2]//\//-}-${lib[1]}.tar.gz + else + einfo "Vendoring ${lib[0]} ${lib[0]//\//-}-${lib[1]}.tar.gz" + _golang-vcs-snapshot_dovendor "${vendor_path}" ${lib[0]} \ + ${lib[0]//\//-}-${lib[1]}.tar.gz + fi + done + fi + + go-env_set_compile_environment +} + +fi + +EXPORT_FUNCTIONS src_unpack |