~ chicken-core (chicken-5) 87c1bab9c5ecc28af323b76f2bc5ef10fb17ab76


commit 87c1bab9c5ecc28af323b76f2bc5ef10fb17ab76
Author:     Jim Ursetto <zbigniewsz@gmail.com>
AuthorDate: Fri Apr 15 22:44:48 2016 -0500
Commit:     Peter Bex <peter@more-magic.net>
CommitDate: Sat Apr 16 17:02:35 2016 +0200

    On OS X, ensure DYLD_LIBRARY_PATH is passed to children (#1277)
    
    On OS X 10.11, according to Apple's System Integrity Protection Guide, "Any
    dynamic linker (dyld) environment variables, such as DYLD_LIBRARY_PATH, are
    purged when launching protected processes," including /bin/sh.  This causes a
    failure running `make check` (bug #1277) because launching children via
    system(3) wipes out the library path override used to test uninstalled
    binaries.  Turning off SIP will resolve the issue but disables other useful
    protections.
    
    This patch simulates the pre-SIP behavior by prepending /usr/bin/env
    DYLD_LIBRARY_PATH=...  to all shell calls made by csc, chicken-install and
    setup-api, using the value of the variable in the caller's environment.
    
    To get all tests in `make check` to work, it is only necessary to augment calls
    from csc to chicken, from chicken-install to csi, and from setup-api to csc.
    Converting these from system(3) to exec(2) works as well, but was deemed too
    invasive.  This patch affects more calls than necessary in the interest of
    simplicity, but calls to protected binaries will have the DYLD_LIBRARY_PATH
    stripped out by SIP again anyway.
    
    Signed-off-by: Peter Bex <peter@more-magic.net>

diff --git a/chicken-install.scm b/chicken-install.scm
index 610097da..9f22296d 100644
--- a/chicken-install.scm
+++ b/chicken-install.scm
@@ -637,7 +637,6 @@
 				(let ((cmd (make-install-command
 					    (car e+d+v) (caddr e+d+v) (> i 1)))
 				      (name (car e+d+v)))
-				  (print "  " cmd)
 				  (keep-going 
 				   (name "installing")
 				   ($system cmd))
@@ -749,12 +748,18 @@
      (gather-egg-information dir)))      
 
   (define ($system str)
-    (let ((r (system
-              (if *windows-shell*
-                  (string-append "\"" str "\"")
-                  str))))
-      (unless (zero? r)
-        (error "shell command terminated with nonzero exit code" r str))))
+    (let ((str (cond (*windows-shell*
+		     (string-append "\"" str "\""))
+		    ((and (eq? (software-version) 'macosx)
+			  (get-environment-variable "DYLD_LIBRARY_PATH"))
+		     => (lambda (path)
+			  (string-append "/usr/bin/env DYLD_LIBRARY_PATH="
+					 (qs path) " " str)))
+		    (else str))))
+      (print "  " str)
+      (let ((r (system str)))
+	(unless (zero? r)
+	  (error "shell command terminated with nonzero exit code" r str)))))
 
   (define (installed-extensions)
     (delete-duplicates
@@ -789,7 +794,6 @@
 
   (define (command fstr . args)
     (let ((cmd (apply sprintf fstr args)))
-      (print "  " cmd)
       ($system cmd)))
 
   (define (usage code)
diff --git a/csc.scm b/csc.scm
index 07cb67b7..60a3235c 100644
--- a/csc.scm
+++ b/csc.scm
@@ -1051,10 +1051,14 @@ EOF
 (define last-exit-code #f)
 
 (define ($system str)
-  (when verbose (print str))
-  (let ((str (if windows-shell
-		 (string-append "\"" str "\"")
-		 str)))
+  (let ((str (cond (windows-shell
+		    (string-append "\"" str "\""))
+		   ((and osx (get-environment-variable "DYLD_LIBRARY_PATH"))
+		    => (lambda (path)
+			 (string-append "/usr/bin/env DYLD_LIBRARY_PATH="
+					(qs path) " " str)))
+		   (else str))))
+    (when verbose (print str))
     (let ((raw-exit-code (if dry-run 0 (system str))))
       (unless (zero? raw-exit-code)
 	(printf "\nError: shell command terminated with non-zero exit status ~S: ~A~%" raw-exit-code str))
diff --git a/setup-api.scm b/setup-api.scm
index f4168a6a..c9697352 100644
--- a/setup-api.scm
+++ b/setup-api.scm
@@ -636,13 +636,18 @@
   (remove-file* (make-pathname repo egg setup-file-extension)))
 
 (define ($system str)
-  (let ((r (system
-	    (if *windows-shell*
-		(string-append "\"" str "\"") ; (sic) thanks to Matthew Flatt
-		str))))
-    (unless (zero? r)
-      (error
-       (sprintf "shell command failed with nonzero exit status ~a:~%~%  ~a" r str)))))
+  (let ((str (cond (*windows-shell*
+		     (string-append "\"" str "\""))
+		    ((and (eq? (software-version) 'macosx)
+			  (get-environment-variable "DYLD_LIBRARY_PATH"))
+		     => (lambda (path)
+			  (string-append "/usr/bin/env DYLD_LIBRARY_PATH="
+					 (qs path) " " str)))
+		    (else str))))
+    (let ((r (system str)))
+      (unless (zero? r)
+	(error
+	 (sprintf "shell command failed with nonzero exit status ~a:~%~%  ~a" r str))))))
 
 (define (setup-error-handling)
   (current-exception-handler
Trap