Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better document generator #924

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tools/generate-docs.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
(import
(chibi)
(chibi io)
(chibi string)
(chibi process)
(chibi filesystem)
(chibi pathname)
(srfi 98))

(define (walk-directory path)
#;(write (cons "visiting: " path))
(apply append
(map
(lambda (filename)
(define path2 (string-append path "/" filename))
#;(write `(,path2))
(cond
((equal? #\. (string-ref filename 0)) (list))
((file-directory? path2) (walk-directory path2))
(else (list path2))))
(directory-files path))))

(define (filter f xs)
(apply append
(map
(lambda (x)
(if (f x)
(list x)
(list)))
xs)))

(define (filename-filter filename)
(and
(string-contains filename "chibi/")
(string-suffix? ".sld" filename)
(not (string-contains filename "-test"))))

(define (char-replacer from to)
(lambda (c)
(if (eq? from c) to c)))

(define (process x)
(define strlen-ext (string-length ".sdl"))
(define outfile
(string-append
"doc/"
(substring x 0 (- (string-length x) strlen-ext))
".html"))
(define doc-mod-name (string-map (char-replacer #\/ #\.) (substring x (string-length "lib/") (- (string-length x) strlen-ext))))
(display `("Started" ,doc-mod-name ,x ,outfile))
(newline)
(let ((output (process->string `("./chibi-scheme" "tools/chibi-doc" "--html" ,doc-mod-name))))
(create-directory* (path-directory outfile))
(call-with-output-file
outfile
(lambda (port)
(display output port))))
(display `("Processed" ,doc-mod-name ,x ,outfile))
(newline))

(define (fork-map f xs)
(if (pair? xs)
(let ((pid (fork)))
(if (= 0 pid)
(begin
(f (car xs))
(exit))
(begin
(fork-map f (cdr xs))
(waitpid pid 0))))))

; fork-map is naive
; BUG: some files like chibi.show are broken
; BUG: editing this script when running breaks it
; example error:
; ERROR: undefined variable: k-map
; called from <anonymous> on line 1268 of file lib/init-7.scm
; called from <anonymous> on line 800 of file lib/init-7.scm

(define (main)
(define CHIBI_MODULE_PATH (get-environment-variable "CHIBI_MODULE_PATH"))
(cond
((not CHIBI_MODULE_PATH) (begin
(display "USAGE: CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme tools/generate-docs.scm")
(newline)))
(else
(fork-map
process
(filter filename-filter (walk-directory CHIBI_MODULE_PATH))))))

(main)