Github messages for voidlinux
 help / color / mirror / Atom feed
From: ericonr <ericonr@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: Re: [PR PATCH] [Updated] Add vtargetrun (run executables with qemu) and vcompletion (install helper for shell completions);  use them in rustup and starship
Date: Tue, 28 Jul 2020 04:43:51 +0200	[thread overview]
Message-ID: <20200728024351.Om98fy82kZKHacam0NW-VuauFzFyE8PgS1odfi-l91k@z> (raw)
In-Reply-To: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-22785@inbox.vuxu.org>

[-- Attachment #1: Type: text/plain, Size: 726 bytes --]

There is an updated pull request by ericonr against master on the void-packages repository

https://github.com/ericonr/void-packages rustup
https://github.com/void-linux/void-packages/pull/22785

Add vtargetrun (run executables with qemu) and vcompletion (install helper for shell completions);  use them in rustup and starship
Inspired by #22761 . Pinging @sgn 

Not revbumping because I don't think it's urgent. I could see the case for making this procedure part of the cargo build style, configurable with some variable like `clap_completions=yes`.

If you feel it adds too much complexity for little gain, I can close the PR.

A patch file from https://github.com/void-linux/void-packages/pull/22785.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rustup-22785.patch --]
[-- Type: text/x-diff, Size: 8855 bytes --]

From bd3f8f5d8f99c4aa3e9f6bc0e7606344ffd1dfb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89rico=20Rolim?= <erico.erc@gmail.com>
Date: Sat, 13 Jun 2020 18:45:12 -0300
Subject: [PATCH 1/4] common/environment/setup/install.sh: add vcompletion.

Install function for installing shell completions in the appropriate
place according to the shell used.
---
 Manual.md                           |  7 +++++++
 common/environment/setup/install.sh | 30 ++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/Manual.md b/Manual.md
index 5b49dc5ddd4..a2e43334b9d 100644
--- a/Manual.md
+++ b/Manual.md
@@ -337,6 +337,13 @@ The following functions are defined by `xbps-src` and can be used on any templat
 	Note that vsed will call the sed command for every regex specified against
 	every file specified, in the order that they are given.
 
+- *vcompletion()* `<file> <shell> [<command>]`
+
+	Installs shell completion from `file` for `command`, in the correct location
+	and with the appropriate filename for `shell`. If `command` isn't specified,
+	it will default to `pkgname`. The `shell` argument can be one of `bash`,
+	`fish` or `zsh`.
+
 > Shell wildcards must be properly quoted, Example: `vmove "usr/lib/*.a"`.
 
 <a id="global_vars"></a>
diff --git a/common/environment/setup/install.sh b/common/environment/setup/install.sh
index f9a1ace90e7..742f13075f8 100644
--- a/common/environment/setup/install.sh
+++ b/common/environment/setup/install.sh
@@ -13,7 +13,7 @@ _noglob_helper() {
 }
 
 # Apply _noglob to v* commands
-for cmd in vinstall vcopy vmove vmkdir vbin vman vdoc vconf vsconf vlicense vsv; do
+for cmd in vinstall vcopy vcompletion vmove vmkdir vbin vman vdoc vconf vsconf vlicense vsv; do
        alias ${cmd}="set -f; _noglob_helper _${cmd}"
 done
 
@@ -258,3 +258,31 @@ _vmkdir() {
 		install -dm${mode} ${_destdir}/${dir}
 	fi
 }
+
+_vcompletion() {
+	local file="$1" shell="$2" cmd="${3:-${pkgname}}"
+	local _bash_completion_dir=usr/share/bash-completion/completions/
+	local _fish_completion_dir=usr/share/fish/vendor_completions.d/
+	local _zsh_completion_dir=usr/share/zsh/site-functions/
+
+	if [ -z "$DESTDIR" ]; then
+		msg_red "$pkgver: vcompletion: DESTDIR unset, can't continue...\n"
+		return 1
+	fi
+
+	if [ $# -lt 2 ]; then
+		msg_red "$pkgver: vcompletion: 2 arguments expected: <file> <shell>\n"
+		return 1
+	fi
+
+	if ! [ -f "$file" ]; then
+		msg_red "$pkgver: vcompletion: file $file doesn't exist\n"
+	fi
+
+	case "$shell" in
+		bash) vinstall "$file" 0644 $_bash_completion_dir "${cmd}" ;;
+		fish) vinstall "$file" 0644 $_fish_completion_dir "${cmd}.fish" ;;
+		zsh) vinstall "$file" 0644 $_zsh_completion_dir "_${cmd}" ;;
+		*) msg_red "$pkgver: vcompletion: unknown shell ${shell}" ;;
+	esac
+}

From 727d913eb50c5bb7ddb0fb6205fdab6b8d74e0b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89rico=20Rolim?= <erico.erc@gmail.com>
Date: Sat, 13 Jun 2020 19:00:05 -0300
Subject: [PATCH 2/4] common/build-helper/qemu.sh: add vtargetrun function.

It's a function to call the qemu executable for the target arch, or a
noop if the build isn't a cross build.
---
 Manual.md                   | 4 +++-
 common/build-helper/qemu.sh | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/Manual.md b/Manual.md
index a2e43334b9d..be28d89e566 100644
--- a/Manual.md
+++ b/Manual.md
@@ -970,7 +970,9 @@ additional paths to be searched when linking target binaries to be introspected.
 - `qemu` sets additional variables for the `cmake` and `meson` build styles to allow
 executing cross-compiled binaries inside qemu.
 It sets `CMAKE_CROSSCOMPILING_EMULATOR` for cmake and `exe_wrapper` for meson
-to `qemu-<target_arch>-static` and `QEMU_LD_PREFIX` to `XBPS_CROSS_BASE`
+to `qemu-<target_arch>-static` and `QEMU_LD_PREFIX` to `XBPS_CROSS_BASE`.
+It also creates the `vtargetrun` function to wrap commands in a call to
+`qemu-<target_arch>-static` for the target architecture.
 
 - `qmake` creates the `qt.conf` configuration file (cf. `qmake` `build_style`)
 needed for cross builds and a qmake-wrapper to make `qmake` use this configuration.
diff --git a/common/build-helper/qemu.sh b/common/build-helper/qemu.sh
index f7a1839cc3e..d6a4342f5e8 100644
--- a/common/build-helper/qemu.sh
+++ b/common/build-helper/qemu.sh
@@ -4,3 +4,11 @@ if [ "$CROSS_BUILD" ]; then
 		hostmakedepends+=" qemu-user-static"
 	fi
 fi
+
+vtargetrun() {
+	if [ "$CROSS_BUILD" ]; then
+		"/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static" "$@"
+	else
+		"$@"
+	fi
+}

From dd6cdeb006f1752869eb0635c7d84700f3086a97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89rico=20Rolim?= <erico.erc@gmail.com>
Date: Thu, 11 Jun 2020 00:38:11 -0300
Subject: [PATCH 3/4] rustup: add completions for all archs.

Use qemu build_helper and vcompletion.

Completion generation is broken for armv6l-musl due to rustup not
knowing about the architecture.
---
 srcpkgs/rustup/template | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/srcpkgs/rustup/template b/srcpkgs/rustup/template
index 3cf8ccf6b78..6472ae1f10c 100644
--- a/srcpkgs/rustup/template
+++ b/srcpkgs/rustup/template
@@ -1,8 +1,9 @@
 # Template file for 'rustup'
 pkgname=rustup
 version=1.22.1
-revision=1
+revision=2
 build_style=cargo
+build_helper=qemu
 configure_args="--features no-self-update --bin rustup-init"
 hostmakedepends="pkg-config"
 makedepends="libressl-devel zlib-devel libcurl-devel"
@@ -13,19 +14,25 @@ homepage="https://www.rustup.rs"
 distfiles="https://github.com/rust-lang/${pkgname}/archive/${version}.tar.gz"
 checksum=ad46cc624f318a9493aa62fc9612a450564fe20ba93c689e0ad856bff3c64c5b
 
+post_build() {
+	# rustup errors out because it doesn't know about armv6l-musl
+	if [ "$XBPS_TARGET_MACHINE" != armv6l-musl ]; then
+		RUSTUP="target/${RUST_TARGET}/release/rustup-init"
+		ln -sf "$RUSTUP" rustup
+		# generate shell completions
+		vtargetrun ./rustup completions zsh >rustup.zsh
+		vtargetrun ./rustup completions bash >rustup.bash
+		vtargetrun ./rustup completions fish >rustup.fish
+	fi
+}
+
 do_install() {
 	vbin target/${RUST_TARGET}/release/rustup-init
 
-	if ! [ "$CROSS_BUILD" ]; then
-		# generate shell completions
-		ln -s target/${RUST_TARGET}/release/rustup-init rustup
-		./rustup completions zsh > rustup.zsh
-		./rustup completions bash > rustup.bash
-		./rustup completions fish > rustup.fish
-
-		vinstall rustup.zsh 0644 usr/share/zsh/site-functions/ _rustup
-		vinstall rustup.bash 0644 usr/share/bash-completion/completions/ rustup
-		vinstall rustup.fish 0644 usr/share/fish/vendor_completions.d/
+	if [ "$XBPS_TARGET_MACHINE" != armv6l-musl ]; then
+		vcompletion rustup.bash bash
+		vcompletion rustup.fish fish
+		vcompletion rustup.zsh zsh
 	fi
 
 	vdoc README.md

From 18ab51fa1f806349c3f715f17cadd2004b65c72a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89rico=20Rolim?= <erico.erc@gmail.com>
Date: Sat, 13 Jun 2020 18:58:48 -0300
Subject: [PATCH 4/4] starship: simplify completion generation.

Use qemu build_helper and vcompletion.
---
 srcpkgs/starship/template | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/srcpkgs/starship/template b/srcpkgs/starship/template
index b792560ff46..eb285022859 100644
--- a/srcpkgs/starship/template
+++ b/srcpkgs/starship/template
@@ -3,7 +3,7 @@ pkgname=starship
 version=0.44.0
 revision=1
 build_style=cargo
-build_helper="rust"
+build_helper=qemu
 hostmakedepends="pkg-config"
 makedepends="libgit2-devel"
 checkdepends="git"
@@ -14,9 +14,12 @@ homepage="https://starship.rs"
 distfiles="https://github.com/starship/starship/archive/v${version}.tar.gz"
 checksum=b002fa0e2b34ad59330a543461a51648751db4ae8d439d58065a3b9656772fe3
 
-if [ "$CROSS_BUILD" ]; then
-	hostmakedepends+=" qemu-user-static"
-fi
+post_build() {
+	STARSHIP="target/${RUST_TARGET}/release/starship"
+	vtargetrun ${STARSHIP} completions zsh  >starship.zsh
+	vtargetrun ${STARSHIP} completions bash >starship.bash
+	vtargetrun ${STARSHIP} completions fish >starship.fish
+}
 
 pre_check() {
 	[ -L target/debug ] && unlink target/debug
@@ -24,19 +27,9 @@ pre_check() {
 }
 
 post_install() {
-	STARSHIP="target/${RUST_TARGET}/release/starship"
-	if [ "$CROSS_BUILD" ]; then
-		export QEMU_LD_PREFIX=${XBPS_CROSS_BASE}
-		STARSHIP="/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static ${STARSHIP}"
-	fi
-
-	${STARSHIP} completions zsh  >starship.zsh
-	${STARSHIP} completions bash >starship.bash
-	${STARSHIP} completions fish >starship.fish
-
-	vinstall starship.zsh 0644 usr/share/zsh/site-functions/ _starship
-	vinstall starship.bash 0644 usr/share/bash-completion/completions/ starship
-	vinstall starship.fish 0644 usr/share/fish/vendor_completions.d/
+	vcompletion starship.bash bash
+	vcompletion starship.fish fish
+	vcompletion starship.zsh zsh
 
 	vlicense LICENSE
 }

  parent reply	other threads:[~2020-07-28  2:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-22785@inbox.vuxu.org>
2020-07-08 19:37 ` ericonr
2020-07-08 19:37 ` ericonr
2020-07-08 22:17 ` jcgruenhage
2020-07-20  3:36 ` [PR PATCH] [Updated] " ericonr
2020-07-20  4:04 ` ericonr
2020-07-20  4:45 ` ericonr
2020-07-20  5:22 ` [PR REVIEW] " fosslinux
2020-07-20  5:22 ` fosslinux
2020-07-20 13:52 ` ericonr
2020-07-20 15:26 ` ahesford
2020-07-20 15:46 ` ahesford
2020-07-20 18:51 ` [PR PATCH] [Updated] " ericonr
2020-07-20 19:06 ` [PR REVIEW] " ahesford
2020-07-20 19:12 ` ericonr
2020-07-21  2:09 ` fosslinux
2020-07-28  2:43 ` ericonr [this message]
2020-07-28  2:51 ` ericonr
2020-07-28  4:24 ` [PR PATCH] [Merged]: " sgn

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

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

  git send-email \
    --in-reply-to=20200728024351.Om98fy82kZKHacam0NW-VuauFzFyE8PgS1odfi-l91k@z \
    --to=ericonr@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /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.
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 NNTP newsgroup(s).