Removed rash integration again and backported raco call.

This commit is contained in:
2026-08-17 21:40:48 +02:00
parent 26a0e780c5
commit a21f4a4a39
15 changed files with 716 additions and 1287 deletions
+53 -42
View File
@@ -1,55 +1,66 @@
#lang racket
(require rackunit
racket/file
racket/runtime-path
racket/system)
racket-makefile
(only-in "../private/engine.rkt" reset-makefiles!))
(define-runtime-path package-root "..")
(reset-makefiles!)
(define racket-executable
(find-system-path 'exec-file))
(define calls '())
(define context #f)
(define tmp (make-temporary-file "racket-makefile-make~a" 'directory))
(makefile first
(default-target status)
(phony status all context)
(define (run-racket . args)
(parameterize ([current-directory tmp])
(apply system* racket-executable args)))
(target status
(set! calls (append calls '(first-status))))
(dynamic-wind
void
(lambda ()
(call-with-output-file (build-path tmp "Makefile.rkt")
(lambda (out)
(displayln "#lang racket-makefile" out)
(displayln "(default-target all)" out)
(displayln "(phony all clean 'compile)" out)
(displayln "(target all (call-with-output-file \"all.out\" (lambda (o) (display \"all\" o)) #:exists 'replace))" out)
(displayln "(target clean (rm-f \"all.out\" \"compile.out\"))" out)
;; `compile` is deliberately chosen because Racket already binds that
;; identifier. `(make compile)` must still mean the target named compile.
(displayln "(target 'compile (call-with-output-file \"compile.out\" (lambda (o) (display \"compile\" o)) #:exists 'replace))" out)))
(target all
(deps status)
(set! calls (append calls '(first-all))))
;; Loading the makefile alone must not run any target.
(check-true (run-racket "-t" "Makefile.rkt"))
(check-false (file-exists? (build-path tmp "all.out")))
(target context
(deps input.txt other.txt)
(set! context (list $target $deps $<))))
;; Explicit make invocation from the command line.
(check-true (run-racket "-t" "Makefile.rkt" "-e" "(make all)"))
(check-true (file-exists? (build-path tmp "all.out")))
(check-equal? (current-makefile-prefix) 'first)
(check-true (procedure? make))
(check-true (procedure? makefile-target-first-status))
(check-true (procedure? makefile-target-first-all))
(check-true (procedure? makefile-target-first-context))
;; A bare target identifier is literal, even when Racket binds the same name.
(check-true (run-racket "-t" "Makefile.rkt" "-e" "(make compile)"))
(check-true (file-exists? (build-path tmp "compile.out")))
;; make resolves the target procedure through the active prefix.
(make 'all)
(check-equal? calls '(first-status first-all))
;; Multiple targets are executed in the requested order.
(check-true (run-racket "-t" "Makefile.rkt" "-e" "(make clean all)"))
(check-true (file-exists? (build-path tmp "all.out")))
(check-false (file-exists? (build-path tmp "compile.out")))
;; The generated target is a real Racket procedure and can be called directly.
(makefile-target-first-status)
(check-equal? calls '(first-status first-all first-status))
;; (make) uses the configured default target.
(delete-file (build-path tmp "all.out"))
(check-true (run-racket "-t" "Makefile.rkt" "-e" "(make)"))
(check-true (file-exists? (build-path tmp "all.out"))))
(lambda ()
(delete-directory/files tmp #:must-exist? #f)))
;; Direct procedure calls still get the automatic target variables.
(makefile-target-first-context)
(check-equal? context '("context" ("input.txt" "other.txt") "input.txt"))
(makefile second
(default-target status)
(phony status)
(target status
(set! calls (append calls '(second-status)))))
;; The last makefile definition becomes active.
(check-equal? (current-makefile-prefix) 'second)
(make)
(check-equal? calls '(first-status first-all first-status second-status))
;; Both prefixes remain registered and can be selected explicitly.
(current-makefile-prefix 'first)
(make 'status)
(check-equal?
calls
'(first-status first-all first-status second-status first-status))
;; The registry stores the generated procedure itself.
(check-eq?
(hash-ref makefile-targets '("first" . "status"))
makefile-target-first-status)