unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Ricardo Wurmus <rekado@elephly.net>
Cc: 32634@debbugs.gnu.org
Subject: [bug#32634] [PATCH 2/2] ui: Add soft port for styling and filtering build output.
Date: Mon, 10 Sep 2018 15:17:22 +0200	[thread overview]
Message-ID: <87d0tlfq59.fsf@gnu.org> (raw)
In-Reply-To: <20180904153226.17555-2-rekado@elephly.net> (Ricardo Wurmus's message of "Tue, 4 Sep 2018 17:32:27 +0200")

Hello,

Ricardo Wurmus <rekado@elephly.net> skribis:

> * guix/ui.scm (build-output-port): New procedure.
> * guix/scripts/package.scm (%default-options): Print build trace.
> (guix-package): Use build-output-port.
> * guix/scripts/build.scm (guix-build): Use build-output-port.
>
> Co-authored-by: Sahithi Yarlagadda <sahi@swecha.net>

Really nice to see this happen!

I’m late to the party but here are some comments:

> +(define* (build-output-port #:key
> +                            (colorize? #t)
> +                            verbose?
> +                            (port (current-error-port)))
> +  "Return a soft port that processes build output.  By default it colorizes
> +phase announcements and replaces any other output with a spinner."
> +  (define spun? #f)
> +  (define spin!
> +    (let ((steps (circular-list "\\" "|" "/" "-")))
> +      (lambda ()
> +        (match steps
> +          ((first . rest)
> +           (set! steps rest)
> +           (set! spun? #t) ; remember to erase spinner
> +           first)))))
> +
> +  (define use-color?
> +    (and colorize?
> +         (not (or (getenv "NO_COLOR")
> +                  (getenv "INSIDE_EMACS")
> +                  (not (isatty? port))))))

I would rather do:

  (define* (build-output-port #:key
                              (colorize? (not (or …))))
    …)

so that callers can still choose to turn it on and off.

Also, perhaps we can optimize things:

  (if (and verbose? (not colorize?))
      port
      (make-soft-port …))

> +  (define handle-string
> +    (let ((rules `(("^(@ build-started) (.*) (.*)"
> +                    #:transform
> +                    ,(lambda (m)
> +                       (string-append
> +                        (colorize-string "Building " 'BLUE 'BOLD)
> +                        (match:substring m 2) "\n")))

It think we should precompile all the regexps with ‘make-regexp’ instead
of calling ‘string-match’ (which in turn calls ‘make-regexp’) for every
line.

> +  (make-soft-port
> +   (vector
> +    ;; procedure accepting one character for output
> +    (cut write <> port)
> +    ;; procedure accepting a string for output
> +    handle-string
> +    ;; thunk for flushing output
> +    (lambda () (force-output port))
> +    ;; thunk for getting one character
> +    (const #t)

I think we should probably user ‘make-custom-binary-output-port’ instead
of ‘make-soft-port’ because it’s a cleaner and more faithful API
(‘make-soft-port’ no longer matches the operations implemented by port
types.)

The brings the issue of how to properly decode build output.  Commit
ce72c780746776a86f59747f5eff8731cb4ff39b fixes issues in this area.  I
wrote the tests below to see how ‘build-output-port’ behaves when passed
valid UTF-8 and garbage, and it appears to behave correctly, though the
question mark that we get in return when throwing garbage at it suggests
that decoding substitution is not happening where it should.

If we use a custom-binary-output-port, we’ll have to do something
similar to what ‘read-maybe-utf8-string’, and that way we’ll be fully in
control.

> +    ;; thunk for closing port (not by garbage collection)
> +    (lambda () (close port)))

At call sites, we should probably do:

  (build-output-port #:port (duplicate-port (current-error-port)))

instead of just:

  (build-output-port)

so that stderr doesn’t get closed.

Thoughts?

Thanks!

Ludo’.

  parent reply	other threads:[~2018-09-10 13:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-04 15:29 [bug#32634] RFC: Process build output Ricardo Wurmus
2018-09-04 15:32 ` [bug#32634] [PATCH 1/2] ui: Add support for colorization Ricardo Wurmus
2018-09-04 15:32   ` [bug#32634] [PATCH 2/2] ui: Add soft port for styling and filtering build output Ricardo Wurmus
2018-09-08  9:49     ` Danny Milosavljevic
2018-09-09 21:22       ` bug#32634: " Ricardo Wurmus
2018-09-10 13:17     ` Ludovic Courtès [this message]
2018-09-10 14:28       ` [bug#32634] " Ludovic Courtès
2018-09-08  8:32   ` [bug#32634] [PATCH 1/2] ui: Add support for colorization Danny Milosavljevic
2018-09-08 16:11 ` [bug#32634] RFC: Process build output Nils Gillmann
2018-09-08 16:58   ` Tobias Geerinckx-Rice
2018-09-08 17:03   ` Tobias Geerinckx-Rice
2018-09-09 12:32 ` Danny Milosavljevic
2018-09-09 16:26   ` Ricardo Wurmus
2018-09-10 14:39 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d0tlfq59.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=32634@debbugs.gnu.org \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).