golang-build.eclass 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: golang-build.eclass
  4. # @MAINTAINER:
  5. # William Hubbs <williamh@gentoo.org>
  6. # @BLURB: Eclass for compiling go packages.
  7. # @DESCRIPTION:
  8. # This eclass provides default src_compile, src_test and src_install
  9. # functions for software written in the Go programming language.
  10. inherit golang-base
  11. case "${EAPI:-0}" in
  12. 5|6)
  13. ;;
  14. *)
  15. die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
  16. ;;
  17. esac
  18. EXPORT_FUNCTIONS src_compile src_install src_test
  19. if [[ -z ${_GOLANG_BUILD} ]]; then
  20. _GOLANG_BUILD=1
  21. # @ECLASS-VARIABLE: EGO_BUILD_FLAGS
  22. # @DEFAULT_UNSET
  23. # @DESCRIPTION:
  24. # This allows you to pass build flags to the Go compiler. These flags
  25. # are common to the "go build" and "go install" commands used below.
  26. # Please emerge dev-lang/go and run "go help build" for the
  27. # documentation for these flags.
  28. #
  29. # Example:
  30. # @CODE
  31. # EGO_BUILD_FLAGS="-ldflags \"-X main.version ${PV}\""
  32. # @CODE
  33. # @ECLASS-VARIABLE: EGO_PN
  34. # @REQUIRED
  35. # @DESCRIPTION:
  36. # This is the import path for the go package(s) to build. Please emerge
  37. # dev-lang/go and read "go help importpath" for syntax.
  38. #
  39. # Example:
  40. # @CODE
  41. # EGO_PN=github.com/user/package
  42. # @CODE
  43. golang-build_src_compile() {
  44. debug-print-function ${FUNCNAME} "$@"
  45. ego_pn_check
  46. set -- env GOPATH="${WORKDIR}/${P}:$(get_golibdir_gopath)" \
  47. go build -v -work -x ${EGO_BUILD_FLAGS} "${EGO_PN}"
  48. echo "$@"
  49. "$@" || die
  50. }
  51. golang-build_src_install() {
  52. debug-print-function ${FUNCNAME} "$@"
  53. ego_pn_check
  54. set -- env GOPATH="${WORKDIR}/${P}:$(get_golibdir_gopath)" \
  55. go install -v -work -x ${EGO_BUILD_FLAGS} "${EGO_PN}"
  56. echo "$@"
  57. "$@" || die
  58. golang_install_pkgs
  59. }
  60. golang-build_src_test() {
  61. debug-print-function ${FUNCNAME} "$@"
  62. ego_pn_check
  63. set -- env GOPATH="${WORKDIR}/${P}:$(get_golibdir_gopath)" \
  64. go test -v -work -x "${EGO_PN}"
  65. echo "$@"
  66. "$@" || die
  67. }
  68. fi