(zilch lang go): document

Change-Id: I6a6a6964558b4fe2f96d78120b2e899f91d48c22
This commit is contained in:
puck 2025-06-23 12:22:20 +00:00
parent f0ce185d5c
commit 18f2887eba
13 changed files with 457 additions and 96 deletions

View file

@ -44,9 +44,8 @@
(if (char-upper-case? ch) (set! out (string-append out (string #\! (char-downcase ch)))) (set! out (string-append out (string ch))))) name)
out)
;; Reads a dirhash from a `go.sum` line. This prefetches the module from
;; the go module proxy, and then generates the dirhash without unpacking
;; said module file.
;; Uses the hash in a `<go-sum-line>` to return a store path containing a list of the hashes of each file,
;; following the https://pkg.go.dev/golang.org/x/mod/sumdb/dirhash[`dirhash`] format used by the `go.sum` files.
(define (fetch-dirhash-for-sum sum-line)
(when (go-sum-path sum-line) (error "go.sum line is invalid for fetch-dirhash-for-sum" sum-line))
(define url (string-append "https://proxy.golang.org/" (rewrite-go-package-name-for-url (go-sum-module sum-line)) "/@v/" (go-sum-version sum-line) ".zip"))
@ -54,7 +53,8 @@
(store-path-for-fod "module" "x86_64-linux" #~(#$(force dirhash-generator)) #~(("src" . #$known)) "sha256" (go-sum-hash sum-line) #f))
;; Generates a full VFS structure from a module as described by a `go.sum`
;; line.
;; line. Uses `fetch-dirhash-for-sum` to generate the dirhash, then creates FODs
;; for each file based on said hash; this is then returned as a `<vfs>` structure.
(define (vfs-from-dirhash sum-line)
(define dirhash-file (fetch-dirhash-for-sum sum-line))
(define url (string-append "https://proxy.golang.org/" (rewrite-go-package-name-for-url (go-sum-module sum-line)) "/@v/" (go-sum-version sum-line) ".zip"))
@ -106,14 +106,17 @@
((= i 0) #f)
(else (extract-extension name (- i 1)))))
;; Returns a VFS, filtered down to only contain the contents of files that
;; will be read during the processing of Go packages.
;; Returns a subset of `vfs`, filtered down to only contain the contents of files that
;; Go cares about.
(define (vfs-filter-for-go-package vfs)
(vfs-dir-filter vfs
(lambda (dir fname contents)
(define extension (extract-extension fname (- (string-length fname) 1)))
(member extension good-extensions))))
;; Generates a representation of the `vfs`, processed to be turned into JSON.
;; Primarily used by `(zilch lang go package)` to allow extracting the necessary
;; information of each package from a module's vfs.
(define (vfs-to-json vfs)
(mapping-map->list
(lambda (k v) (list (car k) (cdr k) (if (eq? v 'directory) "" v)))