Each file gets its own tmp dir

This commit is contained in:
Jay McCarthy 2012-05-17 10:28:56 -06:00
parent e12e559878
commit aa3b849382

View File

@ -91,7 +91,10 @@
(define-syntax-rule (with-temporary-directory e) (define-syntax-rule (with-temporary-directory e)
(call-with-temporary-directory (lambda () e))) (call-with-temporary-directory (lambda () e)))
(define (call-with-temporary-planet-directory thunk) (define-syntax-rule
(define-with-temporary-planet-directory with-temporary-planet-directory env-str)
(begin
(define (call-with-temporary-planet-directory thunk)
(define tempdir (define tempdir
(build-path (current-directory) (build-path (current-directory)
(symbol->string (gensym 'planetdir)))) (symbol->string (gensym 'planetdir))))
@ -99,12 +102,14 @@
(lambda () (lambda ()
(make-directory* tempdir)) (make-directory* tempdir))
(lambda () (lambda ()
(with-env (["PLTPLANETDIR" (path->string tempdir)]) (with-env ([env-str (path->string tempdir)])
(thunk))) (thunk)))
(lambda () (lambda ()
(delete-directory/files tempdir)))) (delete-directory/files tempdir))))
(define-syntax-rule (with-temporary-planet-directory e) (define-syntax-rule (with-temporary-planet-directory e)
(call-with-temporary-planet-directory (lambda () e))) (call-with-temporary-planet-directory (lambda () e)))))
(define-with-temporary-planet-directory with-temporary-planet-directory "PLTPLANETDIR")
(define-with-temporary-planet-directory with-temporary-tmp-directory "TMPDIR")
(define (call-with-temporary-home-directory thunk) (define (call-with-temporary-home-directory thunk)
(define new-dir (define new-dir
@ -141,7 +146,7 @@
#f #f
(current-error-port) (current-error-port)
new-command new-args))) new-command new-args)))
; Die if this program does ;; Die if this program does
(define parent (define parent
(current-thread)) (current-thread))
(define waiter (define waiter
@ -151,22 +156,22 @@
(printf "Killing parent because wrapper is dead...\n") (printf "Killing parent because wrapper is dead...\n")
(kill-thread parent)))) (kill-thread parent))))
; Run without stdin ;; Run without stdin
(close-output-port stdin) (close-output-port stdin)
(dynamic-wind (dynamic-wind
void void
; Run the thunk ;; Run the thunk
thunk thunk
(λ () (λ ()
; Close the output ports ;; Close the output ports
#;(close-input-port stdout) #;(close-input-port stdout)
#;(close-input-port stderr) #;(close-input-port stderr)
; Kill the guard ;; Kill the guard
(kill-thread waiter) (kill-thread waiter)
; Kill the process ;; Kill the process
(subprocess-kill the-process #f) (subprocess-kill the-process #f)
(sleep) (sleep)
(subprocess-kill the-process #t)))) (subprocess-kill the-process #t))))
@ -188,14 +193,14 @@
(path->string (build-path trunk-dir "bin" "racket"))) (path->string (build-path trunk-dir "bin" "racket")))
(define raco-path (define raco-path
(path->string (build-path trunk-dir "bin" "raco"))) (path->string (build-path trunk-dir "bin" "raco")))
; XXX Remove ;; XXX Remove
(define mzc-path (define mzc-path
(path->string (build-path trunk-dir "bin" "mzc"))) (path->string (build-path trunk-dir "bin" "mzc")))
(define gracket-path (define gracket-path
(path->string (build-path trunk-dir "bin" "gracket"))) (path->string (build-path trunk-dir "bin" "gracket")))
(define collects-pth (define collects-pth
(build-path trunk-dir "collects")) (build-path trunk-dir "collects"))
; XXX Use a single GUI thread so that other non-GUI apps can run in parallel ;; XXX Use a single GUI thread so that other non-GUI apps can run in parallel
(define gui-lock (make-semaphore 1)) (define gui-lock (make-semaphore 1))
(define test-workers (make-job-queue (number-of-cpus))) (define test-workers (make-job-queue (number-of-cpus)))
(define (test-directory dir-pth upper-sema) (define (test-directory dir-pth upper-sema)
@ -276,6 +281,7 @@
(format ":~a" (format ":~a"
(cpu->child (cpu->child
(current-worker)))]) (current-worker)))])
(with-temporary-tmp-directory
(with-temporary-planet-directory (with-temporary-planet-directory
(with-temporary-home-directory (with-temporary-home-directory
(with-temporary-directory (with-temporary-directory
@ -284,7 +290,7 @@
#:timeout pth-timeout #:timeout pth-timeout
#:env (current-env) #:env (current-env)
(first l) (first l)
(rest l))))))))) (rest l))))))))))
(λ () (λ ()
(semaphore-post dir-sema)))))] (semaphore-post dir-sema)))))]
[else [else
@ -296,14 +302,14 @@
(notify! "Done with dir: ~a" dir-pth) (notify! "Done with dir: ~a" dir-pth)
(write-cache! dir-log (current-seconds)) (write-cache! dir-log (current-seconds))
(semaphore-post upper-sema)))])) (semaphore-post upper-sema)))]))
; Some setup ;; Some setup
(for ([pp (in-list (planet-packages))]) (for ([pp (in-list (planet-packages))])
(match pp (match pp
[`(,auth ,pkg ,majn ,minn ,ver) [`(,auth ,pkg ,majn ,minn ,ver)
(define maj (number->string majn)) (define maj (number->string majn))
(define min (number->string minn)) (define min (number->string minn))
(run/collect/wait/log (run/collect/wait/log
; XXX Give it its own timeout ;; XXX Give it its own timeout
#:timeout (current-make-install-timeout-seconds) #:timeout (current-make-install-timeout-seconds)
#:env (current-env) #:env (current-env)
(build-path log-dir "planet" auth pkg maj min) (build-path log-dir "planet" auth pkg maj min)
@ -317,7 +323,7 @@
(list "-t" (list "-t"
(path->string* (path->string*
(build-path (drdr-directory) "set-browser.rkt")))) (build-path (drdr-directory) "set-browser.rkt"))))
; And go ;; And go
(define top-sema (make-semaphore 0)) (define top-sema (make-semaphore 0))
(notify! "Starting testing") (notify! "Starting testing")
(when (directory-exists? collects-pth) (when (directory-exists? collects-pth)
@ -367,7 +373,7 @@
(make-directory* planet-dir) (make-directory* planet-dir)
(make-directory* home-dir) (make-directory* home-dir)
(make-directory* tmp-dir) (make-directory* tmp-dir)
; We are running inside of a test directory so that random files are stored there ;; We are running inside of a test directory so that random files are stored there
(parameterize ([current-directory test-dir] (parameterize ([current-directory test-dir]
[current-temporary-directory tmp-dir] [current-temporary-directory tmp-dir]
[current-rev rev]) [current-rev rev])
@ -409,7 +415,7 @@
(sleep 2) (sleep 2)
(notify! "Starting test of rev ~a" rev) (notify! "Starting test of rev ~a" rev)
(test-revision rev))))) (test-revision rev)))))
; Remove the test directory ;; Remove the test directory
(safely-delete-directory test-dir)))) (safely-delete-directory test-dir))))
(provide/contract (provide/contract