makefile-targets and some other meta info functions added
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#lang racket
|
||||
|
||||
(require rackunit
|
||||
racket/file
|
||||
racket-makefile
|
||||
(only-in "../private/engine.rkt" reset-makefiles!))
|
||||
|
||||
(reset-makefiles!)
|
||||
|
||||
(define tmp (make-temporary-file "racket-makefile-generated~a" 'directory))
|
||||
(define called '())
|
||||
|
||||
(dynamic-wind
|
||||
void
|
||||
(λ ()
|
||||
(parameterize ([current-directory tmp])
|
||||
(makefile 'stuff
|
||||
(define sources '("foo.c" "bar.c" "baz.c"))
|
||||
|
||||
(for ([src sources])
|
||||
(call-with-output-file src
|
||||
#:exists 'truncate/replace
|
||||
(λ (out)
|
||||
(displayln src out))))
|
||||
|
||||
(define objects
|
||||
(for/list ([src sources])
|
||||
(define obj (path-replace-extension src #".o"))
|
||||
(target obj
|
||||
(deps src)
|
||||
(set! called (append called (list (list $< $target))))
|
||||
(copy-file $< $target #t))
|
||||
obj))
|
||||
|
||||
(default-target 'all)
|
||||
(phony 'all 'clean)
|
||||
|
||||
(target 'all
|
||||
(deps objects))
|
||||
|
||||
(target 'clean
|
||||
(apply rm-f objects)))
|
||||
|
||||
;; Definitions inside makefile remain ordinary module definitions.
|
||||
(check-equal? sources '("foo.c" "bar.c" "baz.c"))
|
||||
(check-equal? (map path->string objects) '("foo.o" "bar.o" "baz.o"))
|
||||
|
||||
(check-equal? (current-makefile-prefix) 'stuff)
|
||||
(check-true (procedure? makefile-target-stuff-all))
|
||||
(check-true (procedure? makefile-target-stuff-clean))
|
||||
|
||||
(check-equal?
|
||||
(makefile-targets 'stuff)
|
||||
(append objects '(all clean)))
|
||||
|
||||
(for ([obj objects])
|
||||
(check-true
|
||||
(procedure?
|
||||
(makefile-target-procedure 'stuff obj))))
|
||||
|
||||
(make 'all)
|
||||
|
||||
(check-equal?
|
||||
called
|
||||
'(("foo.c" "foo.o")
|
||||
("bar.c" "bar.o")
|
||||
("baz.c" "baz.o")))
|
||||
|
||||
(for ([obj objects])
|
||||
(check-true (file-exists? obj)))
|
||||
|
||||
(make 'clean)
|
||||
|
||||
(for ([obj objects])
|
||||
(check-false (file-exists? obj)))))
|
||||
(λ ()
|
||||
(delete-directory/files tmp #:must-exist? #f)))
|
||||
+28
-16
@@ -9,19 +9,19 @@
|
||||
(define calls '())
|
||||
(define context #f)
|
||||
|
||||
(makefile first
|
||||
(default-target status)
|
||||
(phony status all context)
|
||||
(makefile 'first
|
||||
(default-target 'status)
|
||||
(phony 'status 'all 'context)
|
||||
|
||||
(target status
|
||||
(target 'status
|
||||
(set! calls (append calls '(first-status))))
|
||||
|
||||
(target all
|
||||
(deps status)
|
||||
(target 'all
|
||||
(deps 'status)
|
||||
(set! calls (append calls '(first-all))))
|
||||
|
||||
(target context
|
||||
(deps input.txt other.txt)
|
||||
(target 'context
|
||||
(deps 'input.txt 'other.txt)
|
||||
(set! context (list $target $deps $<))))
|
||||
|
||||
(check-equal? (current-makefile-prefix) 'first)
|
||||
@@ -30,6 +30,14 @@
|
||||
(check-true (procedure? makefile-target-first-all))
|
||||
(check-true (procedure? makefile-target-first-context))
|
||||
|
||||
;; The public inspection API preserves definition order and original values.
|
||||
(check-equal? (makefile-prefixes) '(first))
|
||||
(check-equal? (makefile-targets) '(status all context))
|
||||
(check-true (makefile-target-exists? 'status))
|
||||
(check-false (makefile-target-exists? 'missing))
|
||||
(check-eq? (makefile-target-procedure 'status)
|
||||
makefile-target-first-status)
|
||||
|
||||
;; make resolves the target procedure through the active prefix.
|
||||
(make 'all)
|
||||
(check-equal? calls '(first-status first-all))
|
||||
@@ -42,10 +50,10 @@
|
||||
(makefile-target-first-context)
|
||||
(check-equal? context '("context" ("input.txt" "other.txt") "input.txt"))
|
||||
|
||||
(makefile second
|
||||
(default-target status)
|
||||
(phony status)
|
||||
(target status
|
||||
(makefile 'second
|
||||
(default-target 'status)
|
||||
(phony 'status)
|
||||
(target 'status
|
||||
(set! calls (append calls '(second-status)))))
|
||||
|
||||
;; The last makefile definition becomes active.
|
||||
@@ -60,7 +68,11 @@
|
||||
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)
|
||||
;; Both prefixes remain inspectable after switching the active makefile.
|
||||
(check-equal? (makefile-prefixes) '(first second))
|
||||
(check-equal? (makefile-targets 'first) '(status all context))
|
||||
(check-equal? (makefile-targets 'second) '(status))
|
||||
(check-true (makefile-target-exists? 'first 'status))
|
||||
(check-false (makefile-target-exists? 'first 'missing))
|
||||
(check-eq? (makefile-target-procedure 'first 'status)
|
||||
makefile-target-first-status)
|
||||
|
||||
+7
-7
@@ -31,18 +31,18 @@
|
||||
(build-path tmp "Makefile.rkt")
|
||||
"#lang racket"
|
||||
"(require racket-makefile \"slow.rkt\")"
|
||||
"(makefile demo"
|
||||
" (phony change old)"
|
||||
" (target old (displayln \"old\"))"
|
||||
" (target change (copy-file \"NewMakefile.rkt\" \"Makefile.rkt\" #t)))")
|
||||
"(makefile 'demo"
|
||||
" (phony 'change 'old)"
|
||||
" (target 'old (displayln \"old\"))"
|
||||
" (target 'change (copy-file \"NewMakefile.rkt\" \"Makefile.rkt\" #t)))")
|
||||
|
||||
(write-lines
|
||||
(build-path tmp "NewMakefile.rkt")
|
||||
"#lang racket"
|
||||
"(require racket-makefile \"slow.rkt\")"
|
||||
"(makefile demo"
|
||||
" (phony changed)"
|
||||
" (target changed"
|
||||
"(makefile 'demo"
|
||||
" (phony 'changed)"
|
||||
" (target 'changed"
|
||||
" (call-with-output-file \"result.txt\" #:exists 'truncate/replace"
|
||||
" (lambda (out) (display slow-value out)))))")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user