From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebtLY-0002uQ-3g for guix-patches@gnu.org; Wed, 17 Jan 2018 14:26:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebtLW-0005VF-B1 for guix-patches@gnu.org; Wed, 17 Jan 2018 14:26:04 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:52618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebtLW-0005Un-6V for guix-patches@gnu.org; Wed, 17 Jan 2018 14:26:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ebtLV-0002Zk-Tc for guix-patches@gnu.org; Wed, 17 Jan 2018 14:26:01 -0500 Subject: [bug#30147] Simplify =?UTF-8?Q?=E2=80=9Cscripts/guix=E2=80=9D?= Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebtKq-0002aZ-Sr for guix-patches@gnu.org; Wed, 17 Jan 2018 14:25:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebtKp-0004vA-42 for guix-patches@gnu.org; Wed, 17 Jan 2018 14:25:20 -0500 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:41125) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebtKo-0004uy-Vm for guix-patches@gnu.org; Wed, 17 Jan 2018 14:25:19 -0500 Received: from [2a01:e35:2ec2:e580:7d5f:f616:fc6f:3970] (port=57768 helo=godel) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ebtKn-0003Vc-Sv for guix-patches@gnu.org; Wed, 17 Jan 2018 14:25:18 -0500 From: Mathieu Lirzin Date: Wed, 17 Jan 2018 20:25:14 +0100 Message-ID: <87inc0i8yt.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 30147@debbugs.gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Here are some improvements for =E2=80=9Cscripts/guix=E2=80=9D. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-build-Expand-scripts-guix-at-Make-time.patch Content-Transfer-Encoding: quoted-printable >From 342444897673d5f9d9a475986e76ca2e912f6674 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Wed, 17 Jan 2018 17:14:24 +0100 Subject: [PATCH 1/2] =3D?UTF-8?q?build:=3D20Expand=3D20=3DE2=3D80=3D98scrip= ts/guix?=3D =3D?UTF-8?q?=3DE2=3D80=3D99=3D20at=3D20Make=3D20time.?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit This moves the complexity of Autotools variable expansion outside of the application code. * scripts/guix.in (config-lookup): Delete. (maybe-augment-load-paths!, run-guix-main): Use fully expanded variables instead of calling =E2=80=98config-lookup=E2=80=99. * configure.ac: Don't use AC_CONFIG_FILES for =E2=80=98scripts/guix=E2=80= =99. * Makefile.am (scripts/guix): New rule. (do_subst): New variable. (CLEANFILES, EXTRA_DIST): Adapt. --- Makefile.am | 20 +++++++++++++++++--- configure.ac | 1 - scripts/guix.in | 31 ++++++------------------------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Makefile.am b/Makefile.am index aebd3b1eb..5e36dbf44 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ # Copyright =C2=A9 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Court=C3=A8s= # Copyright =C2=A9 2013 Andreas Enge # Copyright =C2=A9 2015, 2017 Alex Kost -# Copyright =C2=A9 2016 Mathieu Lirzin +# Copyright =C2=A9 2016, 2018 Mathieu Lirzin # Copyright =C2=A9 2016, 2017 Mark H Weaver # Copyright =C2=A9 2017 Mathieu Othacehe # Copyright =C2=A9 2017 Leo Famulari @@ -26,8 +26,20 @@ # You should have received a copy of the GNU General Public License # along with GNU Guix. If not, see . =20 -bin_SCRIPTS =3D \ - scripts/guix +bin_SCRIPTS =3D scripts/guix + +# Handle substitution of fully-expanded Autoconf variables. +do_subst =3D sed \ + -e 's,[@]GUILE[@],$(GUILE),g' \ + -e 's,[@]guilemoduledir[@],$(guilemoduledir),g' \ + -e 's,[@]guileobjectdir[@],$(guileobjectdir),g' \ + -e 's,[@]localedir[@],$(localedir),g' + +scripts/guix: scripts/guix.in Makefile + $(AM_V_GEN)rm -f $@ $@-t \ + && $(MKDIR_P) $(@D) \ + && $(do_subst) <$(srcdir)/$@.in >$@-t \ + && chmod a+x,a-w $@-t && mv -f $@-t $@ =20 nodist_noinst_SCRIPTS =3D \ pre-inst-env \ @@ -437,6 +449,7 @@ EXTRA_DIST =3D \ TODO \ CODE-OF-CONDUCT \ .dir-locals.el \ + bin/guix.in \ build-aux/build-self.scm \ build-aux/compile-all.scm \ build-aux/hydra/evaluate.scm \ @@ -473,6 +486,7 @@ endif !BUILD_DAEMON_OFFLOAD =20 =20 CLEANFILES =3D \ + $(bin_SCRIPTS) \ $(GOBJECTS) \ $(SCM_TESTS:tests/%.scm=3D%.log) =20 diff --git a/configure.ac b/configure.ac index 1e3912248..c50dcaf2e 100644 --- a/configure.ac +++ b/configure.ac @@ -272,7 +272,6 @@ AC_CONFIG_FILES([Makefile po/packages/Makefile.in guix/config.scm]) =20 -AC_CONFIG_FILES([scripts/guix], [chmod +x scripts/guix]) AC_CONFIG_FILES([test-env:build-aux/test-env.in], [chmod +x test-env]) AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in], [chmod +x pre-inst-env]) diff --git a/scripts/guix.in b/scripts/guix.in index e20c27424..af50a782b 100644 --- a/scripts/guix.in +++ b/scripts/guix.in @@ -3,6 +3,7 @@ !# ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2013 Mark H Weaver +;;; Copyright =C2=A9 2018 Mathieu Lirzin ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,35 +23,15 @@ ;; IMPORTANT: We must avoid loading any modules from Guix here, ;; because we need to adjust the guile load paths first. ;; It's okay to import modules from core Guile though. -(use-modules (ice-9 regex) - (srfi srfi-26)) +(use-modules (srfi srfi-26)) =20 (let () (define-syntax-rule (push! elt v) (set! v (cons elt v))) =20 - (define config-lookup - (let ((config '(("prefix" . "@prefix@") - ("exec_prefix" . "@exec_prefix@") - ("datarootdir" . "@datarootdir@") - ("guilemoduledir" . "@guilemoduledir@") - ("guileobjectdir" . "@guileobjectdir@") - ("localedir" . "@localedir@"))) - (var-ref-regexp (make-regexp "\\$\\{([a-z_]+)\\}"))) - (define (expand-var-ref match) - (lookup (match:substring match 1))) - (define (expand str) - (regexp-substitute/global #f var-ref-regexp str - 'pre expand-var-ref 'post)) - (define (lookup name) - (expand (assoc-ref config name))) - lookup)) - (define (maybe-augment-load-paths!) (unless (getenv "GUIX_UNINSTALLED") - (let ((module-dir (config-lookup "guilemoduledir")) - (object-dir (config-lookup "guileobjectdir"))) - (push! module-dir %load-path) - (push! object-dir %load-compiled-path)) + (push! "@guilemoduledir@" %load-path) + (push! "@guileobjectdir@" %load-compiled-path) (let ((updates-dir (and=3D> (or (getenv "XDG_CONFIG_HOME") (and=3D> (getenv "HOME") (cut string-append <> "/.config= "))) @@ -64,8 +45,8 @@ (define (run-guix-main) (let ((guix-main (module-ref (resolve-interface '(guix ui)) 'guix-main))) - (bindtextdomain "guix" (config-lookup "localedir")) - (bindtextdomain "guix-packages" (config-lookup "localedir")) + (bindtextdomain "guix" "@localedir@") + (bindtextdomain "guix-packages" "@localedir@") (apply guix-main (command-line)))) =20 (maybe-augment-load-paths!) --=20 2.15.1 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0002-guix-Refactor-script.patch Content-Transfer-Encoding: quoted-printable >From b6f8331455da1ffc4896b06cd2ee98e09b05be43 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Wed, 17 Jan 2018 19:55:49 +0100 Subject: [PATCH 2/2] guix: Refactor script. MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * scripts/guix.in: Use =E2=80=98and-let*=E2=80=99 and remove empty surround= ing =E2=80=98let=E2=80=99. (run-guix-main, maybe-augment-load-paths!): Inline them. --- scripts/guix.in | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/scripts/guix.in b/scripts/guix.in index af50a782b..f971398e8 100644 --- a/scripts/guix.in +++ b/scripts/guix.in @@ -23,36 +23,33 @@ ;; IMPORTANT: We must avoid loading any modules from Guix here, ;; because we need to adjust the guile load paths first. ;; It's okay to import modules from core Guile though. -(use-modules (srfi srfi-26)) =20 -(let () - (define-syntax-rule (push! elt v) (set! v (cons elt v))) +(use-modules (srfi srfi-2) + (srfi srfi-26)) =20 - (define (maybe-augment-load-paths!) - (unless (getenv "GUIX_UNINSTALLED") - (push! "@guilemoduledir@" %load-path) - (push! "@guileobjectdir@" %load-compiled-path) - (let ((updates-dir (and=3D> (or (getenv "XDG_CONFIG_HOME") - (and=3D> (getenv "HOME") - (cut string-append <> "/.config= "))) - (cut string-append <> "/guix/latest")))) - (when (and updates-dir (file-exists? updates-dir)) - ;; XXX: Currently 'guix pull' puts both .scm and .go files in - ;; UPDATES-DIR. - (push! updates-dir %load-path) - (push! updates-dir %load-compiled-path))))) +(define-syntax-rule (push! elt v) (set! v (cons elt v))) =20 - (define (run-guix-main) - (let ((guix-main (module-ref (resolve-interface '(guix ui)) - 'guix-main))) - (bindtextdomain "guix" "@localedir@") - (bindtextdomain "guix-packages" "@localedir@") - (apply guix-main (command-line)))) +(unless (getenv "GUIX_UNINSTALLED") + ;; Add installed modules to load-path. + (push! "@guilemoduledir@" %load-path) + (push! "@guileobjectdir@" %load-compiled-path) =20 - (maybe-augment-load-paths!) + ;; Add modules fetched by 'guix pull' to load-path. + (and-let* ((conf-dir (or (getenv "XDG_CONFIG_HOME") + (and=3D> (getenv "HOME") + (cut string-append <> "/.config")))) + (updates-dir (string-append conf-dir "/guix/latest")) + ((file-exists? updates-dir))) + ;; XXX: Currently 'guix pull' puts both .scm and .go files in UPDATES-= DIR. + (push! updates-dir %load-path) + (push! updates-dir %load-compiled-path))) =20 +;; Run Guix. +(let ((guix-main (module-ref (resolve-interface '(guix ui)) 'guix-main))) + (bindtextdomain "guix" "@localedir@") + (bindtextdomain "guix-packages" "@localedir@") ;; XXX: It would be more convenient to change it to: ;; (exit (run-guix-main)) ;; but since the 'guix' command is not updated by 'guix pull', we cannot ;; really do it now. - (run-guix-main)) + (apply guix-main (command-line))) --=20 2.15.1 --=-=-= Content-Type: text/plain Thanks. -- Mathieu Lirzin GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37 --=-=-=--