Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] hooks: do-extract: extract to tempdir and rename
@ 2021-09-18 14:49 sgn
  2021-09-18 14:50 ` [PR PATCH] [Updated] " sgn
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: sgn @ 2021-09-18 14:49 UTC (permalink / raw)
  To: ml

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

There is a new pull request by sgn against master on the void-packages repository

https://github.com/sgn/void-packages hooks-do-extract
https://github.com/void-linux/void-packages/pull/33013

hooks: do-extract: extract to tempdir and rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.

Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer.  The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.

In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.

---
Competing with #33006, the idea is his, anyway.

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-hooks-do-extract-33013.patch --]
[-- Type: text/x-diff, Size: 5137 bytes --]

From 6013dc74052dc84472f533ae29741654337fff52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
 <congdanhqx@gmail.com>
Date: Thu, 16 Sep 2021 22:44:43 +0700
Subject: [PATCH 1/3] R: define __MUSL__ when building for musl libc

R people assumes it's defined for musl libc.
---
 srcpkgs/R/template | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/srcpkgs/R/template b/srcpkgs/R/template
index dad0e3b00421..38ecea576b55 100644
--- a/srcpkgs/R/template
+++ b/srcpkgs/R/template
@@ -1,7 +1,7 @@
 # Template file for 'R'
 pkgname=R
 version=4.1.1
-revision=1
+revision=2
 build_style=gnu-configure
 configure_args="--docdir=/usr/share/doc/R rdocdir=/usr/share/doc/R
  --with-blas$(vopt_if openblas '=openblas') --with-lapack
@@ -37,6 +37,10 @@ case "$XBPS_TARGET_MACHINE" in
 	*) ;;
 esac
 
+if [ "$XBPS_TARGET_LIBC" = musl ]; then
+	export CPPFLAGS=-D__MUSL__
+fi
+
 pre_configure() {
 	export R_BROWSER=/usr/bin/xdg-open
 	export R_PDFVIEWER=/usr/bin/xdg-open

From 9580c20a76c7cb2d37cab4c5b11f75624346a25d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
 <congdanhqx@gmail.com>
Date: Sat, 18 Sep 2021 21:02:51 +0700
Subject: [PATCH 2/3] hooks: do-extract: simplify gem extraction

---
 common/hooks/do-extract/00-distfiles.sh | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/common/hooks/do-extract/00-distfiles.sh b/common/hooks/do-extract/00-distfiles.sh
index 922f7029491a..ca2011d5c45a 100644
--- a/common/hooks/do-extract/00-distfiles.sh
+++ b/common/hooks/do-extract/00-distfiles.sh
@@ -3,7 +3,7 @@
 
 hook() {
 	local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
-	local f j curfile found extractdir
+	local f j curfile found extractdir innerdir
 	local TAR_CMD
 
 	if [ -z "$distfiles" -a -z "$checksum" ]; then
@@ -150,16 +150,10 @@ hook() {
 			fi
 			;;
 		gem)
-			case "$TAR_CMD" in
-				*bsdtar)
-					$TAR_CMD -xOf $srcdir/$curfile data.tar.gz | \
-						$TAR_CMD -xz -C "$extractdir" -s ",^,${wrksrc##*/}/," -f -
-					;;
-				*)
-					$TAR_CMD -xOf $srcdir/$curfile data.tar.gz | \
-						$TAR_CMD -xz -C "$extractdir" --transform="s,^,${wrksrc##*/}/,"
-					;;
-			esac
+			innerdir="$extractdir/${wrksrc##*/}"
+			mkdir -p "$innerdir"
+			$TAR_CMD -xOf $srcdir/$curfile data.tar.gz |
+				$TAR_CMD -xz -C "$innerdir" -f -
 			if [ $? -ne 0 ]; then
 				msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
 			fi

From f528ca31387bfafb50b74248915923010f2858f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
 <congdanhqx@gmail.com>
Date: Sat, 18 Sep 2021 21:35:34 +0700
Subject: [PATCH 3/3] hooks: do-extract: extract to temp dir then rename

Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.

Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer.  The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.

In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
---
 common/hooks/do-extract/00-distfiles.sh | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/common/hooks/do-extract/00-distfiles.sh b/common/hooks/do-extract/00-distfiles.sh
index ca2011d5c45a..de5350c15de4 100644
--- a/common/hooks/do-extract/00-distfiles.sh
+++ b/common/hooks/do-extract/00-distfiles.sh
@@ -31,6 +31,9 @@ hook() {
 	[ -z "$TAR_CMD" ] && TAR_CMD="$(command -v tar)"
 	[ -z "$TAR_CMD" ] && msg_error "xbps-src: no suitable tar cmd (bsdtar, tar)\n"
 
+	extractdir=$(mktemp -d "$XBPS_BUILDDIR/.extractdir-XXXXXXX") ||
+		msg_error "Cannot create temporary dir for do-extract\n"
+
 	msg_normal "$pkgver: extracting distfile(s), please wait...\n"
 
 	for f in ${distfiles}; do
@@ -73,12 +76,6 @@ hook() {
 		*) msg_error "$pkgver: unknown distfile suffix for $curfile.\n";;
 		esac
 
-		if [ -n "$create_wrksrc" ]; then
-			extractdir="$wrksrc"
-		else
-			extractdir="$XBPS_BUILDDIR"
-		fi
-
 		case ${cursufx} in
 		tar|txz|tbz|tlz|tgz|crate)
 			$TAR_CMD -x --no-same-permissions --no-same-owner -f $srcdir/$curfile -C "$extractdir"
@@ -163,4 +160,17 @@ hook() {
 			;;
 		esac
 	done
+
+	# perhap below command is less magic?
+	# find "$extractdir" -mindepth 1 -maxdepth 1 -printf '1\n' | wc -l
+	shopt -s nullglob
+	set -- "$extractdir"/* "$extractdir"/.*
+	shopt -u nullglob
+	if [ $# = 3 ]; then
+		mv "$1" "$wrksrc" &&
+		rmdir "$extractdir"
+	else
+		mv "$extractdir" "$wrksrc"
+	fi ||
+		msg_error "$pkgver: failed to move sources to $wrksrc\n"
 }

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-07-06  2:13 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-18 14:49 [PR PATCH] hooks: do-extract: extract to tempdir and rename sgn
2021-09-18 14:50 ` [PR PATCH] [Updated] " sgn
2021-09-18 15:06 ` q66
2021-09-18 19:36 ` Chocimier
2021-09-19 10:07 ` [PR PATCH] [Updated] " sgn
2021-09-19 10:13 ` sgn
2021-09-19 10:17 ` sgn
2021-09-19 10:37 ` [PR PATCH] [Updated] " sgn
2021-09-19 11:01 ` sgn
2021-09-19 11:13 ` sgn
2021-09-19 11:17 ` sgn
2021-09-19 11:26 ` [PR PATCH] [Updated] " sgn
2021-09-19 11:29 ` sgn
2021-09-19 11:37 ` sgn
2021-09-19 16:27 ` [PR PATCH] [Updated] " sgn
2021-09-19 16:38 ` sgn
2022-06-22  2:13 ` github-actions
2022-07-06  2:13 ` [PR PATCH] [Closed]: " github-actions

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).