pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools pkgtools/check-portability: check extracted f...
details: https://anonhg.NetBSD.org/pkgsrc/rev/aaaa945eba28
branches: trunk
changeset: 412722:aaaa945eba28
user: rillig <rillig%pkgsrc.org@localhost>
date: Wed Mar 11 19:15:03 2020 +0000
description:
pkgtools/check-portability: check extracted files for portability issues
Checks whether the given files use features of programming languages that
are not portable to a wide range of platforms.
See mk/check/check-portability.mk.
https://mail-index.netbsd.org/tech-pkg/2020/03/10/msg022787.html
This new check is not active by default, and the package is not forced to
be installed. This will be done after getting some experience in
practical cases.
The code has been tested by extracting about 1.7 GB of pkgsrc distfiles
and scanning for lines containing both "[[" and "]]".
diffstat:
pkgtools/Makefile | 3 +-
pkgtools/check-portability/DESCR | 4 +
pkgtools/check-portability/Makefile | 23 +
pkgtools/check-portability/PLIST | 2 +
pkgtools/check-portability/files/Makefile | 8 +
pkgtools/check-portability/files/check-portability.c | 385 +++++++++++++++
pkgtools/check-portability/files/test-double-brackets.sh | 18 +
7 files changed, 442 insertions(+), 1 deletions(-)
diffs (truncated from 481 to 300 lines):
diff -r a874e8a28dbe -r aaaa945eba28 pkgtools/Makefile
--- a/pkgtools/Makefile Wed Mar 11 18:56:20 2020 +0000
+++ b/pkgtools/Makefile Wed Mar 11 19:15:03 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.119 2018/12/05 19:23:46 schmonz Exp $
+# $NetBSD: Makefile,v 1.120 2020/03/11 19:15:03 rillig Exp $
#
COMMENT= Tools for use in the packages collection
@@ -9,6 +9,7 @@
SUBDIR+= bootstrap-extras
SUBDIR+= bootstrap-mk-files
SUBDIR+= cdpack
+SUBDIR+= check-portability
SUBDIR+= compat_headers
SUBDIR+= createbuildlink
SUBDIR+= cwrappers
diff -r a874e8a28dbe -r aaaa945eba28 pkgtools/check-portability/DESCR
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/check-portability/DESCR Wed Mar 11 19:15:03 2020 +0000
@@ -0,0 +1,4 @@
+Checks whether the given files use features of programming languages that
+are not portable to a wide range of platforms.
+
+See mk/check/check-portability.mk.
diff -r a874e8a28dbe -r aaaa945eba28 pkgtools/check-portability/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/check-portability/Makefile Wed Mar 11 19:15:03 2020 +0000
@@ -0,0 +1,23 @@
+# $NetBSD: Makefile,v 1.1 2020/03/11 19:15:03 rillig Exp $
+
+PKGNAME= check-portability-19.4.0
+CATEGORIES= pkgtools
+DISTFILES= # none
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= # none
+COMMENT= Check extracted files for typical portability issues
+LICENSE= 2-clause-bsd
+
+USE_TOOLS+= pax
+USE_LANGUAGES= c99
+MAKE_ENV+= BINDIR=${PREFIX}/bin
+AUTO_MKDIRS= yes
+
+CHECK_PORTABILITY_SKIP= demo
+
+do-extract:
+ mkdir ${WRKSRC}
+ cd ${FILESDIR} && ${PAX} -rw . ${WRKSRC}
+
+.include "../../mk/bsd.pkg.mk"
diff -r a874e8a28dbe -r aaaa945eba28 pkgtools/check-portability/PLIST
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/check-portability/PLIST Wed Mar 11 19:15:03 2020 +0000
@@ -0,0 +1,2 @@
+@comment $NetBSD: PLIST,v 1.1 2020/03/11 19:15:03 rillig Exp $
+bin/check-portability
diff -r a874e8a28dbe -r aaaa945eba28 pkgtools/check-portability/files/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/check-portability/files/Makefile Wed Mar 11 19:15:03 2020 +0000
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.1 2020/03/11 19:15:03 rillig Exp $
+
+PROG= check-portability
+WARNS= 4
+NOMAN= yes
+CFLAGS+= -ggdb
+
+.include <bsd.prog.mk>
diff -r a874e8a28dbe -r aaaa945eba28 pkgtools/check-portability/files/check-portability.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/check-portability/files/check-portability.c Wed Mar 11 19:15:03 2020 +0000
@@ -0,0 +1,385 @@
+/* $NetBSD: check-portability.c,v 1.1 2020/03/11 19:15:03 rillig Exp $ */
+
+/*
+ Copyright (c) 2020 Roland Illig
+ 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.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define nullptr ((void *)0)
+static const size_t npos = -1;
+
+typedef struct {
+ const char *data; // never nullptr
+ size_t len;
+} cstr;
+
+#define CSTR(str) ((cstr) { str, strlen(str) })
+
+typedef struct {
+ char *data;
+ size_t len;
+ size_t cap;
+} str;
+
+#define STR_EMPTY { nullptr, 0, 0 }
+
+static const char *
+cstr_charptr(cstr s)
+{
+ assert(memchr(s.data, 0, s.len) == nullptr);
+ assert(s.data[s.len] == '\0');
+ return s.data;
+}
+
+static bool
+cstr_ends_with(cstr s, cstr suffix)
+{
+ if (suffix.len > s.len)
+ return false;
+ const char *start = s.data + s.len - suffix.len;
+ return memcmp(start, suffix.data, suffix.len) == 0;
+}
+
+static void
+str_free(str *s)
+{
+ free(s->data);
+}
+
+static void
+str_prepare_append(str *s, size_t n)
+{
+ size_t req_len = s->len + n;
+ assert(req_len >= s->len);
+ if (req_len <= s->cap)
+ return;
+
+ size_t new_cap = s->cap == 0 ? 64 : 2 * s->cap;
+ if (new_cap == 0)
+ new_cap = -1;
+
+ char *new_data = realloc(s->data, new_cap);
+ if (new_data == nullptr) {
+ perror(nullptr);
+ exit(EXIT_FAILURE);
+ }
+
+ s->data = new_data;
+ s->cap = new_cap;
+}
+
+static const char *
+str_charptr(str *s)
+{
+ str_prepare_append(s, 1);
+ s->data[s->len] = '\0';
+ assert(memchr(s->data, 0, s->len) == nullptr);
+ return s->data;
+}
+
+static bool
+cstr_starts_with(cstr s, cstr prefix)
+{
+ return prefix.len <= s.len && memcmp(s.data, prefix.data, prefix.len) == 0;
+}
+
+static void
+str_append_char(str *s, char c)
+{
+ str_prepare_append(s, 1);
+ s->data[s->len++] = c;
+}
+
+static bool
+str_read_line(str *s, FILE *f)
+{
+ int c;
+
+ s->len = 0;
+ while ((c = fgetc(f)) != EOF && c != '\n' && c != '\r') {
+ str_append_char(s, (char) c);
+ }
+ return c != EOF;
+}
+
+static bool
+str_read_text_line(str *s, FILE *f)
+{
+ int c;
+
+ s->len = 0;
+ while ((c = fgetc(f)) > '\0' && c != '\n' && c != '\r') {
+ str_append_char(s, (char) c);
+ }
+ assert(c != '\0');
+ return c != EOF;
+}
+
+static cstr
+str_c(str *s)
+{
+ return (cstr) { s->data, s->len };
+}
+
+static cstr
+cstr_substr(cstr s, size_t start, size_t end)
+{
+ return (cstr) { s.data + start, end - start };
+}
+
+static bool
+is_hspace(char c)
+{
+ return c == ' ' || c == '\t';
+}
+
+static size_t
+cstr_index(cstr haystack, cstr needle)
+{
+ if (needle.len > haystack.len)
+ return npos;
+ size_t limit = haystack.len - needle.len;
+ for (size_t i = 0; i <= limit; i++)
+ if (memcmp(haystack.data + i, needle.data, needle.len) == 0)
+ return i;
+ return npos;
+}
+
+static size_t
+cstr_rindex(cstr haystack, cstr needle)
+{
+ size_t i = cstr_index(haystack, needle);
+ if (i == npos)
+ return npos;
+
+ while (true) {
+ cstr rest = cstr_substr(haystack, i + 1, haystack.len);
+ size_t next = cstr_index(rest, needle);
+ if (next == npos)
+ return i;
+ i = i + 1 + next;
+ }
+}
+
+static bool
+cstr_eq(cstr s1, cstr s2)
+{
+ return s1.len == s2.len && memcmp(s1.data, s2.data, s1.len) == 0;
+}
+
+typedef enum {
+ W_test_eqeq,
+ W_double_bracket
+} warning_kind;
+
+static unsigned long explained = 0;
+
+static void
+explain(warning_kind warning, ...)
+{
+ unsigned long mask = 1UL << warning;
+ if ((explained & mask) != 0)
+ return;
+ explained |= mask;
+
+ va_list args;
+ va_start(args, warning);
+ printf("\n");
+ const char *line;
+ while ((line = va_arg(args, const char *)) != nullptr)
+ printf("%s%s\n", line[0] == '\0' ? "" : "\t", line);
+ printf("\n");
+ va_end(args);
+}
+
+static size_t
+index_opening_bracket(cstr s)
+{
Home |
Main Index |
Thread Index |
Old Index