logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

mix.eclass (2221B)


  1. # Copyright 2019-2023 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: mix.eclass
  4. # @MAINTAINER:
  5. # Haelwenn (lanodan) Monnier <contact@hacktivis.me>
  6. # @AUTHOR:
  7. # Haelwenn (lanodan) Monnier <contact@hacktivis.me>
  8. # @SUPPORTED_EAPIS: 6 7 8
  9. # @BLURB: Build Elixir projects using dev-util/mix.
  10. # @DESCRIPTION:
  11. # An eclass providing functions to build Elixir projects using dev-util/mix.
  12. #
  13. # mix is a tool which tries to resolve dependencies itself
  14. case "${EAPI:-0}" in
  15. 0|1|2|3|4|5)
  16. die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
  17. ;;
  18. 6|7)
  19. ;;
  20. *)
  21. die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
  22. ;;
  23. esac
  24. EXPORT_FUNCTIONS src_prepare src_compile src_install
  25. RDEPEND="dev-lang/elixir"
  26. DEPEND="${RDEPEND}"
  27. # Erlang/Elixir software fails to build when another version with API
  28. # differences is present
  29. BDEPEND="!<${CATEGORY}/${P} !>${CATEGORY}/${P}"
  30. # @ECLASS-VARIABLE: HEX_OFFLINE
  31. HEX_OFFLINE=1
  32. # @ECLASS-VARIABLE: MIX_ENV
  33. MIX_ENV="prod"
  34. # @ECLASS-VARIABLE: MIX_NO_DEPS
  35. MIX_NO_DEPS=1
  36. # @FUNCTION: emix
  37. # @USAGE: <targets>
  38. # @DESCRIPTION:
  39. # Run mix with whatever. Die on failure
  40. emix() {
  41. debug-print-function ${FUNCNAME} "${@}"
  42. (( $# > 0 )) || die "emix: at least one target is required"
  43. MIX_ENV="${MIX_ENV}" mix "$@" || die -n "mix $@ failed"
  44. }
  45. # @ECLASS-VARIABLE: MIX_REWRITE
  46. MIX_REWRITE=""
  47. # @ECLASS-VARIABLE: MIX_BUILD_NAME
  48. MIX_BUILD_NAME="${MIX_ENV}"
  49. # @FUNCTION: mix_src_prepare
  50. mix_src_prepare() {
  51. if [[ "${MIX_REWRITE}" != "" ]]
  52. then
  53. sed -i -E -e 's@\{.*(only|optional): .*},?@@' mix.exs || die "failed removing only & optionnal deps"
  54. rm -f mix.lock
  55. fi
  56. default
  57. }
  58. # @FUNCTION: mix_src_compile
  59. # @DESCRIPTION:
  60. # Compile project with mix.
  61. mix_src_compile() {
  62. debug-print-function ${FUNCNAME} "${@}"
  63. emix compile --no-deps-check
  64. }
  65. # @FUNCTION: mix_src_install
  66. # @DESCRIPTION:
  67. # Install project with mix.
  68. mix_src_install() {
  69. debug-print-function ${FUNCNAME} "${@}"
  70. insinto "/usr/$(get_libdir)/elixir/lib/${P}"
  71. pushd "_build/${MIX_BUILD_NAME}/lib/${PN}" >/dev/null
  72. for reldir in src ebin priv include; do
  73. [ -d "$reldir" ] && doins -r "$(realpath ${reldir})"
  74. done
  75. popd >/dev/null
  76. }