1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (guix build-system minify)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix packages)
24 #:use-module (guix gexp)
25 #:use-module (guix monads)
26 #:use-module (guix search-paths)
27 #:use-module (guix build-system)
28 #:use-module (guix build-system gnu)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-26)
31 #:export (%minify-build-system-modules
37 ;; Standard minification procedure for JavaScript files.
41 (define %minify-build-system-modules
42 ;; Build-side modules imported by default.
43 `((guix build minify-build-system)
44 ,@%gnu-build-system-modules))
46 (define (default-uglify-js)
47 "Return the default package to minify JavaScript source files."
48 ;; Lazily resolve the binding to avoid a circular dependency.
49 (let ((mod (resolve-interface '(gnu packages lisp-xyz))))
50 (module-ref mod 'uglify-js)))
53 #:key source inputs native-inputs outputs system
54 (uglify-js (default-uglify-js))
57 "Return a bag for NAME."
58 (define private-keywords
59 '(#:target #:inputs #:native-inputs))
64 (host-inputs `(,@(if source
68 ,@(standard-packages)))
69 (build-inputs `(("uglify-js" ,uglify-js)
73 (arguments (strip-keyword-arguments private-keywords arguments))))
75 (define* (minify-build name inputs
79 (phases '(@ (guix build minify-build-system)
82 (system (%current-system))
85 (imported-modules %minify-build-system-modules)
86 (modules '((guix build minify-build-system)
88 "Build SOURCE with INPUTS."
90 (with-imported-modules imported-modules
92 (use-modules #$@modules)
93 (minify-build #:name #$name
95 #:javascript-files #$javascript-files
97 #:outputs #$(outputs->gexp outputs)
98 #:search-paths '#$(map search-path-specification->sexp
100 #:inputs #$(input-tuples->gexp inputs)))))
102 (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
103 system #:graft? #f)))
104 (gexp->derivation name builder
106 #:guile-for-build guile)))
108 (define minify-build-system
111 (description "The trivial JavaScript minification build system")
114 ;;; minify.scm ends here