aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2018, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2022 Chris Marusich <cmmarusich@gmail.com>
;;; Copyright © 2022 Pierre Langlois <pierre.langlois@gmx.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-gremlin)
  #:use-module (guix elf)
  #:use-module (guix tests)
  #:use-module ((guix utils) #:select (call-with-temporary-directory
                                       target-aarch64?))
  #:use-module (guix build utils)
  #:use-module (guix build gremlin)
  #:use-module (gnu packages bootstrap)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-64)
  #:use-module (rnrs io ports)
  #:use-module (ice-9 popen)
  #:use-module (ice-9 rdelim)
  #:use-module (ice-9 regex)
  #:use-module (ice-9 match))

(define %guile-executable
  (match (false-if-exception (readlink "/proc/self/exe"))
    ((? string? program)
     (and (file-exists? program) (elf-file? program)
          program))
    (_
     #f)))

(define read-elf
  (compose parse-elf get-bytevector-all))

(define c-compiler
  (or (which "gcc") (which "cc") (which "g++")))


(test-begin "gremlin")

(unless %guile-executable (test-skip 1))
(test-assert "elf-dynamic-info-needed, executable"
  (let* ((elf     (call-with-input-file %guile-executable read-elf))
         (dyninfo (elf-dynamic-info elf)))
    (or (not dyninfo)                             ;static executable
        (lset<= string=?
                (list (string-append "libguile-" (effective-version))
                      "libc")
                (map (lambda (lib)
                       (string-take lib (string-contains lib ".so")))
                     (elf-dynamic-info-needed dyninfo))))))

(unless (and %guile-executable (not (getenv "LD_LIBRARY_PATH"))
             (file-needed %guile-executable) ;statically linked?
             ;; When Guix has been built on a foreign distro, using a
             ;; toolchain and libraries from that foreign distro, it is not
             ;; unusual for the runpath to be empty.
             (pair? (file-runpath %guile-executable)))
  (test-skip 1))
(test-assert "file-needed/recursive"
  (let* ((needed (file-needed/recursive %guile-executable))
         (pipe   (dynamic-wind
                   (lambda ()
                     ;; Tell ld.so to list loaded objects, like 'ldd' does.
                     (setenv "LD_TRACE_LOADED_OBJECTS" "yup"))
                   (lambda ()
                     (open-pipe* OPEN_READ %guile-executable))
                   (lambda ()
                     (unsetenv "LD_TRACE_LOADED_OBJECTS")))))
    (define ldd-rx
      (make-regexp "^[[:blank:]]+([[:graph:]]+ => )?([[:graph:]]+) .*$"))

    (define (read-ldd-output port)
      ;; Read from PORT output in GNU ldd format.
      (let loop ((result '()))
        (match (read-line port)
          ((? eof-object?)
           (reverse result))
          ((= (cut regexp-exec ldd-rx <>) m)
           (if m
               (loop (cons (match:substring m 2) result))
               (loop result))))))
    (define ground-truth
      (remove (lambda (entry)
                ;; See vdso(7) for the list of vDSO names across
                ;; architectures.
                (or (string-prefix? "linux-vdso.so" entry)
                    (string-prefix? "linux-vdso32.so" entry) ;32-bit powerpc
                    (string-prefix? "linux-vdso64.so" entry) ;64-bit powerpc
                    (string-prefix? "linux-gate.so" entry)   ;i386
                    ;; FIXME: ELF files on aarch64 do not always include a
                    ;; NEEDED entry for the dynamic linker, and it is unclear
                    ;; if that is OK.  See: https://issues.guix.gnu.org/52943
                    (and (target-aarch64?)
                         (string-contains entry (glibc-dynamic-linker)))))
              (read-ldd-output pipe)))

    (and (zero? (close-pipe pipe))
         ;; It's OK if file-needed/recursive returns multiple entries that are
         ;; different strings referring to the same file.  This appears to be a
         ;; benign edge case.  See: https://issues.guix.gnu.org/52940
         (lset= file=? (pk 'truth ground-truth) (pk 'needed needed)))))

(test-equal "expand-origin"
  '("OOO/../lib"
    "OOO"
    "../OOO/bar/OOO/baz"
    "ORIGIN/foo")
  (map (cut expand-origin <> "OOO")
       '("$ORIGIN/../lib"
         "${ORIGIN}"
         "../${ORIGIN}/bar/$ORIGIN/baz"
         "ORIGIN/foo")))

(unless c-compiler
  (test-skip 1))
(test-equal "strip-runpath"
  "hello\n"
  (call-with-temporary-directory
   (lambda (directory)
     (with-directory-excursion directory
       (call-with-output-file "t.c"
         (lambda (port)
           (display "int main () { puts(\"hello\"); }" port)))
       (invoke c-compiler "t.c"
               "-Wl,--enable-new-dtags" "-Wl,-rpath=/foo" "-Wl,-rpath=/bar")
       (let* ((dyninfo (elf-dynamic-info
                        (parse-elf (call-with-input-file "a.out"
                                     get-bytevector-all))))
              (old     (elf-dynamic-info-runpath dyninfo))
              (new     (strip-runpath "a.out"))
              (new*    (strip-runpath "a.out")))
         (validate-needed-in-runpath "a.out")
         (and (member "/foo" old) (member "/bar" old)
              (not (member "/foo" new))
              (not (member "/bar" new))
              (equal? new* new)
              (let* ((pipe (open-input-pipe "./a.out"))
                     (str  (get-string-all pipe)))
                (close-pipe pipe)
                str)))))))

(unless c-compiler
  (test-skip 1))
(test-equal "set-file-runpath + file-runpath"
  "hello\n"
  (call-with-temporary-directory
   (lambda (directory)
     (with-directory-excursion directory
       (call-with-output-file "t.c"
         (lambda (port)
           (display "int main () { puts(\"hello\"); }" port)))

       (invoke c-compiler "t.c"
               "-Wl,--enable-new-dtags" "-Wl,-rpath=/xxxxxxxxx")

       (let ((original-runpath (file-runpath "a.out")))
         (and (member "/xxxxxxxxx" original-runpath)
              (guard (c ((runpath-too-long-error? c)
                         (string=? "a.out" (runpath-too-long-error-file c))))
                (set-file-runpath "a.out" (list (make-string 777 #\y))))
              (let ((runpath (delete "/xxxxxxxxx" original-runpath)))
                (set-file-runpath "a.out" runpath)
                (equal? runpath (file-runpath "a.out")))
              (let* ((pipe (open-input-pipe "./a.out"))
                     (str  (get-string-all pipe)))
                (close-pipe pipe)
                str)))))))

(unless c-compiler
  (test-skip 1))
(test-equal "elf-dynamic-info-soname"
  "libfoo.so.2"
  (call-with-temporary-directory
   (lambda (directory)
     (with-directory-excursion directory
       (call-with-output-file "t.c"
         (lambda (port)
           (display "// empty file" port)))
       (invoke c-compiler "t.c"
               "-shared" "-Wl,-soname,libfoo.so.2")
       (let* ((dyninfo (elf-dynamic-info
                       (parse-elf (call-with-input-file "a.out"
                                    get-bytevector-all))))
              (soname  (elf-dynamic-info-soname dyninfo)))
	 soname)))))

(test-end "gremlin")
, gnu/packages/web.scm, gnu/packages/wordnet.scm, gnu/packages/xiph.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, gnu/packages/zile.scm, gnu/packages/zip.scm, gnu/packages/zsh.scm [synopsis, description]: Adjust according to lint checkers. * gnu/packages/fltk.scm (fltk)[source]: Wrap long line in uri. * /gnu/packages/xiph.scm (libogg, libtheora, vorbis-tools)[source]: Same. Eric Bavier 2014-10-13gnu: guile-ssh: Update to 0.7.1....* gnu/packages/ssh.scm (guile-ssh)[source]: Update to 0.7.1. [arguments]: Remove ssh/Makefile.am fiddling from 'autoreconf' phase. Remove #:parallel-build? argument. [inputs]: Add LIBGCRYPT-1.5. Ludovic Courtès 2014-10-13gnu: libssh: Add libgcrypt bug-fix patch....Suggested by Artyom Poptsov <poptsov.artyom@gmail.com>. * gnu/packages/ssh.scm (libssh)[source]: Add 'patches'. Ludovic Courtès 2014-10-11gnu: openssh: Update to 6.7p1....* gnu/packages/ssh.scm (openssh): Update to 6.7p1. Mark H Weaver 2014-09-23Use #:prefix instead of #:renamer with 'symbol-prefix-proc'....* gnu/packages/abiword.scm, gnu/packages/admin.scm, gnu/packages/aidc.scm, gnu/packages/backup.scm, gnu/packages/bittorrent.scm, gnu/packages/boost.scm, gnu/packages/compression.scm, gnu/packages/cryptsetup.scm, gnu/packages/curl.scm, gnu/packages/cyrus-sasl.scm, gnu/packages/dc.scm, gnu/packages/emacs.scm, gnu/packages/fonts.scm, gnu/packages/fontutils.scm, gnu/packages/geeqie.scm, gnu/packages/ghostscript.scm, gnu/packages/gimp.scm, gnu/packages/gkrellm.scm, gnu/packages/gl.scm, gnu/packages/glib.scm, gnu/packages/gnome.scm, gnu/packages/gnunet.scm, gnu/packages/gnupg.scm, gnu/packages/gnutls.scm, gnu/packages/gnuzilla.scm, gnu/packages/gsasl.scm, gnu/packages/gtk.scm, gnu/packages/gv.scm, gnu/packages/image.scm, gnu/packages/indent.scm, gnu/packages/inkscape.scm, gnu/packages/lesstif.scm, gnu/packages/links.scm, gnu/packages/lisp.scm, gnu/packages/lsh.scm, gnu/packages/lsof.scm, gnu/packages/maths.scm, gnu/packages/mp3.scm, gnu/packages/openssl.scm, gnu/packages/ots.scm, gnu/packages/pciutils.scm, gnu/packages/pcre.scm, gnu/packages/pdf.scm, gnu/packages/pulseaudio.scm, gnu/packages/python.scm, gnu/packages/slim.scm, gnu/packages/ssh.scm, gnu/packages/texlive.scm, gnu/packages/vim.scm, gnu/packages/vpn.scm, gnu/packages/web.scm, gnu/packages/wv.scm, gnu/packages/xiph.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, gnu/packages/yasm.scm, gnu/packages/zip.scm, guix/build/cmake-build-system.scm, guix/build/perl-build-system.scm, guix/build/python-build-system.scm, guix/download.scm: Replaces uses of #:renamer and 'symbol-prefix-proc' with #:prefix. Mark H Weaver 2014-09-13gnu: Adjust synopses as recommended by 'guix lint'....Remove leading articles and trailing periods in package synopses. Ludovic Courtès 2014-06-12gnu: Add dropbear....* gnu/packages/ssh.scm (dropbear): New variable. John Darrington 2014-04-27guix: cmake: Add input and package libraries to the rpath, and adapt package... definitions accordingly. * guix/build/cmake-build-system.scm (configure): Add flags. * gnu/packages/maths.scm (lapack): Drop special code. * gnu/packages/ssh.scm (libssh): Drop special code. * gnu/packages/slim.scm (slim): Drop special code and enable shared library. Co-authored-by: Eric Bavier <bavier@member.fsf.org> Andreas Enge 2014-04-12openssh: Add another mirror....* gnu/packages/ssh.scm (openssh): Add the mirror. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Nikita Karetnikov 2014-04-11gnu: Add Mosh....* gnu/packages/ssh.scm (mosh): New variable. Ludovic Courtès 2014-04-04gnu: guile-ssh: Use libssh 0.5.5 patched for CVE-2014-0017....* gnu/packages/patches/libssh-CVE-2014-0017.patch: New file. * gnu-system.am (dist_patch_DATA): Add it. * gnu/packages/ssh.scm (libssh-0.5): New variable. (guile-ssh): Use it. Ludovic Courtès 2014-04-02gnu: libssh: Upgrade to 0.6.3....* gnu/packages/ssh.scm (libssh): Upgrade to 0.6.3. Mark H Weaver 2014-03-31gnu: Remove unused lambda arguments and prefer separate phases over...augmented phases. * gnu/packages/compression.scm (sharutils) [arguments]: Remove unused lambda args. * gnu/packages/gl.scm (mesa) [arguments]: Same * gnu/packages/fltk.scm [arguments]: Same. Substitute const check phase with #:tests? #f. Add pre-configure phase. * gnu/packages/ghostscript.scm (ghostscript) [arguments]: Put makefile patches in separate phase. Put so steps oinseparate phases. * gnu/packages/glib.scm (gobject-introspection) [arguments]: Remove unused lambda args. Put patches in pre-configure phase. * gnu/packages/gnupg.scm (gnupg) [arguments]: Put patch in pre-configure phase. (pius) [arguments]: Delete const #t configure and build phases. (signing-party) [arguments]: Factor patches into post-unpack phase. (paperkey) [arguments]: Remove unused lambda args. Factor out patches into pre-check phase. * gnu/packages/icu4c.scm [arguments]: Change source dir after standard unpack phase. Factor configure patches into pre-configure phase. * gnu/packages/lsof.scm [arguments]: Remove unused lambda args. Remove unnecessary apply. * gnu/packages/lvm.scm (lvm2) [arguments]: Factor out patches into pre-configure phase. * gnu/packages/libtiff.scm [arguments]: Same * gnu/packages/maths.scm (hdf5) [arguments]: Same * gnu/packages/gtk.scm (gtk+-2) [arguments]: Same * gnu/packages/mp3.scm (libmad) [arguments]: Same (id3lib) [arguments]: Same * gnu/packages/python.scm (python-2) [arguments]: Same * gnu/packages/texlive.scm (texlive) [arguments]: Same * gnu/packages/pretty-print.scm (a2ps) [arguments]: Same (trueprint) [arguments]: Same (source-highlight) [arguments]: Same. Remove unused lambda args. * gnu/packages/netpbm.scm [arguments]: Remove unused lambda args. Factor out test patches into pre-check phase. Condense calls to substitute* * gnu/packages/openldap.scm [arguments]: Factor out libtool copy into post-configure phases. [synopsis] Remove package name. * gnu/packages/ssh.scm (openssh) [arguments]: Factor out patches into separate phases. * gnu/packages/tcsh.scm [arguments]: Factor out test patches into pre-check phase. * gnu/packages/version-control.scm (git) [arguments]: Factor out patches into post-configure phase. * gnu/packages/vim.scm [arguments]: Same. [synopsis] Remove package name. * gnu/packages/vpn.scm (openconnect) [arguments]: Put configure flags in #:configure-flags Eric Bavier 2014-03-26gnu: libssh2: Fix use with libssh2.pc...* gnu/packages/ssh.scm (libssh2): Pass --with-libgcrypt configure flag and propagate inputs. Eric Bavier 2014-03-25gnu: guile-ssh: Upgrade to 0.6.0....* gnu/packages/ssh.scm (guile-ssh): Upgrade to 0.6.0. [arguments]: Remove #:tests? #f; add #:parallel-build? #f. Ludovic Courtès 2014-03-21gnu: openssh: Upgrade to 6.6p1....* gnu/packages/ssh.scm (openssh): Upgrade to 6.6p1. Mark H Weaver 2014-03-01gnu: guile-ssh: Upgrade to 0.5.0....* gnu/packages/ssh.scm (guile-ssh): Upgrade to 0.5.0. [arguments]: Adjust 'autoreconf' phase. Add #:parallel-tests? #f and #:tests? #f. [native-inputs]: Add TEXINFO. Ludovic Courtès 2014-02-09gnu: openssh: Upgrade to 6.5p1....* gnu/packages/ssh.scm (openssh): Upgrade to 6.5p1. Mark H Weaver 2014-01-25gnu: Add Corkscrew 2.0....* gnu/packages/ssh.scm (corkscrew): New variable. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Sree Harsha Totakura 2014-01-13gnu: guile-ssh: Remove now unneeded cruft....* gnu/packages/ssh.scm (guile-ssh): Remove libssh version hack from 'autoreconf' phase. Ludovic Courtès 2013-12-18gnu: libgcrypt: Make old version 1.5.3 public....* gnu/packages/gnupg.scm (libgcrypt-1.5): New variable. * gnu/packages/ssh.scm (libssh): Use libgcrypt-1.5 instead of defining it ad-hoc. Andreas Enge 2013-12-17gnu: libssh: Upgrade to 0.5.5....* gnu/packages/ssh.scm (libssh): Upgrade to 0.5.5. Ludovic Courtès 2013-12-17gnu: libssh: Build against an older libgcrypt....* gnu/packages/ssh.scm (libssh): Use libgcrypt 1.5.3 as an input. Ludovic Courtès 2013-12-15gnu: Move libelf and patchelf to (gnu packages elf)....* gnu/packages/patchelf.scm (patchelf): Move to... * gnu/packages/elf.scm (patchelf): ... here. * gnu/packages/patchelf.scm: Remove. * gnu-system.am (GNU_SYSTEM_MODULES): Adjust accordingly. * gnu/packages/gcc.scm (libelf): Move to... * gnu/packages/elf.scm (libelf): ... here. * gnu/packages/cdrom.scm, gnu/packages/icu4c.scm, gnu/packages/samba.scm, gnu/packages/scheme.scm, gnu/packages/ssh.scm: Adjust references to (gnu packages patchelf). Ludovic Courtès 2013-12-04gnu: Move 'guile-ssh' to (gnu packages ssh)....Reported by John Darrington <john@darrington.wattle.id.au>. * gnu/packages/guile.scm (guile-ssh): Move to... * gnu/packages/ssh.scm (guile-ssh): ... here. New variable. This fixes a circular dependency issue, as reported at <https://lists.gnu.org/archive/html/guix-devel/2013-12/msg00024.html>. Ludovic Courtès 2013-12-04gnu: libssh: Add $libdir to RUNPATH of libssh_threads.so....* gnu/packages/ssh.scm (libssh)[arguments]: Add #:phases, #:modules, and #:imported-modules. [native-inputs]: New field. Ludovic Courtès 2013-11-28gnu: Add libssh....* gnu/packages/ssh.scm (libssh): New variable. Ludovic Courtès