]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/libraries/finder/linux/linux.factor
use reject instead of [ ... not ] filter.
[factor.git] / basis / alien / libraries / finder / linux / linux.factor
index 97c8e1c3c8859d6a2660c6b8cc36720044303d43..406cb9a41e582199006760829e8839099a5c6b4c 100644 (file)
@@ -1,36 +1,52 @@
-! Copyright (C) 2013 Björn Lindqvist
+! Copyright (C) 2013 Björn Lindqvist, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license
-
-USING: alien.libraries alien.libraries.finder assocs io
-io.encodings.utf8 io.launcher kernel sequences splitting system
-;
-
+USING: alien.libraries.finder arrays assocs
+combinators.short-circuit io io.encodings.utf8 io.files
+io.files.info io.launcher kernel sequences sets splitting system
+unicode.categories ;
 IN: alien.libraries.finder.linux
 
 <PRIVATE
 
 CONSTANT: mach-map {
-    { ppc.64 "libc6,64bit" }
-    { x86.32 "libc6,x86-32" }
-    { x86.64 "libc6,x86-64" }
+    { ppc.64 { "libc6" "64bit" } }
+    { x86.32 { "libc6" "x32" } }
+    { x86.64 { "libc6" "x86-64" } }
 }
 
-: ldconfig-cache ( -- seq )
-    "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader rest
-    [ "=>" "" replace "\t " split harvest ] map ;
+: parse-ldconfig-lines ( string -- triple )
+    [
+        "=>" split1 [ [ blank? ] trim ] bi@
+        [
+            " " split1 [ "()" in? ] trim "," split
+            [ [ blank? ] trim ] map
+            [ "OS ABI:" head? ] reject
+        ] dip 3array
+    ] map ;
+
+: load-ldconfig-cache ( -- seq )
+    "/sbin/ldconfig -p" utf8 [ lines ] with-process-reader
+    rest parse-ldconfig-lines ;
 
-: ldconfig-filter ( -- str )
-    mach-map cpu of "libc6" or "(" ")" surround ;
+: ldconfig-arch ( -- str )
+    mach-map cpu of { "libc6" } or ;
 
-: ldconfig-matches? ( lib this-lib this-arch -- ? )
-    [ start 0 = ] [ ldconfig-filter = ] bi* and ;
+: name-matches? ( lib triple -- ? )
+    first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
+
+: arch-matches? ( lib triple -- ? )
+    [ drop ldconfig-arch ] [ second swap subset? ] bi* ;
+
+: ldconfig-matches? ( lib triple -- ? )
+    { [ name-matches? ] [ arch-matches? ] } 2&& ;
 
 : ldconfig-find-soname ( lib -- seq )
-    ldconfig-cache [ first2 ldconfig-matches? ] with filter [ first ] map ;
+    load-ldconfig-cache [ ldconfig-matches? ] with filter
+    [ third ] map ;
 
 PRIVATE>
 
-M: linux find-library
-    "lib" ".so" surround ldconfig-find-soname
-    [ dlopen dll-valid? ] map-find nip ;
-
+M: linux find-library*
+    "lib" prepend ldconfig-find-soname [
+        { [ exists? ] [ file-info regular-file? ] } 1&&
+    ] map-find nip ;