summaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorMarius Bakke <mbakke@fastmail.com>2017-02-13 22:35:05 +0100
committerMarius Bakke <mbakke@fastmail.com>2017-02-13 22:35:05 +0100
commit424b1ae76901c538457bd3c30d9d9cf67e79855f (patch)
treeacc35c1160625618cd6083e728c6a4ff7e9cccc9 /guix/build
parenta50e03014177d2f00b5b85d3e1c295406f842016 (diff)
parenteae2dbd47ac1f4a201b8584e2f88c30cd28e093a (diff)
Merge branch 'master' into python-tests
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/bournish.scm11
-rw-r--r--guix/build/dub-build-system.scm125
-rw-r--r--guix/build/r-build-system.scm3
-rw-r--r--guix/build/syscalls.scm137
4 files changed, 270 insertions, 6 deletions
diff --git a/guix/build/bournish.scm b/guix/build/bournish.scm
index 51dad17ba7..e948cd03d3 100644
--- a/guix/build/bournish.scm
+++ b/guix/build/bournish.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -105,6 +106,14 @@ characters."
((@ (guix build utils) dump-port) port (current-output-port))
*unspecified*)))
+(define (rm-command . args)
+ "Emit code for the 'rm' command."
+ (cond ((member "-r" args)
+ `(for-each (@ (guix build utils) delete-file-recursively)
+ (list ,@(delete "-r" args))))
+ (else
+ `(for-each delete-file (list ,@args)))))
+
(define (lines+chars port)
"Return the number of lines and number of chars read from PORT."
(let loop ((lines 0) (chars 0))
@@ -194,7 +203,7 @@ commands such as 'ls' and 'cd'; it lacks globbing, pipes---everything.\n"))
`(("echo" ,(lambda strings `(list ,@strings)))
("cd" ,(lambda (dir) `(chdir ,dir)))
("pwd" ,(lambda () `(getcwd)))
- ("rm" ,(lambda (file) `(delete-file ,file)))
+ ("rm" ,rm-command)
("cp" ,(lambda (source dest) `(copy-file ,source ,dest)))
("help" ,help-command)
("ls" ,ls-command)
diff --git a/guix/build/dub-build-system.scm b/guix/build/dub-build-system.scm
new file mode 100644
index 0000000000..7c7cd8803c
--- /dev/null
+++ b/guix/build/dub-build-system.scm
@@ -0,0 +1,125 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 David Craven <david@craven.ch>
+;;; Copyright © 2017 Danny Milosavljevic <dannym@scratchpost.org>
+;;;
+;;; 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 (guix build dub-build-system)
+ #:use-module ((guix build gnu-build-system) #:prefix gnu:)
+ #:use-module (guix build syscalls)
+ #:use-module (guix build utils)
+ #:use-module (ice-9 popen)
+ #:use-module (ice-9 rdelim)
+ #:use-module (ice-9 ftw)
+ #:use-module (ice-9 format)
+ #:use-module (ice-9 match)
+ #:use-module (rnrs io ports)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:export (%standard-phases
+ dub-build))
+
+;; Commentary:
+;;
+;; Builder-side code of the DUB (the build tool for D) build system.
+;;
+;; Code:
+
+;; FIXME: Needs to be parsed from url not package name.
+(define (package-name->d-package-name name)
+ "Return the package name of NAME."
+ (match (string-split name #\-)
+ (("d" rest ...)
+ (string-join rest "-"))
+ (_ #f)))
+
+(define* (configure #:key inputs #:allow-other-keys)
+ "Prepare one new directory with all the required dependencies.
+ It's necessary to do this (instead of just using /gnu/store as the
+ directory) because we want to hide the libraries in subdirectories
+ lib/dub/... instead of polluting the user's profile root."
+ (let* ((dir (mkdtemp! "/tmp/dub.XXXXXX"))
+ (vendor-dir (string-append dir "/vendor")))
+ (setenv "HOME" dir)
+ (mkdir vendor-dir)
+ (for-each
+ (match-lambda
+ ((name . path)
+ (let* ((d-package (package-name->d-package-name name))
+ (d-basename (basename path)))
+ (when (and d-package path)
+ (match (string-split (basename path) #\-)
+ ((_ ... version)
+ (symlink (string-append path "/lib/dub/" d-basename)
+ (string-append vendor-dir "/" d-basename))))))))
+ inputs)
+ (zero? (system* "dub" "add-path" vendor-dir))))
+
+(define (grep string file-name)
+ "Find the first occurence of STRING in the file named FILE-NAME.
+ Return the position of this occurence, or #f if none was found."
+ (string-contains (call-with-input-file file-name get-string-all)
+ string))
+
+(define (grep* string file-name)
+ "Find the first occurence of STRING in the file named FILE-NAME.
+ Return the position of this occurence, or #f if none was found.
+ If the file named FILE-NAME doesn't exist, return #f."
+ (catch 'system-error
+ (lambda ()
+ (grep string file-name))
+ (lambda args
+ #f)))
+
+(define* (build #:key (dub-build-flags '())
+ #:allow-other-keys)
+ "Build a given DUB package."
+ (if (or (grep* "sourceLibrary" "package.json")
+ (grep* "sourceLibrary" "dub.sdl") ; note: format is different!
+ (grep* "sourceLibrary" "dub.json"))
+ #t
+ (let ((status (zero? (apply system* `("dub" "build" ,@dub-build-flags)))))
+ (system* "dub" "run") ; might fail for "targetType": "library"
+ status)))
+
+(define* (check #:key tests? #:allow-other-keys)
+ (if tests?
+ (zero? (system* "dub" "test"))
+ #t))
+
+(define* (install #:key inputs outputs #:allow-other-keys)
+ "Install a given DUB package."
+ (let* ((out (assoc-ref outputs "out"))
+ (outbin (string-append out "/bin"))
+ (outlib (string-append out "/lib/dub/" (basename out))))
+ (mkdir-p outbin)
+ ;; TODO remove "-test-application"
+ (copy-recursively "bin" outbin)
+ (mkdir-p outlib)
+ (copy-recursively "." (string-append outlib))
+ #t))
+
+(define %standard-phases
+ (modify-phases gnu:%standard-phases
+ (replace 'configure configure)
+ (replace 'build build)
+ (replace 'check check)
+ (replace 'install install)))
+
+(define* (dub-build #:key inputs (phases %standard-phases)
+ #:allow-other-keys #:rest args)
+ "Build the given DUB package, applying all of PHASES in order."
+ (apply gnu:gnu-build #:inputs inputs #:phases phases args))
diff --git a/guix/build/r-build-system.scm b/guix/build/r-build-system.scm
index 3fc13eb835..24aa73d4f2 100644
--- a/guix/build/r-build-system.scm
+++ b/guix/build/r-build-system.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -84,6 +84,7 @@
(params (append configure-flags
(list "--install-tests"
(string-append "--library=" site-library)
+ "--built-timestamp=1970-01-01"
".")))
(site-path (string-append site-library ":"
(generate-site-path inputs))))
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 2e37846ff0..b68c48a05a 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -21,10 +21,12 @@
(define-module (guix build syscalls)
#:use-module (system foreign)
#:use-module (rnrs bytevectors)
+ #:autoload (ice-9 binary-ports) (get-bytevector-n)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-9 gnu)
#:use-module (srfi srfi-11)
+ #:use-module (srfi srfi-19)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 regex)
#:use-module (ice-9 match)
@@ -126,7 +128,23 @@
window-size-x-pixels
window-size-y-pixels
terminal-window-size
- terminal-columns))
+ terminal-columns
+
+ utmpx?
+ utmpx-login-type
+ utmpx-pid
+ utmpx-line
+ utmpx-id
+ utmpx-user
+ utmpx-host
+ utmpx-termination-status
+ utmpx-exit-status
+ utmpx-session-id
+ utmpx-time
+ utmpx-address
+ login-type
+ utmpx-entries
+ (read-utmpx-from-port . read-utmpx)))
;;; Commentary:
;;;
@@ -900,6 +918,15 @@ bytevector BV at INDEX."
;; The most terrible interface, live from Scheme.
(syscall->procedure int "ioctl" (list int unsigned-long '*)))
+(define (bytes->string bytes)
+ "Read BYTES, a list of bytes, and return the null-terminated string decoded
+from there, or #f if that would be an empty string."
+ (match (take-while (negate zero?) bytes)
+ (()
+ #f)
+ (non-zero
+ (list->string (map integer->char non-zero)))))
+
(define (bytevector->string-list bv stride len)
"Return the null-terminated strings found in BV every STRIDE bytes. Read at
most LEN bytes from BV."
@@ -911,9 +938,7 @@ most LEN bytes from BV."
(reverse result))
(_
(loop (drop bytes stride)
- (cons (list->string (map integer->char
- (take-while (negate zero?) bytes)))
- result))))))
+ (cons (bytes->string bytes) result))))))
(define* (network-interface-names #:optional sock)
"Return the names of existing network interfaces. This is typically limited
@@ -1480,4 +1505,108 @@ always a positive integer."
(fall-back)
(apply throw args))))))
+
+;;;
+;;; utmpx.
+;;;
+
+(define-record-type <utmpx-entry>
+ (utmpx type pid line id user host termination exit
+ session time address)
+ utmpx?
+ (type utmpx-login-type) ;login-type
+ (pid utmpx-pid)
+ (line utmpx-line) ;device name
+ (id utmpx-id)
+ (user utmpx-user) ;user name
+ (host utmpx-host) ;host name | #f
+ (termination utmpx-termination-status)
+ (exit utmpx-exit-status)
+ (session utmpx-session-id) ;session ID, for windowing
+ (time utmpx-time) ;entry time
+ (address utmpx-address))
+
+(define-c-struct %utmpx ;<utmpx.h>
+ sizeof-utmpx
+ (lambda (type pid line id user host termination exit session
+ seconds useconds address %reserved)
+ (utmpx type pid
+ (bytes->string line) id
+ (bytes->string user)
+ (bytes->string host) termination exit
+ session
+ (make-time time-utc (* 1000 useconds) seconds)
+ address))
+ read-utmpx
+ write-utmpx!
+ (type short)
+ (pid int)
+ (line (array uint8 32))
+ (id (array uint8 4))
+ (user (array uint8 32))
+ (host (array uint8 256))
+ (termination short)
+ (exit short)
+ (session int32)
+ (time-seconds int32)
+ (time-useconds int32)
+ (address-v6 (array int32 4))
+ (%reserved (array uint8 20)))
+
+(define-bits login-type
+ %unused-login-type->symbols
+ (define EMPTY 0) ;No valid user accounting information.
+ (define RUN_LVL 1) ;The system's runlevel.
+ (define BOOT_TIME 2) ;Time of system boot.
+ (define NEW_TIME 3) ;Time after system clock changed.
+ (define OLD_TIME 4) ;Time when system clock changed.
+
+ (define INIT_PROCESS 5) ;Process spawned by the init process.
+ (define LOGIN_PROCESS 6) ;Session leader of a logged in user.
+ (define USER_PROCESS 7) ;Normal process.
+ (define DEAD_PROCESS 8) ;Terminated process.
+
+ (define ACCOUNTING 9)) ;System accounting.
+
+(define setutxent
+ (let ((proc (syscall->procedure void "setutxent" '())))
+ (lambda ()
+ "Open the user accounting database."
+ (proc))))
+
+(define endutxent
+ (let ((proc (syscall->procedure void "endutxent" '())))
+ (lambda ()
+ "Close the user accounting database."
+ (proc))))
+
+(define getutxent
+ (let ((proc (syscall->procedure '* "getutxent" '())))
+ (lambda ()
+ "Return the next entry from the user accounting database."
+ (let ((ptr (proc)))
+ (if (null-pointer? ptr)
+ #f
+ (read-utmpx (pointer->bytevector ptr sizeof-utmpx)))))))
+
+(define (utmpx-entries)
+ "Return the list of entries read from the user accounting database."
+ (setutxent)
+ (let loop ((entries '()))
+ (match (getutxent)
+ (#f
+ (endutxent)
+ (reverse entries))
+ ((? utmpx? entry)
+ (loop (cons entry entries))))))
+
+(define (read-utmpx-from-port port)
+ "Read a utmpx entry from PORT. Return either the EOF object or a utmpx
+entry."
+ (match (get-bytevector-n port sizeof-utmpx)
+ ((? eof-object? eof)
+ eof)
+ ((? bytevector? bv)
+ (read-utmpx bv))))
+
;;; syscalls.scm ends here