rust: add-layer after launch-rust-analyzer

This commit is contained in:
Davie Li 2024-01-31 16:33:41 +01:00
parent cbf478cc4f
commit 93f6c9989b
Signed by: davie
GPG key ID: 29FD88532FC91BF4

37
env/rust.scm vendored
View file

@ -28,6 +28,8 @@
init-rustup-environment init-rustup-environment
launch-rust-analyzer)) launch-rust-analyzer))
(define directory-files (@@ (ice-9 ftw) directory-files))
(define rustup-origin (define rustup-origin
(let ((name "rustup") (let ((name "rustup")
(commit "737ad82333742dfd350a733c1649ce4e36109773") (commit "737ad82333742dfd350a733c1649ce4e36109773")
@ -154,9 +156,15 @@ function."
(define* (launch-rustup-environment #:optional home) (define* (launch-rustup-environment #:optional home)
(exec-in-rustup-environment '("/bin/sh") #:home home)) (exec-in-rustup-environment '("/bin/sh") #:home home))
(define* (launch-rust-analyzer env target-name (define* (launch-rust-analyzer env target-sym
#:key #:key
(tag 'current) (share '()) (expose '())) (onto (if (member target-sym
(environment-tags env))
target-sym
'current))
(share '())
(expose '()))
(define controlled-files '(".cargo" ".rustup" ".profile"))
(define (remap w) (define (remap w)
(let ((home (getenv "HOME"))) (let ((home (getenv "HOME")))
(λ (m) (λ (m)
@ -170,13 +178,11 @@ function."
(loop (list s s))) (loop (list s s)))
(throw 'file-doesnt-exist)))))))) (throw 'file-doesnt-exist))))))))
(let* ((target (string-append (@@ (env) %env-directory) "/" target-name)) (let* ((target (string-append (@@ (env) %env-directory)
"/" (symbol->string target-sym)))
;; TODO should actually detect if overlay is mounted not that the ;; TODO should actually detect if overlay is mounted not that the
;; directory exists. ;; directory exists.
(mnt (if (file-exists? target) (mnt (mount-environment env #:tag onto #:target target))
target
(overlay-mount-merged
(mount-environment env #:tag tag #:target target))))
(mappings (append (map (remap #f) expose) (mappings (append (map (remap #f) expose)
(map (remap #t) share)))) (map (remap #t) share))))
(exec-in-rustup-environment '("./.cargo/bin/rust-analyzer") (exec-in-rustup-environment '("./.cargo/bin/rust-analyzer")
@ -184,6 +190,23 @@ function."
#:mappings mappings) #:mappings mappings)
(sync) (sync)
(system* "umount" target) (system* "umount" target)
(with-directory-excursion (overlay-mount-upper mnt)
(for-each (λ (f)
(unless (member f controlled-files)
(format (current-output-port)
"Deleting uncontrolled-file: ~a\n"
f)
(delete-file-recursively f)))
(directory-files ".")))
(if (nil? (directory-files (overlay-mount-upper mnt)))
(display "No files to add\n")
(begin
(display "Adding layer\n")
(apply add-layer
(list env
(overlay-mount-upper mnt)
onto
target-sym))))
(for-each delete-file-recursively (for-each delete-file-recursively
(list target (list target
(overlay-mount-upper mnt) (overlay-mount-upper mnt)