test-bad-identifiers 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. (define (directory-files-matching dir pattern)
  40. (let ((file-name-regexp (make-regexp pattern)))
  41. (filter (lambda (fn)
  42. (regexp-exec file-name-regexp fn))
  43. (directory-files dir))))
  44. (let loop ((file-names (directory-files-matching "../../libguile"
  45. "\\.[ch]$")))
  46. (or (null? file-names)
  47. (begin
  48. (with-input-from-file (car file-names)
  49. (lambda ()
  50. (let loop ((linenum 1) (line (read-line)))
  51. (or (eof-object? line)
  52. (begin
  53. (if (regexp-exec bad-id-regexp line)
  54. (begin
  55. (set! exit-status 1)
  56. (format (current-error-port)
  57. "~a:~a: ~a\n"
  58. (car file-names)
  59. linenum
  60. line)))
  61. (loop (+ linenum 1) (read-line)))))))
  62. (loop (cdr file-names)))))
  63. (exit exit-status)
  64. ;; Local Variables:
  65. ;; mode: scheme
  66. ;; End: