pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/check-portability pkgtools/check-portability:...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/7cc6f5ed93e7
branches:  trunk
changeset: 424536:7cc6f5ed93e7
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Mar 12 08:42:34 2020 +0000

description:
pkgtools/check-portability: update to 19.4.1

Changes since 19.4.0:

* Makefile.am and Makefile.in are checked even though they don't start
  with a #! line.
* Only shell programs with an interpreter that is clearly a POSIX shell
  are checked. Before, there was a blacklist of interpreters to be
  skipped.
* Lots of refactorings and code cleanups.
* Some additional test files.

diffstat:

 pkgtools/check-portability/Makefile                       |    6 +-
 pkgtools/check-portability/files/check-portability.c      |  361 +++++++------
 pkgtools/check-portability/files/test-double-brackets.sh  |   18 -
 pkgtools/check-portability/files/test-random.sh           |   15 -
 pkgtools/check-portability/files/test-test-eqeq.sh        |   18 -
 pkgtools/check-portability/files/testdata/Makefile.am     |    8 +
 pkgtools/check-portability/files/testdata/double-brackets |   18 +
 pkgtools/check-portability/files/testdata/env-sh          |    8 +
 pkgtools/check-portability/files/testdata/interp-ok       |    7 +
 pkgtools/check-portability/files/testdata/random          |   15 +
 pkgtools/check-portability/files/testdata/test-eqeq       |   18 +
 11 files changed, 272 insertions(+), 220 deletions(-)

diffs (truncated from 690 to 300 lines):

diff -r 97a97d79e7f7 -r 7cc6f5ed93e7 pkgtools/check-portability/Makefile
--- a/pkgtools/check-portability/Makefile       Thu Mar 12 07:52:00 2020 +0000
+++ b/pkgtools/check-portability/Makefile       Thu Mar 12 08:42:34 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.3 2020/03/12 00:05:36 rillig Exp $
+# $NetBSD: Makefile,v 1.4 2020/03/12 08:42:34 rillig Exp $
 
-PKGNAME=       check-portability-19.4.0
+PKGNAME=       check-portability-19.4.1
 CATEGORIES=    pkgtools
 DISTFILES=     # none
 
@@ -10,7 +10,7 @@
 LICENSE=       2-clause-bsd
 
 USE_TOOLS+=            pax
-CHECK_PORTABILITY_SKIP=        test-*.sh
+CHECK_PORTABILITY_SKIP=        testdata/*
 USE_LANGUAGES=         c99
 USE_BSD_MAKEFILE=      yes
 AUTO_MKDIRS=           yes
diff -r 97a97d79e7f7 -r 7cc6f5ed93e7 pkgtools/check-portability/files/check-portability.c
--- a/pkgtools/check-portability/files/check-portability.c      Thu Mar 12 07:52:00 2020 +0000
+++ b/pkgtools/check-portability/files/check-portability.c      Thu Mar 12 08:42:34 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: check-portability.c,v 1.3 2020/03/11 23:36:32 rillig Exp $ */
+/* $NetBSD: check-portability.c,v 1.4 2020/03/12 08:42:34 rillig Exp $ */
 
 /*
  Copyright (c) 2020 Roland Illig
@@ -38,6 +38,19 @@
 #define nullptr ((void *)0)
 static const size_t npos = -1;
 
+static bool
+is_alnum(char c)
+{
+       return isalnum((unsigned char) c) != 0;
+}
+
+static bool
+is_hspace(char c)
+{
+       return c == ' ' || c == '\t';
+}
+
+// cstr is a constant string view.
 typedef struct {
        const char *data; // never nullptr
        size_t len;
@@ -45,20 +58,6 @@
 
 #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 bool
-is_alnum(char c)
-{
-       return isalnum((unsigned char) c) != 0;
-}
-
 static const char *
 cstr_charptr(cstr s)
 {
@@ -67,6 +66,7 @@
        return s.data;
 }
 
+#if 0 /* unused */
 static bool
 cstr_ends_with(cstr s, cstr suffix)
 {
@@ -75,6 +75,98 @@
        const char *start = s.data + s.len - suffix.len;
        return memcmp(start, suffix.data, suffix.len) == 0;
 }
+#endif
+
+static bool
+cstr_starts_with(cstr s, cstr prefix)
+{
+       if (prefix.len > s.len)
+               return false;
+       return memcmp(s.data, prefix.data, prefix.len) == 0;
+}
+
+static cstr
+cstr_substr(cstr s, size_t start, size_t end)
+{
+       assert(start <= s.len);
+       assert(end <= s.len);
+       assert(end - start <= s.len);
+       return (cstr) { s.data + start, end - start };
+}
+
+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 bool
+cstr_contains(cstr haystack, cstr needle)
+{
+       return cstr_index(haystack, needle) != npos;
+}
+
+static size_t
+cstr_rindex(cstr haystack, cstr needle)
+{
+       if (needle.len > haystack.len)
+               return npos;
+       size_t limit = haystack.len - needle.len;
+       for (size_t i = limit + 1; i-- > 0; )
+               if (memcmp(haystack.data + i, needle.data, needle.len) == 0)
+                       return i;
+       return npos;
+}
+
+static bool
+cstr_eq(cstr s1, cstr s2)
+{
+       return s1.len == s2.len
+           && memcmp(s1.data, s2.data, s1.len) == 0;
+}
+
+static cstr
+cstr_next_field(cstr line, size_t *pidx)
+{
+       size_t idx = *pidx;
+       while (idx < line.len && is_hspace(line.data[idx]))
+               idx++;
+       size_t start = idx;
+       while (idx < line.len && !is_hspace(line.data[idx]))
+               idx++;
+       *pidx = idx;
+       return cstr_substr(line, start, idx);
+}
+
+static cstr
+cstr_right_of_last(cstr s, cstr delimiter)
+{
+       size_t i = cstr_rindex(s, delimiter);
+       if (i == npos)
+               return s;
+       return cstr_substr(s, i + delimiter.len, s.len);
+}
+
+// str is a modifiable string buffer.
+typedef struct {
+       char *data;
+       size_t len;
+       size_t cap;
+} str;
+
+#define STR_EMPTY { nullptr, 0, 0 }
+
+static cstr
+str_c(str *s)
+{
+       return (cstr) { s->data, s->len };
+}
 
 static void
 str_free(str *s)
@@ -83,7 +175,7 @@
 }
 
 static void
-str_prepare_append(str *s, size_t n)
+str_reserve(str *s, size_t n)
 {
        size_t req_len = s->len + n;
        assert(req_len >= s->len);
@@ -104,29 +196,23 @@
        s->cap = new_cap;
 }
 
+static void
+str_append_char(str *s, char c)
+{
+       str_reserve(s, 1);
+       s->data[s->len++] = c;
+}
+
 static const char *
 str_charptr(str *s)
 {
-       str_prepare_append(s, 1);
+       str_reserve(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;
@@ -151,64 +237,6 @@
        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 bool
-cstr_contains(cstr haystack, cstr needle)
-{
-       return cstr_index(haystack, needle) != 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_dollar_random,
        W_test_eqeq,
@@ -266,11 +294,13 @@
 static bool
 is_shell_comment(cstr line)
 {
-       return line.len > 0 && line.data[0] == '#';
+       size_t i = 0;
+       cstr f1 = cstr_next_field(line, &i);
+       return cstr_starts_with(f1, CSTR("#"));
 }
 



Home | Main Index | Thread Index | Old Index