From 7f75fd840a15f24a8a88ec1dbd568a3c1ceea133 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 27 Dec 2019 16:14:07 +0100 Subject: [PATCH] xbps_init: autodetect musl libc variant at compile time. This way we don't need to set the 'architecture' xbps.d setting when the binaries are compiled for musl. Close #195 --- lib/initend.c | 10 ++++++++++ tests/xbps/libxbps/shell/scripts_test.sh | 2 +- tests/xbps/xbps-uhelper/arch_test.sh | 11 ++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/initend.c b/lib/initend.c index a06a4f1e..5efb21e2 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -107,10 +107,20 @@ xbps_init(struct xbps_handle *xhp) if ((native_arch = getenv("XBPS_ARCH")) != NULL) { xbps_strlcpy(xhp->native_arch, native_arch, sizeof (xhp->native_arch)); } else { + char *s = NULL; struct utsname un; if (uname(&un) == -1) return ENOTSUP; +#if defined(__linux__) && !defined(__GLIBC__) + /* musl libc on linux */ + s = xbps_xasprintf("%s-musl", un.machine); + assert(s); + xbps_strlcpy(xhp->native_arch, s, sizeof(xhp->native_arch)); + free(s); +#else + /* glibc or any other os */ xbps_strlcpy(xhp->native_arch, un.machine, sizeof (xhp->native_arch)); +#endif } assert(xhp->native_arch); diff --git a/tests/xbps/libxbps/shell/scripts_test.sh b/tests/xbps/libxbps/shell/scripts_test.sh index 9c6763d5..862e30ec 100644 --- a/tests/xbps/libxbps/shell/scripts_test.sh +++ b/tests/xbps/libxbps/shell/scripts_test.sh @@ -41,7 +41,7 @@ script_nargs_body() { rval=0 xbps-reconfigure -C empty.conf -r root -f A 2>out out="$(cat out)" - expected="post A 1.0_1 no no $(uname -m)" + expected="post A 1.0_1 no no $(xbps-uhelper arch)" if [ "$out" != "$expected" ]; then echo "out: '$out'" echo "expected: '$expected'" diff --git a/tests/xbps/xbps-uhelper/arch_test.sh b/tests/xbps/xbps-uhelper/arch_test.sh index 49050351..d378a310 100644 --- a/tests/xbps/xbps-uhelper/arch_test.sh +++ b/tests/xbps/xbps-uhelper/arch_test.sh @@ -8,7 +8,12 @@ native_head() { } native_body() { - atf_check_equal $(xbps-uhelper arch) $(uname -m) + if $(ldd --version 2>&1|head -1|grep -q musl); then + arch=$(uname -m)-musl + else + arch=$(uname -m) + fi + atf_check_equal $(xbps-uhelper arch) $arch } atf_test_case env @@ -28,8 +33,8 @@ conf_head() { } conf_body() { mkdir -p xbps.d - echo "architecture=x86_64-musl" > xbps.d/arch.conf - atf_check_equal $(xbps-uhelper -C $PWD/xbps.d arch) x86_64-musl + echo "architecture=NULL" > xbps.d/arch.conf + atf_check_equal $(xbps-uhelper -C $PWD/xbps.d arch) NULL } atf_init_test_cases() {