From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1338123-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 53A1A158086
	for <garchives@archives.gentoo.org>; Wed, 10 Nov 2021 03:32:45 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 53CAF2BC020;
	Wed, 10 Nov 2021 03:32:44 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id BE2522BC020
	for <gentoo-commits@lists.gentoo.org>; Wed, 10 Nov 2021 03:32:43 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 500F5342D88
	for <gentoo-commits@lists.gentoo.org>; Wed, 10 Nov 2021 03:32:42 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 88DBF18E
	for <gentoo-commits@lists.gentoo.org>; Wed, 10 Nov 2021 03:32:40 +0000 (UTC)
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" <sam@gentoo.org>
Message-ID: <1636515145.a4957cb794dce725b4801ee16a36f38526bdce2d.sam@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-libs/musl/
X-VCS-Repository: repo/gentoo
X-VCS-Files: sys-libs/musl/musl-1.2.2-r4.ebuild sys-libs/musl/musl-9999.ebuild
X-VCS-Directories: sys-libs/musl/
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: a4957cb794dce725b4801ee16a36f38526bdce2d
X-VCS-Branch: master
Date: Wed, 10 Nov 2021 03:32:40 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 6cc38fcf-0aed-4ce8-b4e7-bde9ecb3f826
X-Archives-Hash: 805c33783a0a6eb11340305b30656cd0

commit:     a4957cb794dce725b4801ee16a36f38526bdce2d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Nov 10 03:31:26 2021 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Nov 10 03:32:25 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a4957cb7

sys-libs/musl: create relative symlink to libc.so if existing one fails

The build system seems to create an absolute symlink to libc.so on
the host which may not exist.

If it doesn't (to avoid being disruptive, we could do this unconditionally),
create a new one relative within ${D} to facilitate SYSROOT installs.

I've hit this a few times when using crossdev but finally dug into it
a bit more.

Bug: https://bugs.gentoo.org/732482
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../{musl-9999.ebuild => musl-1.2.2-r4.ebuild}     | 27 ++++++++++++++++++++--
 sys-libs/musl/musl-9999.ebuild                     | 20 ++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/sys-libs/musl/musl-9999.ebuild b/sys-libs/musl/musl-1.2.2-r4.ebuild
similarity index 81%
copy from sys-libs/musl/musl-9999.ebuild
copy to sys-libs/musl/musl-1.2.2-r4.ebuild
index 56a2bbbc42f..0fe2c8c9a67 100644
--- a/sys-libs/musl/musl-9999.ebuild
+++ b/sys-libs/musl/musl-1.2.2-r4.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=7
 
-inherit flag-o-matic toolchain-funcs
+inherit eapi8-dosym flag-o-matic toolchain-funcs
 if [[ ${PV} == "9999" ]] ; then
 	EGIT_REPO_URI="git://git.musl-libc.org/musl"
 	inherit git-r3
@@ -71,6 +71,13 @@ src_unpack() {
 	cp "${DISTDIR}"/iconv.c misc/iconv.c || die
 }
 
+src_prepare() {
+	default
+
+	# Expand gethostid instead of being just a stub
+	eapply "${FILESDIR}/${PN}-1.2.2-gethostid.patch"
+}
+
 src_configure() {
 	tc-getCC ${CTARGET}
 	just_headers && export CC=true
@@ -120,7 +127,23 @@ src_install() {
 		#   SUBARCH = ...
 		# and print $(ARCH)$(SUBARCH).
 		local arch=$(awk '{ k[$1] = $3 } END { printf("%s%s", k["ARCH"], k["SUBARCH"]); }' config.mak)
-		[[ -e "${D}"/lib/ld-musl-${arch}.so.1 ]] || die
+
+		if [[ ! -e "${D}"/lib/ld-musl-${arch}.so.1 ]] ; then
+			# During cross (using crossdev), when emerging sys-libs/musl,
+			# if /usr/lib/libc.so.1 doesn't exist on the system, installation
+			# would fail.
+			#
+			# The musl build system seems to create a symlink:
+			# ${D}/lib/ld-musl-${arch}.so.1 -> /usr/lib/libc.so.1 (absolute)
+			# During cross, there's no guarantee that the host is using musl
+			# so that file may not exist. Use a relative symlink within ${D}
+			# instead.
+			dosym8 -r /usr/lib/libc.so.1 /lib/ld-musl-${arch}.so.1
+
+			# If it's still a dead symlnk, OK, we really do need to abort.
+			[[ -e "${D}"/lib/ld-musl-${arch}.so.1 ]] || die
+		fi
+
 		cp "${FILESDIR}"/ldconfig.in "${T}" || die
 		sed -e "s|@@ARCH@@|${arch}|" "${T}"/ldconfig.in > "${T}"/ldconfig || die
 		into /

diff --git a/sys-libs/musl/musl-9999.ebuild b/sys-libs/musl/musl-9999.ebuild
index 56a2bbbc42f..5736eadc0fb 100644
--- a/sys-libs/musl/musl-9999.ebuild
+++ b/sys-libs/musl/musl-9999.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=7
 
-inherit flag-o-matic toolchain-funcs
+inherit eapi8-dosym flag-o-matic toolchain-funcs
 if [[ ${PV} == "9999" ]] ; then
 	EGIT_REPO_URI="git://git.musl-libc.org/musl"
 	inherit git-r3
@@ -120,7 +120,23 @@ src_install() {
 		#   SUBARCH = ...
 		# and print $(ARCH)$(SUBARCH).
 		local arch=$(awk '{ k[$1] = $3 } END { printf("%s%s", k["ARCH"], k["SUBARCH"]); }' config.mak)
-		[[ -e "${D}"/lib/ld-musl-${arch}.so.1 ]] || die
+
+		if [[ ! -e "${D}"/lib/ld-musl-${arch}.so.1 ]] ; then
+			# During cross (using crossdev), when emerging sys-libs/musl,
+			# if /usr/lib/libc.so.1 doesn't exist on the system, installation
+			# would fail.
+			#
+			# The musl build system seems to create a symlink:
+			# ${D}/lib/ld-musl-${arch}.so.1 -> /usr/lib/libc.so.1 (absolute)
+			# During cross, there's no guarantee that the host is using musl
+			# so that file may not exist. Use a relative symlink within ${D}
+			# instead.
+			dosym8 -r /usr/lib/libc.so.1 /lib/ld-musl-${arch}.so.1
+
+			# If it's still a dead symlnk, OK, we really do need to abort.
+			[[ -e "${D}"/lib/ld-musl-${arch}.so.1 ]] || die
+		fi
+
 		cp "${FILESDIR}"/ldconfig.in "${T}" || die
 		sed -e "s|@@ARCH@@|${arch}|" "${T}"/ldconfig.in > "${T}"/ldconfig || die
 		into /