1.0.42.20: use platform-dependent CFLAGS consistently in tests
authorNikodemus Siivola <nikodemus@random-state.net>
Wed, 1 Sep 2010 17:21:07 +0000 (17:21 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Wed, 1 Sep 2010 17:21:07 +0000 (17:21 +0000)
 Patch by Josh Elsasser, lp#615499.

 In his words:

 "Attached is a patch which moves all the duplicated, out-of-sync C
 compiler flag selection in the tests into a single wrapper script.
 When passed a flag like -sbcl-pic or -sbcl-shared, the script will
 decided if -fPIC or -shared/-bundle is needed based on SOFTWARE-TYPE
 and MACHINE-TYPE which SBCL has passed in the environment.

 I tested this on several x86 OSes and a couple PowerPC, as well as
 SunOS on SPARC and OpenBSD on x86-64. For the -sbcl-pic case I have
 verified that -fPIC is needed on OpenBSD-PowerPC, OpenBSD-X86-64,
 SunOS-SPARC and SunOS-X86; the other cases are guesses based on the
 existing reader conditionals. It is not needed on Darwin or Linux on
 PowerPC, or on any x86 OSes I tested aside from SunOS.

 I haven't verified that -arch x86_64 is actually needed on
 Darwin-X86-64, or that something like -m64 isn't needed on other
 X86-64 OSes (aside from OpenBSD)."

tests/foreign-stack-alignment.impure.lisp
tests/foreign.test.sh
tests/kill-non-lisp-thread.impure.lisp
tests/run-compiler.sh [new file with mode: 0644]
tests/run-tests.lisp
tests/swap-lispobjs.impure.lisp
tests/test-util.lisp
tests/threads.impure.lisp
version.lisp-expr

index 4ca957d..069c5e8 100644 (file)
@@ -22,7 +22,7 @@
          (output
           (with-output-to-string (s)
             (setf proc (run-program program arguments
-                                    :search (not (eql #\. (char program 0)))
+                                    :environment (test-util::test-env)
                                     :output s)))))
     (unless (zerop (process-exit-code proc))
       (error "Bad exit code: ~S~%Output:~% ~S"
@@ -43,9 +43,7 @@
 ;;;; fork/exec, so that no lisp is on the stack. This is our known-good
 ;;;; number.
 
-(run "cc"
-     #+(and (or linux freebsd) (or x86-64 ppc mips)) "-fPIC"
-     #+(and x86-64 darwin) "-arch" #+(and x86-64 darwin) "x86_64"
+(run "/bin/sh" "run-compiler.sh" "-sbcl-pic"
      "stack-alignment-offset.c" "-o" "stack-alignment-offset")
 
 (defparameter *good-offset*
 
 ;;;; Build the tool again, this time as a shared object, and load it
 
-(run "cc" "stack-alignment-offset.c"
-     #+(and (not darwin) (or x86-64 ppc mips)) "-fPIC"
-     #+(and x86-64 darwin) "-arch" #+(and x86-64 darwin) "x86_64"
-     #+darwin "-bundle" #-darwin "-shared"
-     "-o" "stack-alignment-offset.so")
+(run "/bin/sh" "run-compiler.sh" "-sbcl-pic" "-sbcl-shared"
+     "stack-alignment-offset.c" "-o" "stack-alignment-offset.so")
 
 (load-shared-object (truename "stack-alignment-offset.so"))
 
index 2c5d0d3..bc97a83 100644 (file)
@@ -30,31 +30,7 @@ PUNT=$EXIT_TEST_WIN
 
 build_so() (
   echo building $1.so
-  set +u
-  case "`uname -m`" in
-      x86_64|amd64|mips|mips64)
-         CFLAGS="$CFLAGS -fPIC"
-         ;;
-  esac
-  case "`uname`" in
-      Darwin)
-          SO_FLAGS="-bundle"
-          if run_sbcl --eval '(sb-ext:quit :unix-status #+x86-64 0 #-x86-64 1)'; then
-              CFLAGS="$CFLAGS -arch x86_64"
-          fi
-          ;;
-      OpenBSD)
-          SO_FLAGS="-shared"
-          if [ "`machine -a`" = "powerpc" ]; then
-              CFLAGS="$CFLAGS -fPIC"
-          fi
-          ;;
-      *)
-          SO_FLAGS="-shared"
-          ;;
-  esac
-  cc -c $1.c -o $1.o $CFLAGS
-  ld $SO_FLAGS -o $1.so $1.o  
+  /bin/sh ../run-compiler.sh -sbcl-pic -sbcl-shared "$1.c" -o "$1.so"
 )
 
 # We want to bail out in case any of these Unix programs fails.
index 8a4b661..29680cc 100644 (file)
@@ -21,7 +21,7 @@
          (output
           (with-output-to-string (s)
             (setf proc (run-program program arguments
-                                    :search (not (eql #\. (char program 0)))
+                                    :environment (test-util::test-env)
                                     :output s)))))
     (unless (zerop (process-exit-code proc))
       (error "Bad exit code: ~S~%Output:~% ~S"
              output))
     output))
 
-(run "cc" "-O3"
-     "-I" "../src/runtime/"
-     "kill-non-lisp-thread.c"
-     #+(and (or linux freebsd) (or x86-64 ppc mips)) "-fPIC"
-     #+(and x86-64 darwin) "-arch" #+(and x86-64 darwin) "x86_64"
-     #+darwin "-bundle" #-darwin "-shared"
-     "-o" "kill-non-lisp-thread.so")
+(run "/bin/sh" "run-compiler.sh" "-sbcl-pic" "-sbcl-shared"
+     "-O3" "-I" "../src/runtime/"
+     "kill-non-lisp-thread.c" "-o" "kill-non-lisp-thread.so")
 
 (load-shared-object (truename "kill-non-lisp-thread.so"))
 
diff --git a/tests/run-compiler.sh b/tests/run-compiler.sh
new file mode 100644 (file)
index 0000000..3532fe3
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+platform="${SBCL_SOFTWARE_TYPE}-${SBCL_MACHINE_TYPE}"
+
+case "$platform" in
+    SunOS-*) CC=gcc ;;
+    *) CC=cc ;;
+esac
+
+args=
+case "$platform" in
+    Darwin-X86-64) args="-arch x86_64" ;;
+esac
+
+while [ $# -gt 0 ]; do
+    arg="$1"
+    new=
+    case "$arg" in
+        -sbcl-pic)
+            case "$platform" in
+                FreeBSD-X86-64)  new=-fPIC ;;
+                Linux-MIPS)      new=-fPIC ;;
+                Linux-X86-64)    new=-fPIC ;;
+                NetBSD-PowerPC)  new=-fPIC ;;
+                NetBSD-X86-64)   new=-fPIC ;;
+                OpenBSD-PowerPC) new=-fPIC ;;
+                OpenBSD-X86-64)  new=-fPIC ;;
+                SunOS-SPARC)     new=-fPIC ;;
+                SunOS-X86)       new=-fPIC ;;
+                SunOS-X86-64)    new=-fPIC ;;
+            esac
+            ;;
+
+        -sbcl-shared)
+            case "$platform" in
+                Darwin-*)        new=-bundle ;;
+                *)               new=-shared ;;
+            esac
+            ;;
+
+        *)
+            break
+            ;;
+    esac
+
+    shift
+    if [ x"$new" != x ]; then
+        args="$args $new"
+    fi
+done
+
+echo "/ $CC $args $@"
+"$CC" $args "$@"
index d2942b1..8cb583f 100644 (file)
   ;; What? No SB-POSIX:EXECV?
   `(let ((process (sb-ext:run-program "/bin/sh"
                                       (list (native-namestring ,file))
+                                      :environment (test-util::test-env)
                                       :output *error-output*)))
      (sb-ext:quit :unix-status (process-exit-code process))))
 
index c3cf6f5..b3c2f49 100644 (file)
@@ -21,7 +21,7 @@
          (output
           (with-output-to-string (s)
             (setf proc (run-program program arguments
-                                    :search (not (eql #\. (char program 0)))
+                                    :environment (test-util::test-env)
                                     :output s)))))
     (unless (zerop (process-exit-code proc))
       (error "Bad exit code: ~S~%Output:~% ~S"
              output))
     output))
 
-(run "cc" "-O3"
-     "-I" "../src/runtime/"
-     "swap-lispobjs.c"
-     #+(and (or linux freebsd) (or x86-64 ppc mips)) "-fPIC"
-     #+(and x86-64 darwin) "-arch" #+(and x86-64 darwin) "x86_64"
-     #+darwin "-bundle" #-darwin "-shared"
-     "-o" "swap-lispobjs.so")
+(run "/bin/sh" "run-compiler.sh"
+     "-sbcl-pic" "-sbcl-shared"
+     "-O3" "-I" "../src/runtime/"
+     "swap-lispobjs.c" "-o" "swap-lispobjs.so")
 
 (load-shared-object (truename "swap-lispobjs.so"))
 
index f9ca05f..cdc422c 100644 (file)
@@ -65,3 +65,8 @@
     (let ((*invoke-debugger-hook* *invoke-debugger-hook*))
       (enable-debugger)
       (invoke-debugger condition))))
+
+(defun test-env ()
+  (cons (format nil "SBCL_MACHINE_TYPE=~A" (machine-type))
+        (cons (format nil "SBCL_SOFTWARE_TYPE=~A" (software-type))
+              (posix-environ))))
index 4205a00..1dc2e04 100644 (file)
 
 (with-open-file (o "threads-foreign.c" :direction :output :if-exists :supersede)
   (format o "void loop_forever() { while(1) ; }~%"))
-(sb-ext:run-program
- #-sunos "cc" #+sunos "gcc"
- (or #+(or linux freebsd sunos) '(#+x86-64 "-fPIC"
-                                  "-shared" "-o" "threads-foreign.so" "threads-foreign.c")
-     #+darwin '(#+x86-64 "-arch" #+x86-64 "x86_64"
-                "-dynamiclib" "-o" "threads-foreign.so" "threads-foreign.c")
-     (error "Missing shared library compilation options for this platform"))
- :search t)
+(sb-ext:run-program "/bin/sh"
+                    '("run-compiler.sh" "-sbcl-pic" "-sbcl-shared"
+                      "-o" "threads-foreign.so" "threads-foreign.c")
+                    :environment (test-util::test-env))
 (sb-alien:load-shared-object (truename "threads-foreign.so"))
 (sb-alien:define-alien-routine loop-forever sb-alien:void)
 (delete-file "threads-foreign.c")
index 7a89c31..0dfe4aa 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.42.19"
+"1.0.42.20"