tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: suggestion: pkg_add should stat all libs in REQUIRES, at least base libs



On Wed, Aug 21, 2024 at 09:28:46PM +0200, Roland Illig wrote:
> Am 21.08.2024 um 20:03 schrieb Thomas Klausner:
> > On Tue, Jul 23, 2024 at 07:19:21AM -0400, Greg Troxel wrote:
> >> The concrete suggestion is for pkg_add, before commmiting to add a
> >> package, to:
> >>
> >>   - extract the REQUIRES list of libs
> >>   - for each lib that is not in $LOCALBASE
> >>       stat the lib
> >>       throw an exception if missing
> >
> > Here's an implementation of it.
> I'd prefer to list all missing files instead of only the first.
> 
> The indentation of the 'if (stat' line and the following line is using
> spaces, should be tabs.
> 
> The warning "install the X sets" should only occur on NetBSD, as other
> operating systems have different packaging strategies for their base system.
> 
> The check for S_ISLNK should be unnecessary since you are using stat(2),
> not lstat(2).

Good points, thanks.

# ./work/pkg_install-20240821/add/pkg_add /tmp/dummy-5.9nb2.tgz
pkg_add: Missing required library: /usr/not/lib/libXau.so.8
pkg_add: Missing required library: /usr/X11R7/lib/libXau.so.8
pkg_add: Please make sure to install the X sets
pkg_add: Missing required library: /usr/pkg/lib/libmissing.so.9
pkg_add: 1 package addition failed

 Thomas
Index: files/add/perform.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/perform.c,v
retrieving revision 1.122
diff -u -r1.122 perform.c
--- files/add/perform.c	26 Jan 2024 03:24:49 -0000	1.122
+++ files/add/perform.c	21 Aug 2024 19:53:42 -0000
@@ -1115,6 +1115,41 @@
 	return status;
 }
 
+/* check if all REQUIRES files (usually libraries) are installed */
+static int
+check_requires(struct pkg_task *pkg)
+{
+	const char *data, *eol, *next_line;
+	int ret = 0;
+
+	data = pkg->meta_data.meta_build_info;
+
+	for (; data != NULL && *data != '\0'; data = next_line) {
+		if ((eol = strchr(data, '\n')) == NULL) {
+			eol = data + strlen(data);
+			next_line = eol;
+		} else
+			next_line = eol + 1;
+
+		if (strncmp(data, "REQUIRES=", 9) == 0) {
+			char *library_name = dup_value(data, eol);
+			struct stat sb;
+			if (stat(library_name, &sb) != 0 || !S_ISREG(sb.st_mode)) {
+				warnx("Missing required library: %s", library_name);
+#ifdef __NetBSD__
+				if (strncmp(library_name, "/usr/X11R7", 10) == 0) {
+					warnx("Please make sure to install the X sets");
+				}
+#endif
+				ret = 1;
+			}
+			free(library_name);
+		}
+	}
+
+	return ret;
+}
+
 /*
  * Install a required dependency and verify its installation.
  */
@@ -1124,7 +1159,7 @@
 	/* XXX check cyclic dependencies? */
 	if (Fake || NoRecord) {
 		if (!Force) {
-			warnx("Missing dependency %s\n", dep);
+			warnx("Missing dependency %s", dep);
 			return 1;
 		}
 		warnx("Missing dependency %s, continuing", dep);
@@ -1513,6 +1548,9 @@
 	if (check_implicit_conflict(pkg))
 		goto clean_memory;
 
+	if (check_requires(pkg))
+		goto clean_memory;
+
 	if (pkg->other_version != NULL) {
 		/*
 		 * Replacing an existing package.
Index: files/lib/version.h
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/version.h,v
retrieving revision 1.193
diff -u -r1.193 version.h
--- files/lib/version.h	15 Aug 2024 02:43:58 -0000	1.193
+++ files/lib/version.h	21 Aug 2024 19:53:42 -0000
@@ -27,6 +27,6 @@
 #ifndef _INST_LIB_VERSION_H_
 #define _INST_LIB_VERSION_H_
 
-#define PKGTOOLS_VERSION 20240810
+#define PKGTOOLS_VERSION 20240821
 
 #endif /* _INST_LIB_VERSION_H_ */


Home | Main Index | Thread Index | Old Index