Package: guix-patches;
Reported by: Ricardo Wurmus <rekado <at> elephly.net>
Date: Wed, 2 Aug 2017 20:52:02 UTC
Severity: normal
Tags: patch
Done: Ricardo Wurmus <rekado <at> elephly.net>
Bug is archived. No further changes may be made.
View this message in rfc822 format
From: help-debbugs <at> gnu.org (GNU bug Tracking System) To: Ricardo Wurmus <rekado <at> elephly.net> Subject: bug#27924: closed (Re: gnu: Add r-shiny.) Date: Fri, 04 Aug 2017 09:28:01 +0000
[Message part 1 (text/plain, inline)]
Your bug report #27924: [PATCH] build: Add minify build system. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 27924 <at> debbugs.gnu.org. -- 27924: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=27924 GNU Bug Tracking System Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Ricardo Wurmus <rekado <at> elephly.net> To: 27935-done <at> debbugs.gnu.org, 27924-done <at> debbugs.gnu.org Subject: Re: gnu: Add r-shiny. Date: Fri, 04 Aug 2017 11:27:39 +0200Ricardo Wurmus <rekado <at> elephly.net> writes: > this patch series adds r-shiny and packages for the minified JavaScript > files that it bundles. > > For each of the minified JavaScript files that didn’t have corresponding > sources I tracked down the sources and created our own minified files > with the minify-build-system (see #27924). I have pushed a slightly modified version of the minify-build-system and of this r-shiny patch series. The reason is that my updates to CRAN packages accidentally introduced a dependency on r-crosstalk (in r-plotly), which depends on r-shiny. Rather than reverting the upgrade and potentially breaking dependent packages, I decided to go ahead and get r-shiny and r-crosstalk in. My apologies for the confusion and the breakage! -- Ricardo GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC https://elephly.net
[Message part 3 (message/rfc822, inline)]
From: Ricardo Wurmus <rekado <at> elephly.net> To: guix-patches <at> gnu.org Cc: Ricardo Wurmus <rekado <at> elephly.net> Subject: [PATCH] build: Add minify build system. Date: Wed, 2 Aug 2017 22:50:39 +0200* guix/build-system/minify.scm: New file. * guix/build/minify-build-system: New file. * Makefile.am (MODULES): Add new files. * doc/guix.texi (Build Systems): Document minify-build-system. --- Makefile.am | 2 + doc/guix.texi | 15 +++++ guix/build-system/minify.scm | 127 +++++++++++++++++++++++++++++++++++++ guix/build/minify-build-system.scm | 72 +++++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 guix/build-system/minify.scm create mode 100644 guix/build/minify-build-system.scm diff --git a/Makefile.am b/Makefile.am index 0a7e375c2..91a9113d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,6 +79,7 @@ MODULES = \ guix/build-system/dub.scm \ guix/build-system/emacs.scm \ guix/build-system/font.scm \ + guix/build-system/minify.scm \ guix/build-system/asdf.scm \ guix/build-system/glib-or-gtk.scm \ guix/build-system/gnu.scm \ @@ -105,6 +106,7 @@ MODULES = \ guix/build/cmake-build-system.scm \ guix/build/dub-build-system.scm \ guix/build/emacs-build-system.scm \ + guix/build/minify-build-system.scm \ guix/build/font-build-system.scm \ guix/build/asdf-build-system.scm \ guix/build/git.scm \ diff --git a/doc/guix.texi b/doc/guix.texi index 0ea677387..4d8b7bac5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -3575,6 +3575,21 @@ specified with the @code{#:glib} parameter. Both phases are executed after the @code{install} phase. @end defvr +@defvr {Scheme Variable} minify-build-system +This variable is exported by @code{(guix build-system minify)}. It +implements a minification procedure for simple JavaScript packages. + +It adds @code{uglify-js} to the set of inputs and uses it to compress +all JavaScript files in the @file{src} directory. A different minifier +package can be specified with the @code{#:uglify-js} parameter, but it +is expected that the package writes the minified code to the standard +output. + +When the input JavaScript files are not all located in the @file{src} +directory, the parameter @code{#:javascript-files} can be used to +specify a list of file names to feed to the minifier. +@end defvr + @defvr {Scheme Variable} ocaml-build-system This variable is exported by @code{(guix build-system ocaml)}. It implements a build procedure for @uref{https://ocaml.org, OCaml} packages, which consists diff --git a/guix/build-system/minify.scm b/guix/build-system/minify.scm new file mode 100644 index 000000000..9af93333c --- /dev/null +++ b/guix/build-system/minify.scm @@ -0,0 +1,127 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2017 Ricardo Wurmus <rekado <at> elephly.net> +;;; +;;; 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 <http://www.gnu.org/licenses/>. + +(define-module (guix build-system minify) + #:use-module (guix store) + #:use-module (guix utils) + #:use-module (guix packages) + #:use-module (guix derivations) + #:use-module (guix search-paths) + #:use-module (guix build-system) + #:use-module (guix build-system gnu) + #:use-module (ice-9 match) + #:use-module (srfi srfi-26) + #:export (%minify-build-system-modules + minify-build + minify-build-system)) + +;; Commentary: +;; +;; Standard minification procedure for JavaScript files. +;; +;; Code: + +(define %minify-build-system-modules + ;; Build-side modules imported by default. + `((guix build minify-build-system) + (ice-9 popen) + ,@%gnu-build-system-modules)) + +(define (default-uglify-js) + "Return the default package to minify JavaScript source files." + ;; Lazily resolve the binding to avoid a circular dependency. + (let ((lisp-mod (resolve-interface '(gnu packages lisp)))) + (module-ref lisp-mod 'uglify-js))) + +(define* (lower name + #:key source inputs native-inputs outputs system + (uglify-js (default-uglify-js)) + #:allow-other-keys + #:rest arguments) + "Return a bag for NAME." + (define private-keywords + '(#:source #:target #:jdk #:ant #:zip #:inputs #:native-inputs)) + + (bag + (name name) + (system system) + (host-inputs `(,@(if source + `(("source" ,source)) + '()) + ,@inputs + ,@(standard-packages))) + (build-inputs `(("uglify-js" ,uglify-js) + ,@native-inputs)) + (outputs outputs) + (build minify-build) + (arguments (strip-keyword-arguments private-keywords arguments)))) + +(define* (minify-build store name inputs + #:key + (javascript-files #f) + (phases '(@ (guix build minify-build-system) + %standard-phases)) + (outputs '("out")) + (system (%current-system)) + search-paths + (guile #f) + (imported-modules %minify-build-system-modules) + (modules '((guix build minify-build-system) + (guix build utils)))) + "Build SOURCE with INPUTS." + (define builder + `(begin + (use-modules ,@modules) + (minify-build #:name ,name + #:source ,(match (assoc-ref inputs "source") + (((? derivation? source)) + (derivation->output-path source)) + ((source) + source) + (source + source)) + #:javascript-files ,javascript-files + #:phases ,phases + #:outputs %outputs + #:search-paths ',(map search-path-specification->sexp + search-paths) + #:inputs %build-inputs))) + + (define guile-for-build + (match guile + ((? package?) + (package-derivation store guile system #:graft? #f)) + (#f ; the default + (let* ((distro (resolve-interface '(gnu packages commencement))) + (guile (module-ref distro 'guile-final))) + (package-derivation store guile system #:graft? #f))))) + + (build-expression->derivation store name builder + #:inputs inputs + #:system system + #:modules imported-modules + #:outputs outputs + #:guile-for-build guile-for-build)) + +(define minify-build-system + (build-system + (name 'minify) + (description "The trivial JavaScript minification build system") + (lower lower))) + +;;; minify.scm ends here diff --git a/guix/build/minify-build-system.scm b/guix/build/minify-build-system.scm new file mode 100644 index 000000000..3e20627bd --- /dev/null +++ b/guix/build/minify-build-system.scm @@ -0,0 +1,72 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2016 Ricardo Wurmus <rekado <at> elephly.net> +;;; +;;; 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 <http://www.gnu.org/licenses/>. + +(define-module (guix build minify-build-system) + #:use-module ((guix build gnu-build-system) #:prefix gnu:) + #:use-module ((guix build minify-build-system) #:prefix minify:) + #:use-module (guix build utils) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (ice-9 popen) + #:export (%standard-phases + minify-build)) + +;; Commentary: +;; +;; Builder-side code of the standard minification procedure for JavaScript +;; files. +;; +;; Code: + +(define* (minify file #:optional (install-directory "")) + (format #t "minifying ~a\n" file) + (let* ((base (basename file ".js")) + (installed (string-append install-directory base ".min.js")) + (minified (open-pipe* OPEN_READ "uglify-js" file))) + (call-with-output-file installed + (cut dump-port minified <>)) + #t)) + +(define* (build #:key javascript-files + #:allow-other-keys) + (let ((files (or javascript-files + (find-files "src" "\\.js$")))) + (mkdir-p "guix/build") + (every (cut minify <> "guix/build/") files))) + +(define* (install #:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (js (string-append out "/share/javascript/"))) + (mkdir-p js) + (for-each (cut install-file <> js) + (find-files "guix/build" "\\.min\\.js$"))) + #t) + +(define %standard-phases + (modify-phases gnu:%standard-phases + (delete 'configure) + (replace 'build build) + (delete 'check) + (replace 'install install))) + +(define* (minify-build #:key inputs (phases %standard-phases) + #:allow-other-keys #:rest args) + "Build the given JavaScript package, applying all of PHASES in order." + (apply gnu:gnu-build #:inputs inputs #:phases phases args)) + +;;; minify-build-system.scm ends here -- 2.13.3
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.