Clean up documentation
This commit is contained in:
parent
55a1efa08f
commit
83d41ef778
16 changed files with 146 additions and 98 deletions
|
|
@ -1,3 +1,10 @@
|
|||
;; Contains procedures to work with a very simple virtual filesystem,
|
||||
;; abstracting between local and in-store store paths.
|
||||
;;
|
||||
;; A VFS is defined as a vector containing pairs consisting of the directory's
|
||||
;; name, with a forward slash prefixed and postfixed (e.g. `/` or `/foo/bar/`).
|
||||
;; Each pair then contains another vector, mapping filename to any value that
|
||||
;; can be used as a z-expression (e.g. `store-path-for-fod` or `zfile`).
|
||||
(define-library (zilch lang go vfs)
|
||||
(import
|
||||
(scheme base) (scheme write) (scheme read) (scheme file) (scheme process-context) (scheme lazy) (scheme case-lambda)
|
||||
|
|
@ -42,6 +49,8 @@
|
|||
(if (char-upper-case? ch) (set! out (string-append out (string #\! (char-downcase ch)))) (set! out (string-append out (string ch))))) name)
|
||||
out)
|
||||
|
||||
;; Takes a VFS and writes its directory structure into the Nix store,
|
||||
;; returning a zdir describing the root directory.
|
||||
(define (vfs-to-store vfs)
|
||||
(define dirmap (mapping (make-default-comparator)))
|
||||
(vector-for-each
|
||||
|
|
@ -62,13 +71,17 @@
|
|||
(map (lambda (k) (cons (car k) (translate-dir (cdr k)))) dirs))))
|
||||
(translate-dir "/"))
|
||||
|
||||
|
||||
;; 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.
|
||||
(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-name (go-sum-module sum-line)) "/@v/" (go-sum-version sum-line) ".zip"))
|
||||
(define known (fetch-with-known-url "module.zip" url))
|
||||
(store-path-for-fod "module" "x86_64-linux" #~(#$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.
|
||||
(define (vfs-from-dirhash sum-line)
|
||||
(define dirhash-file (fetch-dirhash-for-sum sum-line))
|
||||
(define url (string-append "https://proxy.golang.org/" (rewrite-name (go-sum-module sum-line)) "/@v/" (go-sum-version sum-line) ".zip"))
|
||||
|
|
@ -106,6 +119,7 @@
|
|||
lines)
|
||||
(list->vector (map (lambda (pair) (cons (car pair) (list->vector (cdr pair)))) dirs)))
|
||||
|
||||
;; Generates a full VFS structure from an on-disk directory.
|
||||
(define (vfs-from-directory osdir)
|
||||
(define iter-dir #f)
|
||||
(define output '())
|
||||
|
|
@ -125,6 +139,8 @@
|
|||
(iter-dir "")
|
||||
(list->vector output))
|
||||
|
||||
;; Calls `filter` for each file in the virtual filesystem, replacing its
|
||||
;; contents with an empty file if `filter` returns false.
|
||||
(define (filter-vfs vfs filter)
|
||||
(vector-map
|
||||
(lambda (dir)
|
||||
|
|
@ -137,13 +153,15 @@
|
|||
(cdr dir))))
|
||||
vfs))
|
||||
|
||||
; List extracted from go src/go/build/build.go.
|
||||
;; List extracted from go src/go/build/build.go.
|
||||
(define good-extensions '("go" "c" "cc" "cpp" "cxx" "m" "h" "hh" "hpp" "hxx" "f" "F" "for" "f90" "s" "S" "sx" "swig" "swigcxx" "syso"))
|
||||
(define (extract-extension name i)
|
||||
(cond ((char=? (string-ref name i) #\.) (string-copy name (+ i 1)))
|
||||
((= 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.
|
||||
(define (filter-vfs-for-package-reading vfs)
|
||||
(filter-vfs vfs
|
||||
(lambda (dir fname)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue