diff --git a/NEWS b/NEWS index 715c1095..2d2f77d9 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.42 (???): + * Implemented issue #69 (No way to set globally a custom architecture) + A new configuration keyword "architecture" has been added to override + the native machine architecture (uname -m). + * Fixed issue #68 "xbps_binpkg_arch() asserts if arch contains a dash" https://github.com/voidlinux/xbps/issues/68 diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 01b86a36..cb77821d 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -45,7 +45,7 @@ usage(void) " Available actions:\n" " binpkgarch, binpkgver, cmpver, digest, fetch, getpkgdepname,\n" " getpkgname, getpkgrevision, getpkgversion, pkgmatch, version,\n" - " real-version.\n" + " real-version, arch.\n" "\n" " Action arguments:\n" " binpkgarch\t\n" @@ -138,6 +138,7 @@ main(int argc, char **argv) if ((strcmp(argv[0], "version") == 0) || (strcmp(argv[0], "real-version") == 0) || + (strcmp(argv[0], "arch") == 0) || (strcmp(argv[0], "fetch") == 0)) { /* * Initialize libxbps. @@ -269,6 +270,12 @@ main(int argc, char **argv) usage(); exit(xbps_cmpver(argv[1], argv[2])); + } else if (strcmp(argv[0], "arch") == 0) { + /* returns the xbps native arch */ + if (argc != 1) + usage(); + + printf("%s\n", xh.native_arch); } else if (strcmp(argv[0], "digest") == 0) { /* Prints SHA256 hashes for specified files */ if (argc < 2) diff --git a/lib/initend.c b/lib/initend.c index 99eab458..67d83dcf 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -157,7 +157,8 @@ parse_option(char *buf, char **k, char **v) "virtualpkg", "include", "preserve", - "bestmatching" + "bestmatching", + "architecture" }; bool found = false; @@ -249,6 +250,10 @@ parse_file(struct xbps_handle *xhp, const char *cwd, const char *path, bool nest xbps_dbg_printf(xhp, "%s: cachedir set to %s\n", path, v); snprintf(xhp->cachedir, sizeof(xhp->cachedir), "%s", v); + } else if (strcmp(k, "architecture") == 0) { + xbps_dbg_printf(xhp, "%s: native architecture set to %s\n", + path, v); + snprintf(xhp->native_arch, sizeof(xhp->native_arch), "%s", v); } else if (strcmp(k, "syslog") == 0) { if (strcasecmp(v, "true") == 0) { xhp->flags &= ~XBPS_FLAG_DISABLE_SYSLOG; diff --git a/tests/xbps/Kyuafile b/tests/xbps/Kyuafile index e034f94f..1572eba4 100644 --- a/tests/xbps/Kyuafile +++ b/tests/xbps/Kyuafile @@ -8,3 +8,5 @@ include('xbps-create/Kyuafile') include('xbps-install/Kyuafile') include('xbps-query/Kyuafile') include('xbps-rindex/Kyuafile') +include('xbps-uhelper/Kyuafile') + diff --git a/tests/xbps/Makefile b/tests/xbps/Makefile index d982763e..af8ae620 100644 --- a/tests/xbps/Makefile +++ b/tests/xbps/Makefile @@ -1,5 +1,5 @@ -include ../../config.mk -SUBDIRS = common libxbps xbps-checkvers xbps-create xbps-install xbps-query xbps-rindex +SUBDIRS = common libxbps xbps-checkvers xbps-create xbps-install xbps-query xbps-rindex xbps-uhelper include ../../mk/subdir.mk diff --git a/tests/xbps/xbps-uhelper/Kyuafile b/tests/xbps/xbps-uhelper/Kyuafile new file mode 100644 index 00000000..748b9d02 --- /dev/null +++ b/tests/xbps/xbps-uhelper/Kyuafile @@ -0,0 +1,4 @@ +syntax("kyuafile", 1) + +test_suite("xbps-uhelper") +atf_test_program{name="arch_test"} diff --git a/tests/xbps/xbps-uhelper/Makefile b/tests/xbps/xbps-uhelper/Makefile new file mode 100644 index 00000000..a803d19f --- /dev/null +++ b/tests/xbps/xbps-uhelper/Makefile @@ -0,0 +1,8 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TESTSHELL = arch_test +TESTSSUBDIR = xbps/xbps-uhelper +EXTRA_FILES = Kyuafile + +include $(TOPDIR)/mk/test.mk diff --git a/tests/xbps/xbps-uhelper/arch_test.sh b/tests/xbps/xbps-uhelper/arch_test.sh new file mode 100644 index 00000000..49050351 --- /dev/null +++ b/tests/xbps/xbps-uhelper/arch_test.sh @@ -0,0 +1,39 @@ +#! /usr/bin/env atf-sh +# Test that xbps-uhelper arch works as expected. + +atf_test_case native + +native_head() { + atf_set "descr" "xbps-uhelper arch: native test" +} + +native_body() { + atf_check_equal $(xbps-uhelper arch) $(uname -m) +} + +atf_test_case env + +env_head() { + atf_set "descr" "xbps-uhelper arch: envvar override test" +} +env_body() { + export XBPS_ARCH=foo + atf_check_equal $(xbps-uhelper arch) foo +} + +atf_test_case conf + +conf_head() { + atf_set "descr" "xbps-uhelper arch: configuration override test" +} +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 +} + +atf_init_test_cases() { + atf_add_test_case native + atf_add_test_case env + atf_add_test_case conf +}