Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
arch-indep detection take two. work in progress
Matthew Seaman committed 13 years ago
commit c4f611cda8a22e34dc6edee1b2e3cda3dfcf023a
parent e72db04
6 files changed +80 -49
modified libpkg/pkg.c
@@ -176,15 +176,6 @@ pkg_is_valid(struct pkg *pkg)
	return (EPKG_OK);
}

-
int
-
pkg_is_arch_indep(struct pkg *pkg)
-
{
-
	if (pkg->flags & PKG_CONTAINS_ARCH_DEP)
-
		return EPKG_FATAL;
-
	else
-
		return EPKG_OK;
-
}
-

static int
pkg_vget(struct pkg const *const pkg, va_list ap)
{
modified libpkg/pkg.h
@@ -257,7 +257,6 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_AUTODEPS = 12,
	PKG_CONFIG_ABI = 13,
	PKG_CONFIG_DEVELOPER_MODE = 14,
-
	PKG_CONFIG_ARCH_INDEP = 15,
} pkg_config_key;

typedef enum {
@@ -328,11 +327,6 @@ void pkg_free(struct pkg *);
int pkg_is_valid(struct pkg *);

/**
-
 * Check if a package is marked architecture independent
-
 */
-
int pkg_is_arch_indep(struct pkg *);
-

-
/**
 * Open a package file archive and retrive informations.
 * @param p A pointer to pkg allocated by pkg_new(), or if it points to a
 * NULL pointer, the function allocate a new pkg using pkg_new().
@@ -442,9 +436,19 @@ int pkg_shlibs(struct pkg *pkg, struct pkg_shlib **shlib);
 * @return An error code
 */

-
#define PKG_CONTAINS_ARCH_DEP (1<<24) /* Don't conflict with PKG_LOAD_* q.v. */
+
 /* Don't conflict with PKG_LOAD_* q.v. */
+
#define PKG_CONTAINS_ELF_OBJECTS (1<<24)
+
#define PKG_CONTAINS_STATIC_LIBS (1<<25)
+
#define PKG_CONTAINS_H_OR_LA (1<<26)

int pkg_analyse_files(struct pkgdb *, struct pkg *);
+

+
/**
+
 * Suggest if a package could be marked architecture independent or
+
 * not.
+
 */
+
int pkg_suggest_arch(struct pkg *, const char *);
+

/**
 * Generic setter for simple attributes.
 */
modified libpkg/pkg_config.c
@@ -151,12 +151,6 @@ static struct config_entry c[] = {
		"DEVELOPER_MODE",
		"NO",
		{ NULL }
-
	},
-
	[PKG_CONFIG_ARCH_INDEP] = {
-
		BOOL,
-
		"ARCH_INDEP",
-
		"NO",
-
		{ NULL }
	}
};

modified libpkg/pkg_elf.c
@@ -132,11 +132,11 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)

	bool shlibs = false;
	bool autodeps = false;
-
	bool arch_indep = false;
+
	bool developer = false;

	pkg_config_bool(PKG_CONFIG_AUTODEPS, &autodeps);
	pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs);
-
	pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &arch_indep);
+
	pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &developer);

	int fd;

@@ -162,8 +162,8 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
		return (EPKG_END); /* Not an elf file: no results */
	}

-
	if (arch_indep)
-
		pkg->flags |= PKG_CONTAINS_ARCH_DEP;
+
	if (developer)
+
		pkg->flags |= PKG_CONTAINS_ELF_OBJECTS;

	if (!autodeps && !shlibs) {
	   ret = EPKG_OK;
@@ -242,32 +242,63 @@ cleanup:
	return (ret);
}

+
static int
+
analyse_fpath(struct pkg *pkg, const char *fpath)
+
{
+
	const char *dot;
+

+
	dot = strrchr(fpath, '.');
+

+
	if (dot == NULL)	/* No extension */
+
		return (EPKG_OK);
+

+
	if (dot[1] == 'a' && dot[2] == '\0')
+
		pkg->flags |= PKG_CONTAINS_STATIC_LIBS;
+

+
	if ((dot[1] == 'l' && dot[2] == 'a' && dot[3] == '\0') ||
+
	    (dot[1] == 'h' && dot[2] == '\0'))
+
		pkg->flags |= PKG_CONTAINS_H_OR_LA;
+

+
	return (EPKG_OK);
+
}
+

int
pkg_analyse_files(struct pkgdb *db, struct pkg *pkg)
{
	struct pkg_file *file = NULL;
	int ret = EPKG_OK;
+
	const char *fpath;
	bool shlibs = false;
	bool autodeps = false;
-
	bool arch_indep = false;
+
	bool developer = false;

	pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs);
	pkg_config_bool(PKG_CONFIG_AUTODEPS, &autodeps);
-
	pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &arch_indep);
+
	pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &developer);

-
	if (!autodeps && !shlibs && !arch_indep)
+
	if (!autodeps && !shlibs && !developer)
		return (EPKG_OK);

	if (elf_version(EV_CURRENT) == EV_NONE)
		return (EPKG_FATAL);

-
	if (arch_indep)
-
		pkg->flags &= ~PKG_CONTAINS_ARCH_DEP; /* Assume no architecture dependence, for contradiction */
-

-
	while (pkg_files(pkg, &file) == EPKG_OK)
-
		analyse_elf(db, pkg, pkg_file_get(file, PKG_FILE_PATH));
+
	/* Assume no architecture dependence, for contradiction */
+
	if (developer)
+
		pkg->flags &= ~(PKG_CONTAINS_ELF_OBJECTS |
+
				PKG_CONTAINS_STATIC_LIBS |
+
				PKG_CONTAINS_H_OR_LA);
+

+
	while (pkg_files(pkg, &file) == EPKG_OK) {
+
		fpath = pkg_file_get(file, PKG_FILE_PATH);
+
		ret = analyse_elf(db, pkg, fpath);
+
		if (developer) {
+
			if ( ret != EPKG_OK && ret != EPKG_END )
+
				return (ret);
+
			analyse_fpath(pkg, fpath);
+
		}
+
	}

-
	return (ret);
+
	return (EPKG_OK);
}

static const char *
@@ -425,3 +456,21 @@ pkg_get_myarch_indep(char *dest, size_t sz)
{
	return (get_myarch(dest, sz, true));
}
+

+
int
+
pkg_suggest_arch(struct pkg *pkg, const char *arch)
+
{
+
	if (pkg->flags & (PKG_CONTAINS_ELF_OBJECTS|PKG_CONTAINS_STATIC_LIBS)) {
+
		/* Definitely has to be arch specific */
+
		pkg_emit_error("Package installs architecture specific files");
+
	} else {
+
		if (pkg->flags & PKG_CONTAINS_H_OR_LA) {
+
			/* Could well be arch specific */
+
			pkg_emit_error("Warning: package installs C/C++ headers or libtool library files, which are frequently architecture specific.");
+
		} else {
+
			/* Might be arch independent */
+
			pkg_emit_error("No architecture specific files found (which doesn't mean there aren't any) -- test before marking as architecture independent");
+
		}
+
	}
+
	return (EPKG_OK);
+
}
modified pkg/main.c
@@ -266,8 +266,6 @@ main(int argc, char **argv)
			printf("Custom keywords directory: %s\n", buf ? buf : "none");
			pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &b);
			printf("Developer mode: %s\n", b ? "yes" : "no");
-
			pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &b);
-
			printf("Detect achitecture independence: %s\n", b ? "yes" : "no");
		}
		pkg_config_bool(PKG_CONFIG_MULTIREPOS, &b);
		if (b) {
modified pkg/register.c
@@ -93,7 +93,7 @@ exec_register(int argc, char **argv)
	size_t size;

	bool legacy = false;
-
	bool arch_indep = false;
+
	bool developer = false;

	int i;
	int ret = EPKG_OK, retcode = EPKG_OK;
@@ -103,6 +103,8 @@ exec_register(int argc, char **argv)
		return (EX_NOPERM);
	}

+
	pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &developer);
+

	pkg_new(&pkg, PKG_INSTALLED);
	while ((ch = getopt(argc, argv, "a:f:m:i:ld")) != -1) {
		switch (ch) {
@@ -139,8 +141,6 @@ exec_register(int argc, char **argv)
	if (plist == NULL)
		errx(EX_USAGE, "missing -f flag");

-
	pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &arch_indep);
-

	if (mdir == NULL)
		errx(EX_USAGE, "missing -m flag");

@@ -203,22 +203,17 @@ exec_register(int argc, char **argv)
		/*
		 * do not take the one from configuration on purpose
		 * but the real abi of the package.
-
		 *
-
		 * Don't label any package as arch-indep unless arch_indep
-
		 * is set: default to treating everything as
-
		 * architecture dependent.
		 */
-
		if (arch_indep && pkg_is_arch_indep(pkg) == EPKG_OK)
-
			pkg_get_myarch_indep(myarch, BUFSIZ);
-
		else
-
			pkg_get_myarch(myarch, BUFSIZ);
-

+
		pkg_get_myarch(myarch, BUFSIZ);
		pkg_set(pkg, PKG_ARCH, myarch);
	} else {
		pkg_set(pkg, PKG_ARCH, arch);
		free(arch);
	}

+
	if (developer)
+
		pkg_suggest_arch(pkg, arch);
+

	if (input_path != NULL) {
		pkg_copy_tree(pkg, input_path, "/");
		free(input_path);