50 lines
1.4 KiB
Racket
50 lines
1.4 KiB
Racket
#lang racket
|
|
|
|
(require rackunit
|
|
racket/file
|
|
"../private/engine.rkt")
|
|
|
|
(define tmp (make-temporary-file "racket-makefile-engine~a" 'directory))
|
|
|
|
(dynamic-wind
|
|
void
|
|
(lambda ()
|
|
(parameterize ([current-directory tmp]
|
|
[current-command-line-arguments #()])
|
|
(call-with-output-file "input.txt"
|
|
(lambda (out) (display "one" out)))
|
|
|
|
(define build-count 0)
|
|
|
|
(reset-makefile!)
|
|
(set-default-target! 'all)
|
|
(mark-phony! 'all)
|
|
|
|
(register-target!
|
|
"result.txt"
|
|
'("input.txt")
|
|
(lambda ()
|
|
(set! build-count (add1 build-count))
|
|
(copy-file "input.txt" "result.txt" #t)))
|
|
|
|
;; A dependency expression may produce a list. The engine flattens it.
|
|
(register-target! 'all
|
|
(list (list "result.txt"))
|
|
void)
|
|
|
|
(run-selected-target!)
|
|
(check-equal? build-count 1)
|
|
(check-true (file-exists? "result.txt"))
|
|
|
|
;; Nothing changed, so the file target remains up to date.
|
|
(run-selected-target!)
|
|
(check-equal? build-count 1)
|
|
|
|
;; Make the input newer than the output and verify that it rebuilds.
|
|
(define result-time (file-or-directory-modify-seconds "result.txt"))
|
|
(file-or-directory-modify-seconds "input.txt" (+ result-time 2))
|
|
(run-selected-target!)
|
|
(check-equal? build-count 2)))
|
|
(lambda ()
|
|
(delete-directory/files tmp #:must-exist? #f)))
|