pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/mktools mktools: Import new package, version ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c15850953f38
branches:  trunk
changeset: 380442:c15850953f38
user:      jperkin <jperkin%pkgsrc.org@localhost>
date:      Tue Jun 07 09:53:36 2022 +0000

description:
mktools: Import new package, version 20220607.

Collection of tools written in C to improve the performance of certain
sections of the pkgsrc mk infrastructure where shell is too slow.

For now this just includes mk-buildlink-symlinks which is used to generate
the buildlink3 symlinks as part of the "wrapper" phase.

diffstat:

 pkgtools/mktools/DESCR                         |    2 +
 pkgtools/mktools/Makefile                      |   23 +++++
 pkgtools/mktools/PLIST                         |    2 +
 pkgtools/mktools/files/Makefile                |   12 ++
 pkgtools/mktools/files/mk-buildlink-symlinks.c |   75 +++++++++++++++++
 pkgtools/mktools/files/mkpath.c                |  110 +++++++++++++++++++++++++
 6 files changed, 224 insertions(+), 0 deletions(-)

diffs (248 lines):

diff -r b3bdeae0c625 -r c15850953f38 pkgtools/mktools/DESCR
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/mktools/DESCR    Tue Jun 07 09:53:36 2022 +0000
@@ -0,0 +1,2 @@
+Collection of tools written in C to improve the performance of certain
+sections of the pkgsrc mk infrastructure where shell is too slow.
diff -r b3bdeae0c625 -r c15850953f38 pkgtools/mktools/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/mktools/Makefile Tue Jun 07 09:53:36 2022 +0000
@@ -0,0 +1,23 @@
+# $NetBSD: Makefile,v 1.1 2022/06/07 09:53:36 jperkin Exp $
+
+PKGNAME=               mktools-20220607
+CATEGORIES=            pkgtools sysutils
+
+MAINTAINER=            jperkin%pkgsrc.org@localhost
+HOMEPAGE=              https://www.NetBSD.org/
+COMMENT=               Collection of pkgsrc mk infrastructure tools
+LICENSE=               modified-bsd
+
+USE_BSD_MAKEFILE=      yes
+
+INSTALLATION_DIRS=     libexec/mktools
+
+# Avoid any dependency cycles
+CHECK_PERMS_SKIP=      *
+CHECK_PORTABILITY_SKIP=        *
+PKGSRC_LOCKTYPE=       none
+
+do-extract:
+       ${CP} -R ${FILESDIR}/ ${WRKSRC}/
+
+.include "../../mk/bsd.pkg.mk"
diff -r b3bdeae0c625 -r c15850953f38 pkgtools/mktools/PLIST
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/mktools/PLIST    Tue Jun 07 09:53:36 2022 +0000
@@ -0,0 +1,2 @@
+@comment $NetBSD: PLIST,v 1.1 2022/06/07 09:53:36 jperkin Exp $
+libexec/mktools/mk-buildlink-symlinks
diff -r b3bdeae0c625 -r c15850953f38 pkgtools/mktools/files/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/mktools/files/Makefile   Tue Jun 07 09:53:36 2022 +0000
@@ -0,0 +1,12 @@
+# $NetBSD: Makefile,v 1.1 2022/06/07 09:53:36 jperkin Exp $
+#
+PROGS= mk-buildlink-symlinks
+
+BINDIR=        ${PREFIX}/libexec/mktools
+
+SRCS.mk-buildlink-symlinks=    mk-buildlink-symlinks.c mkpath.c
+
+WARNS= 4
+NOMAN=
+
+.include <bsd.prog.mk>
diff -r b3bdeae0c625 -r c15850953f38 pkgtools/mktools/files/mk-buildlink-symlinks.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/mktools/files/mk-buildlink-symlinks.c    Tue Jun 07 09:53:36 2022 +0000
@@ -0,0 +1,75 @@
+/* $NetBSD: mk-buildlink-symlinks.c,v 1.1 2022/06/07 09:53:36 jperkin Exp $ */
+
+/*
+ * Copyright (c) 2022 Jonathan Perkin <jonathan%perkin.org.uk@localhost>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/stat.h>
+#include <err.h>
+#include <errno.h>
+#include <libgen.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define        LINK_SEP        " -> "
+#define LINK_SEP_LEN   4
+
+extern int mkpath(char *, mode_t, mode_t);
+
+int
+main(int argc, char *argv[])
+{
+       char *line, *path1, *path2, *pdir;
+       size_t len;
+       ssize_t llen;
+
+       for (len = 0, line = NULL; (llen = getline(&line, &len, stdin)) > 0;
+           free(line), line = NULL, len = 0) {
+               if (line[llen - 1] == '\n')
+                       line[llen - 1] = '\0';
+
+               if ((path1 = strstr(line, LINK_SEP)) == NULL)
+                       errx(1, "Could not find separator");
+
+               *path1 = '\0';
+               path1 += LINK_SEP_LEN;
+
+               if ((path2 = strdup(line)) == NULL)
+                       err(1, "strdup");
+
+               /*
+                * The implementation notes for dirname() say that its argument
+                * may be modified, so ensure this operation comes after any
+                * other use of "line".
+                */
+               if ((pdir = dirname(line)) == NULL)
+                       err(1, "dirname");
+
+               if (access(pdir, F_OK) != 0) {
+                       if (mkpath(pdir, 0755, 0755) != 0)
+                               err(1, "mkpath: %s", pdir);
+               }
+
+               if (unlink(path2) != 0 && errno != ENOENT)
+                       warn("unlink: %s", path2);
+
+               if (symlink(path1, path2) != 0)
+                       err(1, "symlink: %s -> %s", path2, path1);
+
+               free(path2);
+       }
+}
diff -r b3bdeae0c625 -r c15850953f38 pkgtools/mktools/files/mkpath.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/mktools/files/mkpath.c   Tue Jun 07 09:53:36 2022 +0000
@@ -0,0 +1,110 @@
+/* $NetBSD: mkpath.c,v 1.1 2022/06/07 09:53:36 jperkin Exp $ */
+
+/*
+ * Copyright (c) 1983, 1992, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copy of mkpath() from NetBSD src/bin/mkdir/mkdir.c
+ */
+#include <sys/stat.h>
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+
+int mkpath(char *path, mode_t mode, mode_t dir_mode);
+
+/*
+ * mkpath -- create directories.
+ *     path     - path
+ *     mode     - file mode of terminal directory
+ *     dir_mode - file mode of intermediate directories
+ */
+int
+mkpath(char *path, mode_t mode, mode_t dir_mode)
+{
+       struct stat sb;
+       char *slash;
+       int done, rv;
+
+       done = 0;
+       slash = path;
+
+       for (;;) {
+               slash += strspn(slash, "/");
+               slash += strcspn(slash, "/");
+
+               done = (*(slash + strspn(slash, "/")) == '\0');
+               *slash = '\0';
+
+               rv = mkdir(path, done ? mode : dir_mode);
+               if (rv < 0) {
+                       /*
+                        * Can't create; path exists or no perms.
+                        * stat() path to determine what's there now.
+                        */
+                       int     sverrno;
+
+                       sverrno = errno;
+                       if (stat(path, &sb) < 0) {
+                                       /* Not there; use mkdir()s error */
+                               errno = sverrno;
+                               warn("%s", path);
+                               return -1;
+                       }
+                       if (!S_ISDIR(sb.st_mode)) {
+                                       /* Is there, but isn't a directory */
+                               errno = ENOTDIR;
+                               warn("%s", path);
+                               return -1;
+                       }
+               } else if (done) {
+                       /*
+                        * Created ok, and this is the last element
+                        */
+                       /*
+                        * The mkdir() and umask() calls both honor only the
+                        * file permission bits, so if you try to set a mode
+                        * including the sticky, setuid, setgid bits you lose
+                        * them. So chmod().
+                        */
+                       if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 &&
+                           chmod(path, mode) == -1) {
+                               warn("%s", path);
+                               return -1;
+                       }
+               }
+
+               if (done) {
+                       break;
+               }
+               *slash = '/';
+       }
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index