Message ID | 20220910214721.9993-1-mike@rohleder.de |
---|---|
State | Accepted |
Headers | show |
Series | [bug#57722] gnu: ipfs: Install bash completion. | expand |
Context | Check | Description |
---|---|---|
cbaines/comparison | success | View comparision |
cbaines/git-branch | success | View Git branch |
cbaines/applying patch | success | View Laminar job |
cbaines/issue | success | View issue |
On 10-09-2022 23:47, Michael Rohleder wrote: > + (lambda* (#:key inputs outputs #:allow-other-keys) 'inputs' is unused. > + (let* ((out (assoc-ref outputs "out")) > + (completiondir (string-append out "/etc/bash_completion.d"))) #$output can be used nowadays instead of (assoc-ref outputs "out"). Then 'outputs' would be unused as well and the lambda can be simplified to (lambda _ [...]). > + (mkdir-p completiondir) > + (call-with-output-file (string-append completiondir "/ipfs") > + (lambda (port) > + (let ((input-pipe (open-pipe* OPEN_READ > + (string-append out "/bin/ipfs") > + "commands" "completion" "bash"))) > + (display (get-string-all input-pipe) port) > + (close-pipe input-pipe)))))))))) Can be simplified to (with-output-to-file (string-append completiondir "/ipfs") (invoke (string-append out "/bin/ipfs") "commands" "completion" "bash")) (untested) When cross-compiling, the cross-compiled bin/ipfs cannot be run. To solve this, you can add 'this-package' to the native-inputs conditional upon (%current-target-system): (native-inputs (append (if (%current-target-system) (list this-package) '()) (list python-minimal-wrapper zsh))). and in the build phase, do two separate cases: when compiling natively, use the ipfs from #$output as you're doing, when cross-compiling, use the ipfs from $PATH: (with-output-to-file (string-append completiondir "/ipfs") (invoke #$(if (%current-target-system) "ipfs" #~(string-append #$output "/bin/ipfs")) "commands" "completion" "bash")) Greetings, Maxime.
On 11-09-2022 13:47, Maxime Devos wrote: > > and in the build phase, do two separate cases: when compiling natively, > use the ipfs from #$output as you're doing, when cross-compiling, use > the ipfs from $PATH: > > (with-output-to-file (string-append completiondir "/ipfs") > (invoke #$(if (%current-target-system) > "ipfs" > #~(string-append #$output "/bin/ipfs")) > "commands" "completion" "bash")) > Oops that incorrect, with-output-to-file is not a macro but a procedure accepting a thunk, try (with-output-to-file [...] (lambda () (invoke ...))) instead.
diff --git a/gnu/packages/ipfs.scm b/gnu/packages/ipfs.scm index ccc36007b4..faa209bf2a 100644 --- a/gnu/packages/ipfs.scm +++ b/gnu/packages/ipfs.scm @@ -2,7 +2,7 @@ ;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz> ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr> ;;; Copyright © 2019, 2020 Martin Becze <mjbecze@riseup.net> -;;; Copyright © 2020, 2021 Michael Rohleder <mike@rohleder.de> +;;; Copyright © 2020, 2021, 2022 Michael Rohleder <mike@rohleder.de> ;;; ;;; This file is part of GNU Guix. ;;; @@ -230,7 +230,26 @@ (define-public go-ipfs (build-system go-build-system) (arguments `(#:unpack-path "github.com/ipfs/go-ipfs" - #:import-path "github.com/ipfs/go-ipfs/cmd/ipfs")) + #:import-path "github.com/ipfs/go-ipfs/cmd/ipfs" + #:modules ((guix build utils) + (guix build go-build-system) + (ice-9 popen) + (ice-9 textual-ports)) + #:phases + (modify-phases %standard-phases + ;; https://github.com/ipfs/kubo/blob/master/docs/command-completion.md + (add-after 'install 'install-bashcompletion + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (completiondir (string-append out "/etc/bash_completion.d"))) + (mkdir-p completiondir) + (call-with-output-file (string-append completiondir "/ipfs") + (lambda (port) + (let ((input-pipe (open-pipe* OPEN_READ + (string-append out "/bin/ipfs") + "commands" "completion" "bash"))) + (display (get-string-all input-pipe) port) + (close-pipe input-pipe)))))))))) (native-inputs (list python-minimal-wrapper zsh)) (home-page "https://ipfs.io")