[PATCH core-updates] utils: Add helper method to invoke programs.

  • Done
  • quality assurance status badge
Details
2 participants
  • Danny Milosavljevic
  • Ludovic Courtès
Owner
unassigned
Submitted by
Danny Milosavljevic
Severity
normal

Debbugs page

Danny Milosavljevic wrote 8 years ago
(address . guix-patches@gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20170601072207.27718-1-dannym@scratchpost.org
* guix/build/utils.scm (invoke): New variable.
---
guix/build/utils.scm | 8 ++++++++
1 file changed, 8 insertions(+)

Toggle diff (26 lines)
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 6d3c29d00..b2307d9d6 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -84,6 +84,7 @@
fold-port-matches
remove-store-references
wrap-program
+ invoke
locale-category->string))
@@ -1058,6 +1059,13 @@ with definitions for VARS."
(chmod prog-tmp #o755)
(rename-file prog-tmp prog))))
+(define invoke
+ "Invokes the program (array-ref ARGS 0) and gives it ARGS.
+ If the exit code is non-zero, raises an error."
+ (lambda args
+ (if (not (zero? (system* args)))
+ (error (format #f "Failed to invoke ~a" args)))))
+
;;;
;;; Locales.
Ludovic Courtès wrote 8 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 27180@debbugs.gnu.org)
87shjjzz1q.fsf@gnu.org
Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (28 lines)
> * guix/build/utils.scm (invoke): New variable.
> ---
> guix/build/utils.scm | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/guix/build/utils.scm b/guix/build/utils.scm
> index 6d3c29d00..b2307d9d6 100644
> --- a/guix/build/utils.scm
> +++ b/guix/build/utils.scm
> @@ -84,6 +84,7 @@
> fold-port-matches
> remove-store-references
> wrap-program
> + invoke
>
> locale-category->string))
>
> @@ -1058,6 +1059,13 @@ with definitions for VARS."
> (chmod prog-tmp #o755)
> (rename-file prog-tmp prog))))
>
> +(define invoke
> + "Invokes the program (array-ref ARGS 0) and gives it ARGS.
> + If the exit code is non-zero, raises an error."
> + (lambda args
> + (if (not (zero? (system* args)))
> + (error (format #f "Failed to invoke ~a" args)))))

Good idea. I would suggest writing it this way though:

(define (invoke program . args)
"Invoke PROGRAM with the given ARGS. Raise an error if the exit
code is non-zero; otherwise return #t."
(let ((status (apply system* program args)))
(unless (zero? status)
(error (format #f "program ~s exited with non-zero code" program)
status))
#t))

If that’s fine with you, please push to ‘core-updates’. (Just in time!)

Thanks,
Ludo’.
Danny Milosavljevic wrote 8 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 27180-done@debbugs.gnu.org)
20170601190900.75571862@scratchpost.org
Good idea to end it with #t :)

Pushed your variant as 3f65c190d23296e7e718c3deff413e8beb61d8ba to core-updates.
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 27180@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 27180
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help