bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Improve shell script headers and pre-inst-env handling


From: Mark H Weaver
Subject: Re: [PATCH] Improve shell script headers and pre-inst-env handling
Date: Mon, 11 Feb 2013 21:24:43 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

I wrote:

> I've attached two patches.  The first arranges to make sure that
> 'pre-inst-env' will be rebuilt when 'pre-inst-env.in' is modified.
>
> The second patch is the main subject of this email.  It reworks the
> shell script headers at the top of 'guix-package' and the other scripts
> to avoid modifying environment variables (which could propagate to
> unrelated subprocesses that use libguile), and to avoid prepending
> installed directories to the guile load paths in the case where
> 'pre-inst-env' is being used.
>
> My approach here might be controversial, given that the resulting code
> is a bit longer, so if you don't like it, no worries :)
>
> However, I do find it nice to write more scheme and less shell code, and
> as a bonus the scheme code at the top is properly handled by emacs and
> paredit as if it were in the main body of the file.
>
> What do you think?

And here are the actual patches (oops :)

      Mark


>From 172011c586a96cd15e6401cf813fd6d6ea59b355 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <address@hidden>
Date: Mon, 11 Feb 2013 19:23:20 -0500
Subject: [PATCH 1/2] Add noinst_SCRIPTS = pre-inst-env to Makefile.am.

* Makefile.am: Add noinst_SCRIPTS = pre-inst-env.
---
 Makefile.am |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index b90f7e0..9ec7f55 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,9 @@ bin_SCRIPTS =                                 \
   guix-package                                 \
   guix-gc
 
+noinst_SCRIPTS =                                \
+  pre-inst-env
+
 MODULES =                                      \
   guix/base32.scm                              \
   guix/utils.scm                               \
-- 
1.7.10.4

>From 4df3f71782256c7a90f9a7445f093a545fcaa1b1 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <address@hidden>
Date: Mon, 11 Feb 2013 19:13:32 -0500
Subject: [PATCH 2/2] Improve shell script headers and pre-inst-env handling.

* pre-inst-env.in: Define $GUIX_UNINSTALLED.

* guix-build.in, guix-download.in, guix-gc.in, guix-import.in,
  guix-package.in: Rewrite shell script headers to adjust '%load-path' and
  '%load-compiled-path' within Guile itself instead of setting environment
  variables.  Inhibit this behavior if $GUIX_UNINSTALLED is set to a non-empty
  string.
---
 guix-build.in    |   22 ++++++++++++++++------
 guix-download.in |   22 ++++++++++++++++------
 guix-gc.in       |   24 +++++++++++++++++-------
 guix-import.in   |   22 ++++++++++++++++------
 guix-package.in  |   24 +++++++++++++++++-------
 pre-inst-env.in  |    7 ++++++-
 6 files changed, 88 insertions(+), 33 deletions(-)

diff --git a/guix-build.in b/guix-build.in
index f8c7115..6b79962 100644
--- a/guix-build.in
+++ b/guix-build.in
@@ -1,15 +1,25 @@
 #!/bin/sh
 # aside from this initial boilerplate, this is actually -*- scheme -*- code
 
+script=guix-build
+
 prefix="@prefix@"
 datarootdir="@datarootdir@"
+moduledir="@guilemoduledir@"
 
-GUILE_LOAD_COMPILED_PATH="@guilemoduledir@:$GUILE_LOAD_COMPILED_PATH"
-export GUILE_LOAD_COMPILED_PATH
-
-main='(module-ref (resolve-interface '\''(guix-build)) '\'guix-build')'
-exec address@hidden@} -L "@guilemoduledir@" -l "$0"    \
-         -c "(apply $main (cdr (command-line)))" "$@"
+start="
+(let ()
+  (define (main interp guix-uninstalled-str module-dir script-file . args)
+    (let* ((guix-uninstalled? (not (string-null? guix-uninstalled-str)))
+           (path-to-prepend (if guix-uninstalled? '() (list module-dir))))
+      (set! %load-path          (append path-to-prepend %load-path))
+      (set! %load-compiled-path (append path-to-prepend %load-compiled-path))
+      (load script-file)
+      (let (($script (module-ref (resolve-interface '($script)) '$script)))
+        (apply $script args))))
+  (apply main (command-line)))
+"
+exec "address@hidden@}" -c "$start" "$GUIX_UNINSTALLED" "$moduledir" "$0" "$@"
 !#
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013 Ludovic Courtès <address@hidden>
diff --git a/guix-download.in b/guix-download.in
index ea62b09..f6f226e 100644
--- a/guix-download.in
+++ b/guix-download.in
@@ -1,15 +1,25 @@
 #!/bin/sh
 # aside from this initial boilerplate, this is actually -*- scheme -*- code
 
+script=guix-download
+
 prefix="@prefix@"
 datarootdir="@datarootdir@"
+moduledir="@guilemoduledir@"
 
-GUILE_LOAD_COMPILED_PATH="@guilemoduledir@:$GUILE_LOAD_COMPILED_PATH"
-export GUILE_LOAD_COMPILED_PATH
-
-main='(module-ref (resolve-interface '\''(guix-download)) '\'guix-download')'
-exec address@hidden@} -L "@guilemoduledir@" -l "$0"    \
-         -c "(apply $main (cdr (command-line)))" "$@"
+start="
+(let ()
+  (define (main interp guix-uninstalled-str module-dir script-file . args)
+    (let* ((guix-uninstalled? (not (string-null? guix-uninstalled-str)))
+           (path-to-prepend (if guix-uninstalled? '() (list module-dir))))
+      (set! %load-path          (append path-to-prepend %load-path))
+      (set! %load-compiled-path (append path-to-prepend %load-compiled-path))
+      (load script-file)
+      (let (($script (module-ref (resolve-interface '($script)) '$script)))
+        (apply $script args))))
+  (apply main (command-line)))
+"
+exec "address@hidden@}" -c "$start" "$GUIX_UNINSTALLED" "$moduledir" "$0" "$@"
 !#
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013 Ludovic Courtès <address@hidden>
diff --git a/guix-gc.in b/guix-gc.in
index 1a4a541..aa30a5f 100644
--- a/guix-gc.in
+++ b/guix-gc.in
@@ -1,15 +1,25 @@
 #!/bin/sh
 # aside from this initial boilerplate, this is actually -*- scheme -*- code
 
+script=guix-gc
+
 prefix="@prefix@"
 datarootdir="@datarootdir@"
-
-GUILE_LOAD_COMPILED_PATH="@guilemoduledir@:$GUILE_LOAD_COMPILED_PATH"
-export GUILE_LOAD_COMPILED_PATH
-
-main='(module-ref (resolve-interface '\''(guix-gc)) '\'guix-gc')'
-exec address@hidden@} -L "@guilemoduledir@" -l "$0"    \
-         -c "(apply $main (cdr (command-line)))" "$@"
+moduledir="@guilemoduledir@"
+
+start="
+(let ()
+  (define (main interp guix-uninstalled-str module-dir script-file . args)
+    (let* ((guix-uninstalled? (not (string-null? guix-uninstalled-str)))
+           (path-to-prepend (if guix-uninstalled? '() (list module-dir))))
+      (set! %load-path          (append path-to-prepend %load-path))
+      (set! %load-compiled-path (append path-to-prepend %load-compiled-path))
+      (load script-file)
+      (let (($script (module-ref (resolve-interface '($script)) '$script)))
+        (apply $script args))))
+  (apply main (command-line)))
+"
+exec "address@hidden@}" -c "$start" "$GUIX_UNINSTALLED" "$moduledir" "$0" "$@"
 !#
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013 Ludovic Courtès <address@hidden>
diff --git a/guix-import.in b/guix-import.in
index 97619a9..525fa30 100644
--- a/guix-import.in
+++ b/guix-import.in
@@ -1,15 +1,25 @@
 #!/bin/sh
 # aside from this initial boilerplate, this is actually -*- scheme -*- code
 
+script=guix-import
+
 prefix="@prefix@"
 datarootdir="@datarootdir@"
+moduledir="@guilemoduledir@"
 
-GUILE_LOAD_COMPILED_PATH="@guilemoduledir@:$GUILE_LOAD_COMPILED_PATH"
-export GUILE_LOAD_COMPILED_PATH
-
-main='(module-ref (resolve-interface '\''(guix-import)) '\'guix-import')'
-exec address@hidden@} -L "@guilemoduledir@" -l "$0"    \
-         -c "(apply $main (cdr (command-line)))" "$@"
+start="
+(let ()
+  (define (main interp guix-uninstalled-str module-dir script-file . args)
+    (let* ((guix-uninstalled? (not (string-null? guix-uninstalled-str)))
+           (path-to-prepend (if guix-uninstalled? '() (list module-dir))))
+      (set! %load-path          (append path-to-prepend %load-path))
+      (set! %load-compiled-path (append path-to-prepend %load-compiled-path))
+      (load script-file)
+      (let (($script (module-ref (resolve-interface '($script)) '$script)))
+        (apply $script args))))
+  (apply main (command-line)))
+"
+exec "address@hidden@}" -c "$start" "$GUIX_UNINSTALLED" "$moduledir" "$0" "$@"
 !#
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013 Ludovic Courtès <address@hidden>
diff --git a/guix-package.in b/guix-package.in
index ae3d2cd..2082a93 100644
--- a/guix-package.in
+++ b/guix-package.in
@@ -1,15 +1,25 @@
 #!/bin/sh
 # aside from this initial boilerplate, this is actually -*- scheme -*- code
 
+script=guix-package
+
 prefix="@prefix@"
 datarootdir="@datarootdir@"
-
-GUILE_LOAD_COMPILED_PATH="@guilemoduledir@:$GUILE_LOAD_COMPILED_PATH"
-export GUILE_LOAD_COMPILED_PATH
-
-main='(module-ref (resolve-interface '\''(guix-package)) '\'guix-package')'
-exec address@hidden@} -L "@guilemoduledir@" -l "$0"    \
-         -c "(apply $main (cdr (command-line)))" "$@"
+moduledir="@guilemoduledir@"
+
+start="
+(let ()
+  (define (main interp guix-uninstalled-str module-dir script-file . args)
+    (let* ((guix-uninstalled? (not (string-null? guix-uninstalled-str)))
+           (path-to-prepend (if guix-uninstalled? '() (list module-dir))))
+      (set! %load-path          (append path-to-prepend %load-path))
+      (set! %load-compiled-path (append path-to-prepend %load-compiled-path))
+      (load script-file)
+      (let (($script (module-ref (resolve-interface '($script)) '$script)))
+        (apply $script args))))
+  (apply main (command-line)))
+"
+exec "address@hidden@}" -c "$start" "$GUIX_UNINSTALLED" "$moduledir" "$0" "$@"
 !#
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013 Ludovic Courtès <address@hidden>
diff --git a/pre-inst-env.in b/pre-inst-env.in
index 1dc63cd..5349c4c 100644
--- a/pre-inst-env.in
+++ b/pre-inst-env.in
@@ -43,7 +43,12 @@ export NIX_ROOT_FINDER NIX_SETUID_HELPER
 # auto-compilation.
 
 NIX_HASH="@NIX_HASH@"
-
 export NIX_HASH
 
+# Define $GUIX_UNINSTALLED to prevent `guix-package' and other scripts from
+# prepending @guilemoduledir@ to the Guile load paths.
+
+GUIX_UNINSTALLED=1
+export GUIX_UNINSTALLED
+
 exec "$@"
-- 
1.7.10.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]