From 5eddf04898b3bc1de92e9a82927c6b7b616f1edc Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 7 Mar 2013 18:08:12 +0100 Subject: [PATCH] Ignore executing install/remove scripts if XBPS_TARGET_ARCH is set. Instead a two stage approach is necessary when packages for target arch are installed: - XBPS_TARGET_ARCH=arch xbps-install foo <- only unpack - xbps-reconfigure -a <- configure natively or via an emulator --- include/xbps_api.h.in | 5 +++-- lib/initend.c | 19 +++++++------------ lib/package_script.c | 6 ++++++ lib/rindex_sync.c | 15 ++++++++++----- lib/transaction_commit.c | 8 ++++++-- lib/util.c | 36 +++++++++++++++++++++++++++++++----- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/include/xbps_api.h.in b/include/xbps_api.h.in index 62b0717b..faad492b 100644 --- a/include/xbps_api.h.in +++ b/include/xbps_api.h.in @@ -48,7 +48,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.7" -#define XBPS_API_VERSION "20130307-1" +#define XBPS_API_VERSION "20130307-2" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -544,7 +544,8 @@ struct xbps_handle { */ char *cachedir_priv; char *metadir_priv; - char *un_machine; + char *native_arch; + const char *target_arch; /* * @var repository * diff --git a/lib/initend.c b/lib/initend.c index e38edc1e..46fa3182 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -166,7 +166,6 @@ xbps_init(struct xbps_handle *xhp) struct utsname un; int rv, cc, cch; bool syslog_enabled = false; - char *tarch; assert(xhp != NULL); @@ -246,15 +245,10 @@ xbps_init(struct xbps_handle *xhp) return ENOMEM; xhp->metadir = xhp->metadir_priv; - /* Override target arch if XBPS_TARGET_ARCH is set in the environment */ - tarch = getenv("XBPS_TARGET_ARCH"); - if (tarch != NULL) { - xhp->un_machine = strdup(tarch); - } else { - uname(&un); - xhp->un_machine = strdup(un.machine); - assert(xhp->un_machine); - } + xhp->target_arch = getenv("XBPS_TARGET_ARCH"); + uname(&un); + xhp->native_arch = strdup(un.machine); + assert(xhp->native_arch); if (xhp->cfg == NULL) { xhp->flags |= XBPS_FLAG_SYSLOG; @@ -283,7 +277,8 @@ xbps_init(struct xbps_handle *xhp) xbps_dbg_printf(xhp, "FetchCacheconn=%u\n", cc); xbps_dbg_printf(xhp, "FetchCacheconnHost=%u\n", cch); xbps_dbg_printf(xhp, "Syslog=%u\n", syslog_enabled); - xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->un_machine); + xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->native_arch); + xbps_dbg_printf(xhp, "Target Architecture: %s\n", xhp->target_arch); xhp->initialized = true; @@ -307,7 +302,7 @@ xbps_end(struct xbps_handle *xhp) cfg_free(xhp->cfg); free(xhp->cachedir_priv); free(xhp->metadir_priv); - free(xhp->un_machine); + free(xhp->native_arch); xhp->initialized = false; xhp = NULL; diff --git a/lib/package_script.c b/lib/package_script.c index 66c7d839..32b5ca4f 100644 --- a/lib/package_script.c +++ b/lib/package_script.c @@ -48,6 +48,12 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, assert(pkgver); assert(action); + if (xhp->target_arch) { + xbps_dbg_printf(xhp, "%s: not executing %s " + "install/remove action.\n", pkgver, action); + return 0; + } + if (strcmp(xhp->rootdir, "/") == 0) { tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) diff --git a/lib/rindex_sync.c b/lib/rindex_sync.c index 41814eab..29027538 100644 --- a/lib/rindex_sync.c +++ b/lib/rindex_sync.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2012 Juan Romero Pardines. + * Copyright (c) 2009-2013 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -75,7 +75,7 @@ int HIDDEN xbps_rindex_sync(struct xbps_handle *xhp, const char *uri, const char *plistf) { prop_dictionary_t repod; - const char *fetchstr = NULL; + const char *arch, *fetchstr = NULL; char *rpidx, *lrepodir, *uri_fixedp, *lrepofile; int rv = 0; @@ -89,10 +89,16 @@ xbps_rindex_sync(struct xbps_handle *xhp, const char *uri, const char *plistf) uri_fixedp = xbps_get_remote_repo_string(uri); if (uri_fixedp == NULL) return -1; + + if (xhp->target_arch) + arch = xhp->target_arch; + else + arch = xhp->native_arch; + /* * Remote repository plist index full URL. */ - rpidx = xbps_xasprintf("%s/%s-%s", uri, xhp->un_machine, plistf); + rpidx = xbps_xasprintf("%s/%s-%s", uri, arch, plistf); /* * Full path to repository directory to store the plist * index file. @@ -101,8 +107,7 @@ xbps_rindex_sync(struct xbps_handle *xhp, const char *uri, const char *plistf) /* * Full path to the local repository index file. */ - lrepofile = xbps_xasprintf("%s/%s-%s", lrepodir, - xhp->un_machine, plistf); + lrepofile = xbps_xasprintf("%s/%s-%s", lrepodir, arch, plistf); /* * Create repodir in metadir. */ diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 712e31d8..dd148b05 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -296,12 +296,16 @@ xbps_transaction_commit(struct xbps_handle *xhp) goto out; } } - prop_object_iterator_reset(iter); - /* if there are no packages to install or update we are done */ if (!update && !install) goto out; + /* if installing packages for target_arch, don't configure anything */ + if (xhp->target_arch && strcmp(xhp->native_arch, xhp->target_arch)) + goto out; + + prop_object_iterator_reset(iter); + /* * Configure all unpacked packages. */ diff --git a/lib/util.c b/lib/util.c index f9c7c34e..c3da802e 100644 --- a/lib/util.c +++ b/lib/util.c @@ -175,6 +175,7 @@ get_pkg_index_remote_plist(struct xbps_handle *xhp, const char *uri, const char *plistf) { + const char *arch; char *uri_fixed, *repodir; assert(uri != NULL); @@ -183,8 +184,13 @@ get_pkg_index_remote_plist(struct xbps_handle *xhp, if (uri_fixed == NULL) return NULL; + if (xhp->target_arch) + arch = xhp->target_arch; + else + arch = xhp->native_arch; + repodir = xbps_xasprintf("%s/%s/%s-%s", xhp->metadir, - uri_fixed, xhp->un_machine, plistf); + uri_fixed, arch, plistf); free(uri_fixed); return repodir; } @@ -192,26 +198,39 @@ get_pkg_index_remote_plist(struct xbps_handle *xhp, char * xbps_pkg_index_plist(struct xbps_handle *xhp, const char *uri) { + const char *arch; + assert(xhp); assert(uri != NULL); if (xbps_repository_is_remote(uri)) return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX); - return xbps_xasprintf("%s/%s-%s", uri, xhp->un_machine, XBPS_PKGINDEX); + if (xhp->target_arch) + arch = xhp->target_arch; + else + arch = xhp->native_arch; + + return xbps_xasprintf("%s/%s-%s", uri, arch, XBPS_PKGINDEX); } char * xbps_pkg_index_files_plist(struct xbps_handle *xhp, const char *uri) { + const char *arch; + assert(xhp); assert(uri != NULL); if (xbps_repository_is_remote(uri)) return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX_FILES); - return xbps_xasprintf("%s/%s-%s", uri, - xhp->un_machine, XBPS_PKGINDEX_FILES); + if (xhp->target_arch) + arch = xhp->target_arch; + else + arch = xhp->native_arch; + + return xbps_xasprintf("%s/%s-%s", uri, arch, XBPS_PKGINDEX_FILES); } char HIDDEN * @@ -270,9 +289,16 @@ xbps_pkg_arch_match(struct xbps_handle *xhp, const char *orig, const char *target) { + const char *arch; + + if (xhp->target_arch) + arch = xhp->target_arch; + else + arch = xhp->native_arch; + if (target == NULL) { if ((strcmp(orig, "noarch") == 0) || - (strcmp(orig, xhp->un_machine) == 0)) + (strcmp(orig, arch) == 0)) return true; } else { if ((strcmp(orig, "noarch") == 0) ||