blob: 3d2028398b407ded4c67b20fdf2f317eed8fa8d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
(define-module (hnh module-introspection all-modules)
:use-module (srfi srfi-1)
:use-module (ice-9 ftw)
:use-module (ice-9 match)
:use-module (hnh util path)
:use-module (hnh module-introspection)
:export (all-files-and-modules-under-directory
all-files-under-directory
all-modules-under-directory
fs-find
module-file-mapping
))
(define (fs-find dir)
(define files '())
(ftw dir (lambda args (set! files (cons args files)) #t))
files)
(define (string-ends-with? string tail)
(and (>= (string-length string)
(string-length tail))
(string=? tail
(substring string
(- (string-length string)
(string-length tail))))))
(define* (all-files-under-directory dir extension)
(map car
(filter (match-lambda ((filename _ 'regular)
(and (string-ends-with? filename extension)
(not (file-hidden? filename))))
(_ #f))
(fs-find dir))))
(define (all-files-and-modules-under-directory dir)
(map (lambda (file)
(list file
(call-with-input-file file
(compose find-module-declaration get-forms))))
(all-files-under-directory dir ".scm")))
(define (all-modules-under-directory dir)
"Returns two values, all scm files in dir, and all top
level modules in those files"
(define pairs (all-files-and-modules-under-directory dir))
(values
(map car pairs)
(filter identity (map cadr pairs))))
;; Returns an association list from module names the modules
;; containing filename
(define (module-file-mapping dir)
(filter
car
(map (lambda (pair) (cons (cadr pair) (car pair)))
(all-files-and-modules-under-directory dir))))
|