Subject: [bug#29409] [PATCH] build: utils: Introduce dd.

From: [email-masked]
Date: Thu, 30 Nov 2017 11:47:08 +0100

From: Mathieu Othacehe <[email-masked]>

* guix/build/utils.scm (dd): New exported procedure.
* gnu/bootloader/extlinux.scm (dd): Remove it,
(install-extlinux): replace gexp dd with dd added above.
---
Hi,

dd will be used in different bootloader related gexp. So it may be
good to add it to (guix build utils). The problem is that
it triggers a big rebuild. I was able to test this path with
"installed-extlinux-os".

Thanks,

Mathieu

 gnu/bootloader/extlinux.scm | 13 ++++---------
 guix/build/utils.scm        | 28 +++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm
index 0db5598..b0b463e 100644
--- a/gnu/bootloader/extlinux.scm
+++ b/gnu/bootloader/extlinux.scm
@@ -85,14 +85,6 @@ TIMEOUT ~a~%"
 ;;; Install procedures.
 ;;;
 
-(define dd
-  #~(lambda (bs count if of)
-      (zero? (system* "dd"
-                      (string-append "bs=" (number->string bs))
-                      (string-append "count=" (number->string count))
-                      (string-append "if=" if)
-                      (string-append "of=" of)))))
-
 (define (install-extlinux mbr)
   #~(lambda (bootloader device mount-point)
       (let ((extlinux (string-append bootloader "/sbin/extlinux"))
@@ -103,7 +95,10 @@ TIMEOUT ~a~%"
                   (find-files syslinux-dir "\\.c32$"))
 
         (unless (and (zero? (system* extlinux "--install" install-dir))
-                     (#$dd 440 1 (string-append syslinux-dir "/" #$mbr) device))
+                     (zero? (dd (string-append syslinux-dir "/" #$mbr)
+                                device
+                                #:bs 440
+                                #:count 1)))
           (error "failed to install SYSLINUX")))))
 
 (define install-extlinux-mbr
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 7391307..2ed5ddc 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2013 Andreas Enge <[email-masked]>
 ;;; Copyright © 2013 Nikita Karetnikov <[email-masked]>
 ;;; Copyright © 2015 Mark H Weaver <[email-masked]>
+;;; Copyright © 2017 Mathieu Othacehe <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -86,7 +87,8 @@
             wrap-program
             invoke
 
-            locale-category->string))
+            locale-category->string
+            dd))

 ;;;
@@ -1089,6 +1091,30 @@ returned."
              LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE
              LC_TIME)))
 
+
+;;;
+;;; dd.
+;;;
+
+(define* (dd input output #:key bs count seek (extras '()))
+  "Call dd command with provided INPUT and OUTPUT arguments. BS, COUNT, SEEK
+  and EXTRAS parameters are optional. EXTRAS is a list of string arguments to
+  be passed directly to dd."
+  (apply system* "dd"
+         (string-append "if=" input)
+         (string-append "of=" output)
+         (append
+          (if bs
+              `(,(string-append "bs=" (number->string bs)))
+              '())
+          (if count
+              `(,(string-append "count=" (number->string count)))
+              '())
+          (if seek
+              `(,(string-append "seek=" (number->string seek)))
+              '())
+          extras)))
+
 ;;; Local Variables:
 ;;; eval: (put 'call-with-output-file/atomic 'scheme-indent-function 1)
 ;;; eval: (put 'call-with-ascii-input-file 'scheme-indent-function 1)
-- 
2.7.4