test-bad-identifiers 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. exec guile -q -s "$0" "$@"
  3. !#
  4. ;; The use of certain identifiers as variable or parameter names has
  5. ;; been found to cause build problems on particular platforms. The
  6. ;; aim of this test is to cause "make check" to fail (on GNU/Linux,
  7. ;; which most Guile developers use) if we accidentally add new code
  8. ;; that uses those identifiers.
  9. (define bad-identifiers
  10. '(
  11. ;; On AIX 5.2 and 5.3, /usr/include/sys/timer.h includes:
  12. ;; #ifndef _LINUX_SOURCE_COMPAT
  13. ;; #define func_data t_union.data
  14. ;; #endif
  15. ;; So we want to avoid using func_data in Guile source code.
  16. "func_data"
  17. ;; More troublesome identifiers can be added into the list here.
  18. ))
  19. (use-modules (ice-9 regex) (ice-9 rdelim))
  20. (define bad-id-regexp
  21. (make-regexp (string-append "\\<("
  22. (string-join (map regexp-quote bad-identifiers) "|")
  23. ")\\>")))
  24. (define exit-status 0)
  25. ;; Non-exported code from (ice-9 ftw).
  26. (define (directory-files dir)
  27. (let ((dir-stream (opendir dir)))
  28. (let loop ((new (readdir dir-stream))
  29. (acc '()))
  30. (if (eof-object? new)
  31. (begin
  32. (closedir dir-stream)
  33. acc)
  34. (loop (readdir dir-stream)
  35. (if (or (string=? "." new) ;;; ignore
  36. (string=? ".." new)) ;;; ignore
  37. acc
  38. (cons (in-vicinity dir new) acc)))))))
  39. (let loop ((file-names (filter (lambda (fn)
  40. (and (or (string-suffix? ".h" fn)
  41. (string-suffix? ".c" fn))
  42. (not (string-prefix? "." (basename fn)))))
  43. (directory-files "../../libguile"))))
  44. (or (null? file-names)
  45. (begin
  46. (with-input-from-file (car file-names)
  47. (lambda ()
  48. (let loop ((linenum 1) (line (read-line)))
  49. (or (eof-object? line)
  50. (begin
  51. (if (regexp-exec bad-id-regexp line)
  52. (begin
  53. (set! exit-status 1)
  54. (format (current-error-port)
  55. "~a:~a: ~a\n"
  56. (car file-names)
  57. linenum
  58. line)))
  59. (loop (+ linenum 1) (read-line)))))))
  60. (loop (cdr file-names)))))
  61. (exit exit-status)
  62. ;; Local Variables:
  63. ;; mode: scheme
  64. ;; End: