From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id qFT5BN1LVWVh7QAA9RJhRA:P1 (envelope-from ) for ; Wed, 15 Nov 2023 23:53:17 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id qFT5BN1LVWVh7QAA9RJhRA (envelope-from ) for ; Wed, 15 Nov 2023 23:53:17 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0F92258F9E for ; Wed, 15 Nov 2023 23:53:16 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=deeplinks-com.20230601.gappssmtp.com header.s=20230601 header.b=1bSVXYNL; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1700088796; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=CDH9gPIzZbcKxks4yOFmBuyPfSFHX7ZYwWY738AVA50=; b=hx8mQzx+La1amfPeIa+9H0KLTSoLTzdOC74PUB+sbcEWwShibj/KXU75QMNrFjZxKRWh8M Bu7I1ishjvNv37a6mPOvPZ59U9EVwOm9v9MuHcpDHgQ9lnWUpqZZXAaImiGTwuhMUBrsFT WwE/xdhmJOXQK3t2QfP+Ge6f3zKD6Hndia2njSyn+UO4oDOxatoLgcfwLzG5M/Fh8SXdpI PaHnKI/fegtrqcZ7G89lFVwl8IARP6p5hh1Um4pz0YBiLmjAa6cgoR2rWEK3EChhHrbvLM RTPW3YYnvIWIA5HgeIn4qweEHG6lbdtT6GGmxCNyDauTPHPRxxPbsGQwjxxkYA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=deeplinks-com.20230601.gappssmtp.com header.s=20230601 header.b=1bSVXYNL; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1700088796; a=rsa-sha256; cv=none; b=fdNrZ8+AbOleO7E7/rXum/+Xmii9G5puxPve6jH2+Ppx6UTq9QJpalt1rQxzhlCmD6ceCe O+kkYwFSyXbQBPLba1SN87+CBaLTqhcYPOxqJXpFzHLpm62uyJvbUTRSMvibnyvNEnnG7e je/iAA8+W5b9uv3SCEG4+0azW3NGCx/uCdX13JVXU1KJu+R3eq1xD2G8dsQrxJugy7vJqD 682VZ1Fdm1pzEhhOe/5t2Dwm8r/UzcWbbDa3jVWLJawA0joyeOQlBLjdeJ2CjIg/D59dyu d+KtxjaGlK+0QThQY9lsXvnp2uLD9nE9rhT50CktMHp6DTunRaHX7wSnUTkaMA== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3Okq-00084k-8J; Wed, 15 Nov 2023 17:53:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3Okp-00082z-55 for guix-patches@gnu.org; Wed, 15 Nov 2023 17:53:03 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r3Oko-0005cW-Th for guix-patches@gnu.org; Wed, 15 Nov 2023 17:53:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r3Oko-0001Pb-5W for guix-patches@gnu.org; Wed, 15 Nov 2023 17:53:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#66801] [PATCH v3 01/14] build-system: Add mix-build-system. References: <68117eb2b3e0e6adcc7449d878e602c7b831ffee.1698524350.git.phfrohring@deeplinks.com> In-Reply-To: <68117eb2b3e0e6adcc7449d878e602c7b831ffee.1698524350.git.phfrohring@deeplinks.com> Resent-From: Pierre-Henry =?UTF-8?Q?Fr=C3=B6hring?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 15 Nov 2023 22:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66801 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66801@debbugs.gnu.org Cc: liliana.prikler@gmail.com, Pierre-Henry =?UTF-8?Q?Fr=C3=B6hring?= Received: via spool by 66801-submit@debbugs.gnu.org id=B66801.17000887275350 (code B ref 66801); Wed, 15 Nov 2023 22:53:02 +0000 Received: (at 66801) by debbugs.gnu.org; 15 Nov 2023 22:52:07 +0000 Received: from localhost ([127.0.0.1]:54114 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3Oju-0001OD-Dm for submit@debbugs.gnu.org; Wed, 15 Nov 2023 17:52:07 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:46323) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3Ojs-0001Nf-7e for 66801@debbugs.gnu.org; Wed, 15 Nov 2023 17:52:05 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4084de32db5so1381585e9.0 for <66801@debbugs.gnu.org>; Wed, 15 Nov 2023 14:52:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deeplinks-com.20230601.gappssmtp.com; s=20230601; t=1700088717; x=1700693517; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CDH9gPIzZbcKxks4yOFmBuyPfSFHX7ZYwWY738AVA50=; b=1bSVXYNLBq4929h+MMRp7RfPqc7nWwTqRgdt0bOJ7IY5JnxlFnfJ90o6mPc4woiSlX Lhs0Os9LSZKxt23ldfGSN7l3AoWc7C2mzbwzigbGuRmELWuphcwnB3njvFEzBX/4G82b rXiyRMC4tLMDtUwN60TeylnXPmdidyh0jpD7Da69MMlnZcO6LIATMRS4T1Ti9FefPB5P VPogpxulvI25JHGRuZrNMyBtbBXXPyCYIgF+A6ZM2RVLCMx+kVyXrFiMtb6xkFaA85cV euzAPuAuvfEjm1eVWKKPs5F+55k19+C730zFw9YHPOlr/jN4Cx4/lORc+zQTNEMh0C5S BkUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700088717; x=1700693517; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CDH9gPIzZbcKxks4yOFmBuyPfSFHX7ZYwWY738AVA50=; b=VoP/TdNeMqbopbpTSiY+vOQ7aeUoQbWilIhl1jsymD38Dvx7SeIi7Gzco3wffz1h0u bIVkNFs4+HdcondXXiTtrYUpRFrhqNkoWmK4pakMRMsiyYOS7g18NCEHOTTROuvlLhQu Xe5bQ9Y0NtbObBy/JK+Ctf6t3RXjW1z88pq+L1AbfHVj8zT7lRMfoOeYKyhEl3iNCRrA lzW9MABfSMLdZOInqaFnwAofFOYg4J2sJ/33l4HDHEKFdj5CJfF57XnlZQqUpi4ME2ku i6b1h+bSA5OMIoWzLjW4TZGS99H0TqunaPwuBfwLLHFdovzASe0/Og6PTDV6pRz44F2f vPeg== X-Gm-Message-State: AOJu0YzPgjvSoe2guPb0S55alo6+3kb7HnUc8GSW0VmF99MnRDLSXJyK +TGzYVKQzT7785HcSQmU0CZKY33rMZr2mLOSyuc= X-Google-Smtp-Source: AGHT+IHlZ358PJx6oC7dvnyB6kPrNGRRMRYWSLt5XnCYu2tpBe35FNQUl+s/dd8Ky4UjgvVaXgVNkA== X-Received: by 2002:a05:600c:548e:b0:403:cc64:2dbf with SMTP id iv14-20020a05600c548e00b00403cc642dbfmr11335145wmb.27.1700088716768; Wed, 15 Nov 2023 14:51:56 -0800 (PST) Received: from doug.home ([2a01:cb19:85a1:c200:ee66:fd17:945:f033]) by smtp.gmail.com with ESMTPSA id m21-20020a05600c3b1500b004094c5d929asm1159910wms.10.2023.11.15.14.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 14:51:56 -0800 (PST) From: Pierre-Henry =?UTF-8?Q?Fr=C3=B6hring?= Date: Wed, 15 Nov 2023 23:51:12 +0100 Message-ID: <67c324d191a9698aed8d9887260cb0ef2bc031df.1700088189.git.phfrohring@deeplinks.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -1.09 X-Spam-Score: -1.09 X-Migadu-Queue-Id: 0F92258F9E X-Migadu-Scanner: mx13.migadu.com X-TUID: EHvtu57ngrcl * guix/build-system/mix.scm, * guix/build/mix-build-system.scm: New modules. Change-Id: I2cbf6c963a530e73420da0eb17ffaf92827451bf --- guix/build-system/mix.scm | 181 ++++++++++++++++++++++++++++ guix/build/mix-build-system.scm | 205 ++++++++++++++++++++++++++++++++ 2 files changed, 386 insertions(+) create mode 100644 guix/build-system/mix.scm create mode 100644 guix/build/mix-build-system.scm diff --git a/guix/build-system/mix.scm b/guix/build-system/mix.scm new file mode 100644 index 00000000..ae80679b --- /dev/null +++ b/guix/build-system/mix.scm @@ -0,0 +1,181 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2023 Pierre-Henry Fröhring +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +;; Commentary: +;; +;; Standard build procedure for Elixir packages using 'mix'. This is +;; implemented as an extension of 'gnu-build-system'. +;; +;; Code: + +(define-module (guix build-system mix) + #:use-module (guix build mix-build-system) + #:use-module (guix build-system gnu) + #:use-module (guix build-system) + #:use-module (guix gexp) + #:use-module (guix monads) + #:use-module (guix packages) + #:use-module (guix search-paths) + #:use-module (guix store) + #:use-module (guix utils) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (mix-build-system hexpm-uri)) + +;; Lazily resolve the bindings to avoid circular dependencies. +(define (default-glibc-utf8-locales) + (let* ((base (resolve-interface '(gnu packages base)))) + (module-ref base 'glibc-utf8-locales))) + +(define (default-elixir-hex) + (let ((elixir (resolve-interface '(gnu packages elixir)))) + (module-ref elixir 'elixir-hex))) + +(define (default-rebar3) + (let ((erlang (resolve-interface '(gnu packages erlang)))) + (module-ref erlang 'rebar3))) + +(define (default-elixir) + "Return the default Elixir package." + (let ((elixir (resolve-interface '(gnu packages elixir)))) + (module-ref elixir 'elixir))) + +(define (hexpm-uri name version) + "Return the URI where to fetch the sources of a Hex package NAME at VERSION. +NAME is the name of the package which should look like: elixir-pkg-name-X.Y.Z +See: https://github.com/hexpm/specifications/blob/main/endpoints.md" + ((compose + (cut string-append "https://repo.hex.pm/tarballs/" <> "-" version ".tar") + (cut string-replace-substring <> "-" "_") + strip-elixir-prefix) + name)) + +;; A number of environment variables specific to the Mix build system are +;; reflected here. They are documented at +;; https://hexdocs.pm/mix/1.15.7/Mix.html#module-environment-variables. Other +;; parameters located in mix.exs are defined at +;; https://hexdocs.pm/mix/1.15.7/Mix.Project.html#module-configuration +(define* (mix-build name + inputs + #:key + source + (tests? #t) + (mix-path #f) ;See MIX_PATH. + (mix-exs "mix.exs") ;See MIX_EXS. + (build-per-environment #t) ;See :build_per_environment. + (phases '%standard-phases) + (outputs '("out")) + (search-paths '()) + (system (%current-system)) + (guile #f) + (imported-modules `((guix build mix-build-system) + ,@%gnu-build-system-modules)) + (modules '((guix build mix-build-system) + (guix build utils)))) + "Build SOURCE using Elixir, and with INPUTS." + + ;; Check the documentation of :build_per_environment here: + ;; https://hexdocs.pm/mix/1.15.7/Mix.Project.html#module-configuration And + ;; "Environments" here: + ;; https://hexdocs.pm/mix/1.15.7/Mix.html#module-environments + (define mix-environments + (if build-per-environment + `("prod" ,@(if tests? '("test") '())) + '("shared"))) + + (define builder + (with-imported-modules imported-modules + #~(begin + + (use-modules #$@(sexp->gexp modules)) + + #$(with-build-variables inputs outputs + #~(mix-build #:name #$name + #:source #+source + #:system #$system + #:tests? #$tests? + #:mix-path #$mix-path + #:mix-exs #$mix-exs + #:mix-environments '#$mix-environments + #:build-per-environment #$build-per-environment + #:phases #$(if (pair? phases) + (sexp->gexp phases) + phases) + #:outputs %outputs + #:search-paths '#$(sexp->gexp + (map + search-path-specification->sexp + search-paths)) + #:inputs + %build-inputs))))) + + (mlet %store-monad ((guile (package->derivation (or guile (default-guile)) + system + #:graft? #f))) + (gexp->derivation name + builder + #:system system + #:graft? #f ;consistent with 'gnu-build' + #:target #f + #:guile-for-build guile))) + +(define* (lower name + #:key + (elixir (default-elixir)) + (elixir-hex (default-elixir-hex)) + (glibc-utf8-locales (default-glibc-utf8-locales)) + (inputs '()) + (native-inputs '()) + (propagated-inputs '()) + (rebar3 (default-rebar3)) + (tests? #t) + outputs + source + system + target + #:allow-other-keys #:rest arguments) + "Return a bag for NAME." + (let ((private-keywords + '(#:inputs #:native-inputs + #:outputs #:system #:target + #:elixir #:elixir-hex #:glibc-utf8-locales + #:rebar3 #:erlang)) + (build-inputs + `(,@(standard-packages) + ("glibc-utf8-locales" ,glibc-utf8-locales) + ("erlang" ,(lookup-package-input elixir "erlang")) + ("rebar3" ,rebar3) + ("elixir" ,elixir) + ("elixir-hex" ,elixir-hex) + ,@inputs + ,@native-inputs))) + (bag (name name) + (system system) + (build-inputs build-inputs) + (host-inputs (if target inputs '())) + (outputs outputs) + (build mix-build) + (arguments (strip-keyword-arguments private-keywords arguments))))) + +(define mix-build-system + (build-system (name 'mix) + (description "The standard Mix build system") + (lower lower))) + +;;; mix.scm ends here diff --git a/guix/build/mix-build-system.scm b/guix/build/mix-build-system.scm new file mode 100644 index 00000000..0a1fcb5c --- /dev/null +++ b/guix/build/mix-build-system.scm @@ -0,0 +1,205 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2023 Pierre-Henry Fröhring +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +;; Commentary: +;; +;; Code: + +(define-module (guix build mix-build-system) + #:use-module ((guix build gnu-build-system) #:prefix gnu:) + #:use-module (guix build utils) + #:use-module (ice-9 ftw) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) + #:use-module (ice-9 string-fun) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (mix-build + strip-elixir-prefix + %standard-phases)) + +(define (elixir-version elixir) + "Return an X.Y string where X and Y are respectively the major and minor version number of ELIXIR. +Example: /gnu/store/…-elixir-1.14.0 → 1.14" + ((compose + (cut string-join <> ".") + (cut take <> 2) + (cut string-split <> #\.) + last) + (string-split elixir #\-))) + +(define (elixir-libdir elixir path) + "Return the path where all libraries for a specified ELIXIR version are installed." + (string-append path "/lib/elixir/" (elixir-version elixir))) + +(define (erlang-libdir path) + "Return the path of the directory where libraries of an Erlang package are +installed in the store." + (string-append path "/lib/erlang/lib")) + +(define (install-dir inputs outputs) + "Return the path of the current output's Elixir library. +Example: /gnu/store/…/lib/elixir/1.14" + (elixir-libdir (assoc-ref inputs "elixir") + (assoc-ref outputs "out"))) + +(define (strip-prefix prefix name) + "Return NAME without the prefix PREFIX." + (if (string-prefix? prefix name) + (string-drop name (string-length prefix)) + name)) + +(define (strip-elixir-prefix name) + "Strip elixir- from NAME." + (strip-prefix "elixir-" name)) + +(define (mix-build-dir mix-env) + "Return the directory where build artifacts are to be installed according to +en environment MIX-ENV in the current directory." + (string-append "_build/" mix-env "/lib")) + +(define* (unpack #:key source mix-path #:allow-other-keys) + "Unpack SOURCE in the working directory, and change directory within the +source. When SOURCE is a directory, copy it in a sub-directory of the current +working directory." + (let ((gnu-unpack (assoc-ref gnu:%standard-phases 'unpack))) + (gnu-unpack #:source source) + (when (file-exists? "contents.tar.gz") + (invoke "tar" "xvf" "contents.tar.gz")))) + +(define (list-directories dir) + "List absolute paths of directories directly under the directory DIR." + (map (cut string-append dir "/" <>) + (scandir dir (lambda (filename) + (and (not (member filename '("." ".."))) + (directory-exists? (string-append dir "/" filename))))))) + +(define* (configure #:key inputs mix-path mix-exs #:allow-other-keys) + "Set environment variables. +See: https://hexdocs.pm/mix/1.15.7/Mix.html#module-environment-variables" + (setenv "LC_ALL" "en_US.UTF-8") + (setenv "MIX_HOME" (getcwd)) + (setenv "MIX_ARCHIVES" "archives") + (setenv "MIX_BUILD_ROOT" "_build") + (setenv "MIX_DEPS_PATH" "deps") + (setenv "MIX_PATH" (or mix-path "")) + (setenv "MIX_REBAR3" (string-append (assoc-ref inputs "rebar3") "/bin/rebar3")) + (setenv "MIX_EXS" mix-exs)) + +(define* (install-hex #:key name inputs outputs #:allow-other-keys) + "Install Hex." + (let ((hex-archive-path (string-append (getenv "MIX_ARCHIVES") "/hex"))) + (mkdir-p hex-archive-path) + (symlink (car (list-directories (elixir-libdir (assoc-ref inputs "elixir") + (assoc-ref inputs "elixir-hex")))) + (string-append hex-archive-path "/hex")))) + +(define* (install-dependencies #:key + name + inputs + outputs + tests? + build-per-environment + (native-inputs '()) + mix-environments + #:allow-other-keys + #:rest rest) + "Install dependencies." + (define (install-lib lib dir) + (let ((lib-name (last (string-split lib #\/)))) + (symlink lib (string-append dir "/" lib-name)))) + + (define (install-input mix-env input) + (let ((dir (mix-build-dir mix-env))) + (mkdir-p dir) + (match input + ((_ . path) + ((compose + (cut for-each (cut install-lib <> dir) <>) + (cut append-map list-directories <>) + (cut filter directory-exists? <>)) + (list (elixir-libdir (assoc-ref inputs "elixir") path) + (erlang-libdir path))))))) + + (define (install-inputs mix-env) + (for-each (cut install-input mix-env <>) + (append inputs native-inputs))) + + (for-each install-inputs mix-environments)) + +(define* (build #:key mix-environments #:allow-other-keys) + "Builds the Mix project." + (for-each (lambda (mix-env) + (setenv "MIX_ENV" mix-env) + (invoke "mix" "compile" "--no-deps-check")) + mix-environments)) + +(define* (check #:key (tests? #t) #:allow-other-keys) + "Test the Mix project." + (if tests? + (invoke "mix" "test" "--no-deps-check") + (format #t "tests? = ~a~%" tests?))) + +(define* (remove-mix-dirs . _) + "Remove all .mix/ directories. +We do not want to copy them to the installation directory." + (for-each delete-file-recursively + (find-files "." (file-name-predicate "\\.mix$") #:directories? #t))) + +(define (library-name pkg-name) + "Return the library name deduced from PKG-NAME. +A package should be named: elixir-lib-name-X.Y.Z from which the library name +lib_name is deduced." + ((compose + (cut string-join <> "_") + (cut drop-right <> 1) + (cut string-split <> #\-)) + (strip-elixir-prefix pkg-name))) + +(define* (install #:key + inputs + outputs + name + build-per-environment + #:allow-other-keys) + "Install build artifacts in the store." + (let* ((lib-name (library-name name)) + (lib-dir (string-append (install-dir inputs outputs) "/" lib-name))) + (mkdir-p lib-dir) + (copy-recursively (string-append (mix-build-dir (if build-per-environment "prod" "shared")) "/" lib-name) + lib-dir + #:follow-symlinks? #t))) + +(define %standard-phases + (modify-phases gnu:%standard-phases + (delete 'bootstrap) + (replace 'configure configure) + (replace 'unpack unpack) + (add-after 'patch-generated-file-shebangs 'install-hex install-hex) + (add-after 'install-hex 'install-dependencies install-dependencies) + (replace 'build build) + (replace 'check check) + (add-before 'install 'remove-mix-dirs remove-mix-dirs) + (replace 'install install))) + +(define* (mix-build #:key inputs (phases %standard-phases) + #:allow-other-keys #:rest args) + "Build the given Mix package, applying all of PHASES in order." + (apply gnu:gnu-build #:inputs inputs #:phases phases args)) + +;;; mix-build-system.scm ends here base-commit: a0d337e79c87d7c38c79d0291974f490cb137a52 -- 2.41.0