From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id DD58A158020 for ; Tue, 8 Nov 2022 17:55:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B148DE0931; Tue, 8 Nov 2022 17:55:40 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 922B7E0931 for ; Tue, 8 Nov 2022 17:55:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5C1CC33BE19 for ; Tue, 8 Nov 2022 17:55:39 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id E19446DF for ; Tue, 8 Nov 2022 17:55:37 +0000 (UTC) From: "Anna Vyalkova" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anna Vyalkova" Message-ID: <1667927490.2b2b50543122b1e068cac963f70de19cc3f50dd4.cybertailor@gentoo> Subject: [gentoo-commits] repo/proj/guru:dev commit in: eclass/ X-VCS-Repository: repo/proj/guru X-VCS-Files: eclass/crystal-utils.eclass X-VCS-Directories: eclass/ X-VCS-Committer: cybertailor X-VCS-Committer-Name: Anna Vyalkova X-VCS-Revision: 2b2b50543122b1e068cac963f70de19cc3f50dd4 X-VCS-Branch: dev Date: Tue, 8 Nov 2022 17:55:37 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2f2c2d71-7276-4ff4-8139-28d33215d3dc X-Archives-Hash: 3142e556fd08f8ed0952dc59e803f1b2 commit: 2b2b50543122b1e068cac963f70de19cc3f50dd4 Author: Anna (cybertailor) Vyalkova sysrq in> AuthorDate: Tue Nov 8 16:12:14 2022 +0000 Commit: Anna Vyalkova sysrq in> CommitDate: Tue Nov 8 17:11:30 2022 +0000 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=2b2b5054 crystal-utils.eclass: new eclass Signed-off-by: Anna (cybertailor) Vyalkova sysrq.in> eclass/crystal-utils.eclass | 124 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/eclass/crystal-utils.eclass b/eclass/crystal-utils.eclass new file mode 100644 index 000000000..cb67682a6 --- /dev/null +++ b/eclass/crystal-utils.eclass @@ -0,0 +1,124 @@ +# Copyright 2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: crystal-utils.eclass +# @MAINTAINER: +# Anna +# @AUTHOR: +# Anna +# @SUPPORTED_EAPIS: 8 +# @BLURB: utility functions for Crystal packages +# @DESCRIPTION: +# A utility eclass providing functions to invoke Crystal. +# +# This eclass does not set any metadata variables nor export any phase, so it +# can be inherited safely. +# +# All helper functions die on failure and support being called via 'nonfatal'. + +case ${EAPI} in + 8) ;; + *) die "${ECLASS}: EAPI ${EAPI} unsupported." +esac + +if [[ ! ${_CRYSTAL_UTILS_ECLASS} ]]; then +_CRYSTAL_UTILS_ECLASS=1 + +inherit edo flag-o-matic + +# @ECLASS_VARIABLE: CRYSTAL_DEPS +# @OUTPUT_VARIABLE +# @DESCRIPTION: +# This is an eclass-generated Crystal dependency string. +CRYSTAL_DEPS=" + || ( + dev-lang/crystal + dev-lang/crystal-bin + ) +" + +# @FUNCTION: _crystal_get_colors_opt +# @INTERNAL +# @RETURN: "--no-color" if colors should be disabled, empty string otherwise +_crystal_get_colors_opt() { + if [[ ${NOCOLOR} == "true" || ${NOCOLOR} == "yes" ]]; then + echo "--no-color" + fi +} + +# @FUNCTION: _crystal_get_debug_opt +# @INTERNAL +# @RETURN: "--debug" if USE=debug, "--no-debug" otherwise +_crystal_get_debug_opt() { + if has debug ${IUSE} && use debug; then + echo "--debug" + else + echo "--no-debug" + fi +} + +# @FUNCTION: crystal_configure +# @DESCRIPTION: +# Set Crystal environment variables to match user settings. +# +# Must be run or ecrystal/eshards will fail. +crystal_configure() { + debug-print-function ${FUNCNAME} "${@}" + + # avoid possible sandbox violation + export CRYSTAL_CACHE_DIR="${T}/crystal" + export SHARDS_CACHE_PATH="${T}/shards" + + local args=( + --link-flags="\"${LDFLAGS}\"" + --release + --progress + $(_crystal_get_debug_opt) + $(_crystal_get_colors_opt) + $(is-flagq -mcpu && echo "--mcpu=$(get-flag mcpu)") + $(is-flagq -mcmodel && echo "--mcmodel=$(get-flag mcmodel)") + # TODO: --mattr + ) + + export CRYSTAL_OPTS="${args[@]}" + + _CRYSTAL_CONFIGURE_HAS_RUN=1 +} + +# @FUNCTION: ecrystal +# @USAGE: [...] +# @DESCRIPTION: +# Call crystal, passing supplied arguments. +ecrystal() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${_CRYSTAL_CONFIGURE_HAS_RUN} ]] || \ + die "${FUNCNAME}: crystal_configure has not been run" + + mkdir -p "${CRYSTAL_CACHE_DIR}" || die "Creating Crystal cache dir failed" + edo crystal "${@}" +} + +# @FUNCTION: eshards +# @USAGE: [...] +# @DESCRIPTION: +# Call shards, passing the standard set of options, then supplied arguments. +eshards() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${_CRYSTAL_CONFIGURE_HAS_RUN} ]] || \ + die "${FUNCNAME}: crystal_configure has not been run" + + mkdir -p "${CRYSTAL_CACHE_DIR}" || die "Creating Crystal cache dir failed" + mkdir -p "${SHARDS_CACHE_PATH}" || die "Creating Shards cache dir failed" + + local args=( + --local + --without-development + $(_crystal_get_colors_opt) + ) + + edo shards "${args[@]}" "${@}" +} + +fi