Already found a bug in the Windows code of course.  This patch replaces the
setup-api 0003 patch from the last message.

I will try to get a Windows VM running so I can test this myself.



On Thu, Apr 14, 2016 at 3:22 PM, Jim Ursetto <zbignie...@gmail.com> wrote:

> This is an initial patchset for #1277 on which I invite comments.
>
> The problem was correctly diagnosed in that OS X 10.11 blacklists
> certain environment variables such as DYLD_LIBRARY_PATH from being
> passed to trusted binaries, and /bin/sh is trusted.  This prevents
> `make check` from working.
>
> The cleanest solution was to change certain 'system' calls (to
> chicken, csc and csi) to direct calls via 'process-run'.  This avoids
> the blacklisting problem and as a bonus, lets us avoid quoting shell
> metacharacters.
>
> Since this needs thorough testing, it probably has to wait until after
> 4.11.  I did test building and rebuilding of the compiler as well as
> installing chickadee and dependencies, on OS X.
>
> Issues:
>
> 1. I don't know if it works on Windows.  It needs to be tested.  If it
> doesn't work we could fall back to the shell method, at the cost of
> extra code.
>
> 2. Only the minimum required calls were changed to direct: csc call
> out to chicken; chicken-install call out to csi; setup-api (compile)
> calls.  There are several other opportunities for direct calls, but
> they are not needed to pass the tests on OS X, so can be deferred until
> after this is approved and verified to work.
>
> 3. Some code duplication for execing of processes.
>
> 4. It loses a bit of quoting in verbose mode; we don't try to simulate
> a quoted shell command.
>
> Compatibility issue:
>
> The 'reverser' test executes a (compile) step via
> (standard-extension), so the (compile) macro was converted to direct
> call.  However, this affects a minority of eggs which execute
> backticks or assume a string with spaces denotes multiple arguments
> (usually, C or LD flags).  I think this is preferable and we should
> disallow shell metacharacters in (compile).  (run (csc ...)) still
> retains the old behavior, but a few eggs would have to be updated to
> use this form, so this is backwards incompatible.  If not acceptable, we
> could implement (compile*) separately and change standard-extension to
> use it, which would allow the test to pass without disrupting any
> eggs.
>
>
>
From a6dc1a05acb20bdc8ca1c24fac4f522182478b76 Mon Sep 17 00:00:00 2001
From: Jim Ursetto <zbignie...@gmail.com>
Date: Thu, 14 Apr 2016 12:31:33 -0500
Subject: [PATCH] Add (run*) to setup-api; change (compile) from shell to
 direct call (#1277)

A new macro (run*) is exported, which is like (run) but does not rely on
the shell.  (compile) is changed to be (run* (csc ...)).

This permits blacklisted environment variables such as DYLD_LIBRARY_PATH
to be passed to csc on OS X 10.11, addressing a problem with the
deployment tests in `make check` in bug #1277.

Due to the changed semantics of (compile), certain eggs which rely on
backticks or pass flags as single strings to (compile) will need to be
updated; for example, to use (run (csc ...)).
---
 setup-api.scm | 107 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 80 insertions(+), 27 deletions(-)

diff --git a/setup-api.scm b/setup-api.scm
index f4168a6..7db0c80 100644
--- a/setup-api.scm
+++ b/setup-api.scm
@@ -37,6 +37,7 @@
 (module setup-api
 
     ((run execute)
+     (run* execute*)
      compile
      standard-extension
      host-extension
@@ -212,12 +213,21 @@
   (set! *registered-programs* 
     (alist-cons (->string name) path *registered-programs*)))
 
+;; Not used here, but exported; may be relied on externally
 (define (find-program name)
+  (find-program* name #t))
+
+;; (run) does not quote or normalize unregistered program names, so names 
containing spaces are
+;; interpolated unchanged into the shell command line; this behavior is 
explicitly relied upon
+;; in *copy-command* for example.  This complicates the logic.
+(define (find-program* name shell?)
   (let* ((name (->string name))
         (a (assoc name *registered-programs*)))
-    (if a
-       (shellpath (cdr a))
-       name)))
+    (if shell?
+       (if a
+           (shellpath (cdr a))
+           name) ; deliberately not quoted
+       (normalize-pathname (if a (cdr a) name)))))
 
 (let ()
   (define (reg name rname) 
@@ -234,31 +244,41 @@
   (and-let* ((tp (runtime-prefix)))
     (make-pathname tp fname)))
 
-(define (fixpath prg)
+(define (_fixpath prg shell?)
+  ;; Requires shell? argument because unregistered programs should not be 
quoted,
+  ;; so we cannot simply quote in the caller.
   (cond ((string=? prg "csc")
-        (string-intersperse 
-         (cons*
-          (find-program "csc")
-          "-feature" "compiling-extension" 
-          (if (or (deployment-mode)
-                  (and (feature? #:cross-chicken)
-                       (not (host-extension))))
-              "" "-setup-mode")
-          (if (keep-intermediates) "-k" "")
-          (if (host-extension) "-host" "")
-          (if (deployment-mode) "-deployed" "")
-          (append
-           (map (lambda (f)
-                  (string-append "-feature " (symbol->string f)))
-                (extra-features))
-           (map (lambda (f)
-                  (string-append "-no-feature " (symbol->string f)))
-                (extra-nonfeatures))
-           *csc-options*) )
-         " ") )
+        `(,(find-program* "csc" shell?)
+          "-feature" "compiling-extension"
+          ,@(if (or (deployment-mode)
+                    (and (feature? #:cross-chicken)
+                         (not (host-extension))))
+                '() '("-setup-mode"))
+          ,@(if (keep-intermediates) '("-k") '())
+          ,@(if (host-extension) '("-host") '())
+          ,@(if (deployment-mode) '("-deployed") '())
+          ;; done up to here
+          ,@(map (lambda (f)
+                   `("-feature" ,f))
+                 (extra-features))
+          ,@(map (lambda (f)
+                   `("-no-feature" ,f))
+                 (extra-nonfeatures))
+          ,@*csc-options* ) )
        ((and (string-prefix? "./" prg) *windows-shell*)
-        (shellpath (substring prg 2)))
-       (else (find-program prg))))
+        (let ((prg (substring prg 2)))
+          (list
+           (if shell?
+               (shellpath prg)
+               (normalize-pathname prg)))))
+       (else (list (find-program* prg shell?)))))
+
+(define (fixpath prg) ; compress result list into a shell command string
+  (let ((path (_fixpath prg #t)))
+    (string-intersperse (map ->string path)
+                       " ")))
+(define (fixpath* prg)
+  (_fixpath (->string prg) #f))
 
 (define (execute explist)
   (define (smooth lst)
@@ -275,10 +295,25 @@
     ((_ exp ...)
      (execute (list `exp ...)))))
 
+(define (execute* explist)
+  (for-each
+   (lambda (cmdlist)
+     (let ((L (append (fixpath* (car cmdlist))
+                     (cdr cmdlist))))
+       (when (run-verbose)  ; should be part of $exec ?
+        (printf "  ~A~%~!" (string-intersperse (map ->string L))))
+       ($exec (car L) (cdr L))))
+   explist))
+
+(define-syntax run*
+  (syntax-rules ()
+    ((_ exp ...)
+     (execute* (list `exp ...)))))
+
 (define-syntax compile
   (syntax-rules ()
     ((_ exp ...)
-     (run (csc exp ...)))))
+     (run* (csc exp ...)))))
 
 
 ;;; Processing setup scripts
@@ -644,6 +679,24 @@
       (error
        (sprintf "shell command failed with nonzero exit status ~a:~%~%  ~a" r 
str)))))
 
+(define ($exec cmd args)
+  (let ((verbose #f) (dry-run #f))
+    (let* ((args (map ->string args))
+          (str (string-intersperse (cons cmd args)))) ; no quoting is rendered
+      (when verbose (print str))
+      (receive (_ normal return-code)
+         (if dry-run
+             (values #f #t 0)
+             (process-wait (process-run cmd args)))
+       (cond ((= 0 return-code)
+              (unless normal
+                (error "unexpected 0 return code with abnormal exit" str)))
+             (normal
+              (error "command terminated with non-zero exit status" 
return-code str))
+             (else
+              (error "command terminated on signal" return-code str)))))))
+
+
 (define (setup-error-handling)
   (current-exception-handler
    (lambda (c)
-- 
2.2.1

_______________________________________________
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to