Initial import

This commit is contained in:
2026-08-08 14:32:18 +02:00
parent be2baa9280
commit f32503f3e7
11 changed files with 689 additions and 76 deletions
+49
View File
@@ -0,0 +1,49 @@
#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)))
+31
View File
@@ -0,0 +1,31 @@
#lang racket
(require rackunit
racket/file
(only-in racket-makefile rm-f rm-rf cleanup))
(define tmp (make-temporary-file "racket-makefile-test~a" 'directory))
(dynamic-wind
void
(lambda ()
(define file (build-path tmp "x.tmp"))
(call-with-output-file file (lambda (out) (display "x" out)))
(check-true (file-exists? file))
(rm-f file)
(check-false (file-exists? file))
(define nested (build-path tmp "a" "b"))
(make-directory* nested)
(define html (build-path nested "x.html"))
(define txt (build-path nested "x.txt"))
(call-with-output-file html (lambda (out) (display "html" out)))
(call-with-output-file txt (lambda (out) (display "txt" out)))
(cleanup tmp '("**.html"))
(check-false (file-exists? html))
(check-true (file-exists? txt))
(rm-rf (build-path tmp "a"))
(check-false (directory-exists? (build-path tmp "a"))))
(lambda ()
(delete-directory/files tmp #:must-exist? #f)))