return 0;
}
-int pakfire_arch_supported_by_host(const char* name) {
- if (!name)
- return -EINVAL;
+/*
+ This function figures out which architecture the build environment has -
+ which might not be the same as the requested architecture.
+*/
+const char* pakfire_arch_supported_by_host(const char* name) {
+ if (!name) {
+ errno = EINVAL;
+ return NULL;
+ }
const char* native_arch = pakfire_arch_native();
+ // All hosts support noarch natively
+ if (strcmp(name, "noarch") == 0)
+ return native_arch;
+
// Check if those two architectures are compatible
- return pakfire_arch_is_compatible(native_arch, name);
+ if (pakfire_arch_is_compatible(native_arch, name))
+ return name;
+
+ // Not supported
+ errno = ENOTSUP;
+ return NULL;
}
static char* find_interpreter(DIR* dir, const char* path, const char* magic) {
if (r)
return 1;
- const char* arch = pakfire_get_arch(db->pakfire);
+ const char* arch = pakfire_get_effective_arch(db->pakfire);
// Set architecture
r = pakfire_db_set_string(db, "arch", arch);
}
// Fetch the running architecture
- const char* arch = pakfire_get_arch(db->pakfire);
+ const char* arch = pakfire_get_effective_arch(db->pakfire);
if (!arch)
goto ERROR;
pakfire_parser_set(parser, NULL, "DISTRO_VENDOR", vendor, 0);
// Set DISTRO_ARCH
- const char* arch = pakfire_get_arch(pakfire);
- if (arch) {
- pakfire_parser_set(parser, NULL, "DISTRO_ARCH", arch, 0);
+ const char* effective_arch = pakfire_get_effective_arch(pakfire);
+ if (effective_arch) {
+ pakfire_parser_set(parser, NULL, "DISTRO_ARCH", effective_arch, 0);
- const char* platform = pakfire_arch_platform(arch);
+ const char* platform = pakfire_arch_platform(effective_arch);
if (platform)
pakfire_parser_set(parser, NULL, "DISTRO_PLATFORM", platform, 0);
if (vendor) {
// Set DISTRO_MACHINE
- r = pakfire_arch_machine(buffer, arch, vendor);
+ r = pakfire_arch_machine(buffer, effective_arch, vendor);
if (!r)
pakfire_parser_set(parser, NULL, "DISTRO_MACHINE", buffer, 0);
// Set DISTRO_BUILDTARGET
- r = pakfire_arch_buildtarget(buffer, arch, vendor);
+ r = pakfire_arch_buildtarget(buffer, effective_arch, vendor);
if (!r)
pakfire_parser_set(parser, NULL, "DISTRO_BUILDTARGET", buffer, 0);
}
const char* pakfire_arch_platform(const char* name);
int pakfire_arch_is_compatible(const char* name, const char* compatible_arch);
-int pakfire_arch_supported_by_host(const char* name);
+const char* pakfire_arch_supported_by_host(const char* name);
char* pakfire_arch_find_interpreter(const char* name);
#endif
#include <pakfire/config.h>
#include <pakfire/pwd.h>
+const char* pakfire_get_effective_arch(struct pakfire* pakfire);
+
int pakfire_on_root(struct pakfire* pakfire);
uid_t pakfire_uid(struct pakfire* pakfire);
PAKFIRE_EXPORT int pakfire_jail_create(struct pakfire_jail** jail, struct pakfire* pakfire) {
int r;
- const char* arch = pakfire_get_arch(pakfire);
+ const char* arch = pakfire_get_effective_arch(pakfire);
// Allocate a new jail
struct pakfire_jail* j = calloc(1, sizeof(*j));
}
const char* root = pakfire_get_path(jail->pakfire);
- const char* arch = pakfire_get_arch(jail->pakfire);
+ const char* arch = pakfire_get_effective_arch(jail->pakfire);
// Change mount propagation to slave to receive anything from the parent namespace
r = pakfire_mount_change_propagation(jail->pakfire, MS_SLAVE, "/");
char target[PATH_MAX];
// Fetch the target architecture
- const char* arch = pakfire_get_arch(pakfire);
+ const char* arch = pakfire_get_effective_arch(pakfire);
// Can we emulate this architecture?
char* interpreter = pakfire_arch_find_interpreter(arch);
char path[PATH_MAX];
char lock_path[PATH_MAX];
char cache_path[PATH_MAX];
- char arch[ARCH_MAX];
+
+ struct pakfire_arches {
+ char nominal[ARCH_MAX];
+ const char* effective;
+ } arches;
int flags;
struct pakfire_repo* system = NULL;
int r;
+ const char* arch = pakfire_get_effective_arch(pakfire);
+
// Initialize the pool
Pool* pool = pakfire->pool = pool_create();
pool_setdisttype(pool, DISTTYPE_RPM);
#endif
// Set architecture of the pool
- pool_setarch(pool, pakfire->arch);
+ pool_setarch(pool, arch);
// Set path
pool_set_rootdir(pool, pakfire->path);
char basepath[PATH_MAX];
int r;
+ const char* arch = pakfire_get_effective_arch(pakfire);
+
// Fetch the path from the configuration file
const char* path = pakfire_config_get(pakfire->config, "general", "cache_path", NULL);
if (!path) {
// Format the final path
return pakfire_string_format(pakfire->cache_path, "%s/%s/%s/%s",
- path, pakfire->distro.id, pakfire->distro.version_id, pakfire->arch);
+ path, pakfire->distro.id, pakfire->distro.version_id, arch);
}
static int pakfire_setup_user(struct pakfire* pakfire) {
pakfire_log_set_priority(p, log_priority(env));
}
- // Check if the architecture is supported by this host
- if (!pakfire_arch_supported_by_host(arch)) {
+ // Store the nominal architecture
+ r = pakfire_string_set(p->arches.nominal, arch);
+ if (r)
+ goto ERROR;
+
+ // Determine the effective architecture
+ p->arches.effective = pakfire_arch_supported_by_host(arch);
+ if (!p->arches.effective) {
ERROR(p, "Unsupported architecture: %s\n", arch);
- r = -EINVAL;
+ r = errno;
goto ERROR;
}
- // Set architecture
- pakfire_string_set(p->arch, arch);
-
// Path must be absolute
if (path && !pakfire_string_startswith(path, "/")) {
ERROR(p, "Invalid path: %s\n", path);
DEBUG(p, "Pakfire initialized at %p\n", p);
DEBUG(p, " user = %s (%d)\n", p->user.name, p->user.uid);
DEBUG(p, " group = %s (%d)\n", p->group.name, p->group.gid);
- DEBUG(p, " arch = %s\n", pakfire_get_arch(p));
+ DEBUG(p, " arch = %s (%s)\n", pakfire_get_arch(p), pakfire_get_effective_arch(p));
DEBUG(p, " path = %s\n", pakfire_get_path(p));
if (p->user.subuids.id)
DEBUG(p, " subuid = %d (%zu)\n", p->user.subuids.id, p->user.subuids.length);
}
PAKFIRE_EXPORT const char* pakfire_get_arch(struct pakfire* pakfire) {
- return pakfire->arch;
+ return pakfire->arches.nominal;
+}
+
+const char* pakfire_get_effective_arch(struct pakfire* pakfire) {
+ return pakfire->arches.effective;
}
PAKFIRE_EXPORT int pakfire_version_compare(struct pakfire* pakfire, const char* evr1, const char* evr2) {
const char* replacement;
} replacements[] = {
{ "%{name}", pakfire_repo_get_name(repo) },
- { "%{arch}", pakfire_get_arch(repo->pakfire) },
+ { "%{arch}", pakfire_get_effective_arch(repo->pakfire) },
{ "%{distro}", pakfire_get_distro_id(repo->pakfire) },
{ "%{version}", pakfire_get_distro_version_id(repo->pakfire) },
{ NULL, NULL },