From 6dc1ca9cca762f3ebb93ceafef81be86ec0c5614 Mon Sep 17 00:00:00 2001 From: Locria Cyber <74560659+iacore@users.noreply.github.com> Date: Mon, 19 Jun 2023 20:02:01 +0000 Subject: [PATCH 1/4] Add generate-docs.scm --- tools/generate-docs.scm | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tools/generate-docs.scm diff --git a/tools/generate-docs.scm b/tools/generate-docs.scm new file mode 100644 index 00000000..bac011d4 --- /dev/null +++ b/tools/generate-docs.scm @@ -0,0 +1,65 @@ +(import + (chibi) + (chibi io) + (chibi string) + (chibi process) + (chibi filesystem) + (chibi pathname) + (srfi 18)) + +(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-suffix? ".sld" filename) + (not (string-contains filename "-test")))) + + +(define (process x) + (define outfile + (string-append + "doc/" + (substring x 0 (- (string-length x) 4)) + ".html")) + (display `("Processing" ,x ,outfile)) + (newline) + (let ((output (process->string `("./chibi-scheme" "tools/chibi-doc" "--html" ,x)))) + (create-directory* (path-directory outfile)) + (call-with-output-file + outfile + (lambda (port) + (display output port))))) + +(define (fork-map f xs) + (if (pair? xs) + (let* ((x (car xs)) + (thread (make-thread (lambda () (f x))))) + (thread-start! thread) + (fork-map f (cdr xs)) + (thread-join! thread)) + (begin))) + +(fork-map + process + (filter filename-filter (walk-directory "lib"))) + From f339e95eb6ee1cd2c359714c5221e2c13563f9e9 Mon Sep 17 00:00:00 2001 From: Locria Cyber <74560659+iacore@users.noreply.github.com> Date: Mon, 19 Jun 2023 20:20:56 +0000 Subject: [PATCH 2/4] Fix generate-docs.scm It is now much slower --- tools/generate-docs.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/generate-docs.scm b/tools/generate-docs.scm index bac011d4..8287acf9 100644 --- a/tools/generate-docs.scm +++ b/tools/generate-docs.scm @@ -59,7 +59,9 @@ (thread-join! thread)) (begin))) -(fork-map +; fork-map is broken. The HTML files produced are empty + +(map process (filter filename-filter (walk-directory "lib"))) From 99b793118b3c2fe24c596cafdaaccb370b141a4c Mon Sep 17 00:00:00 2001 From: Locria Cyber <74560659+iacore@users.noreply.github.com> Date: Mon, 19 Jun 2023 22:32:04 +0000 Subject: [PATCH 3/4] Try to fix it again --- tools/generate-docs.scm | 48 +++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tools/generate-docs.scm b/tools/generate-docs.scm index 8287acf9..2152e2ad 100644 --- a/tools/generate-docs.scm +++ b/tools/generate-docs.scm @@ -5,7 +5,7 @@ (chibi process) (chibi filesystem) (chibi pathname) - (srfi 18)) + (srfi 98)) (define (walk-directory path) #;(write (cons "visiting: " path)) @@ -34,34 +34,50 @@ (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) 4)) + (substring x 0 (- (string-length x) strlen-ext)) ".html")) - (display `("Processing" ,x ,outfile)) - (newline) - (let ((output (process->string `("./chibi-scheme" "tools/chibi-doc" "--html" ,x)))) + (define doc-mod-name (string-map (char-replacer #\/ #\.) (substring x (string-length "lib/") (- (string-length x) strlen-ext)))) + (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 output port)))) + (display `("Processed" ,doc-mod-name ,x ,outfile)) + (newline)) (define (fork-map f xs) (if (pair? xs) - (let* ((x (car xs)) - (thread (make-thread (lambda () (f x))))) - (thread-start! thread) - (fork-map f (cdr xs)) - (thread-join! thread)) - (begin))) + (let ((pid (fork))) + (if (= 0 pid) + (begin + (f (car xs)) + (exit)) + (begin + (fork-map f (cdr xs)) + (waitpid pid 0)))))) -; fork-map is broken. The HTML files produced are empty +; fork-map is naive +; BUG: some files like chibi.show are broken -(map - process - (filter filename-filter (walk-directory "lib"))) +(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) From 162ef8d2355195a89f7a3fb5fe823e9294fe0d78 Mon Sep 17 00:00:00 2001 From: Locria Cyber <74560659+iacore@users.noreply.github.com> Date: Mon, 19 Jun 2023 22:56:22 +0000 Subject: [PATCH 4/4] Update script --- tools/generate-docs.scm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/generate-docs.scm b/tools/generate-docs.scm index 2152e2ad..b02608cc 100644 --- a/tools/generate-docs.scm +++ b/tools/generate-docs.scm @@ -31,6 +31,7 @@ (define (filename-filter filename) (and + (string-contains filename "chibi/") (string-suffix? ".sld" filename) (not (string-contains filename "-test")))) @@ -46,6 +47,8 @@ (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 @@ -68,6 +71,11 @@ ; 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 on line 1268 of file lib/init-7.scm +; called from on line 800 of file lib/init-7.scm (define (main) (define CHIBI_MODULE_PATH (get-environment-variable "CHIBI_MODULE_PATH"))