2023-05-04 23:19:34 +02:00
|
|
|
#lang racket
|
|
|
|
|
|
|
|
(provide define-logging
|
|
|
|
log-calls
|
|
|
|
output-bin-path
|
|
|
|
cmd
|
|
|
|
rm
|
2023-05-07 15:53:25 +02:00
|
|
|
copy
|
2023-06-01 16:27:35 +02:00
|
|
|
generate-cgopt-json
|
2023-05-17 21:42:04 +02:00
|
|
|
install-zig
|
2023-05-19 16:23:34 +02:00
|
|
|
install-rust
|
2023-08-19 16:03:22 +02:00
|
|
|
install-roswell
|
2023-10-31 15:51:21 +01:00
|
|
|
build-haxe
|
|
|
|
load-config
|
|
|
|
install-script?)
|
|
|
|
|
|
|
|
;; A parameter containing a predicate string? -> boolean? for checking if a script should be installed.
|
|
|
|
(define install-script? (make-parameter (λ (_) #t)))
|
|
|
|
|
|
|
|
(define-namespace-anchor common-ns)
|
|
|
|
(define (load-config)
|
|
|
|
(let ([path (expand-user-path "~/.config/mzte_localconf/setup-opts.rkts")])
|
|
|
|
(if (file-exists? path)
|
|
|
|
(parameterize ([current-namespace (namespace-anchor->namespace common-ns)])
|
|
|
|
(load path))
|
|
|
|
(fprintf (current-error-port) "no setup-opts found, skipping\n"))))
|
2023-05-04 23:19:34 +02:00
|
|
|
|
|
|
|
;; Whether to log calls or not
|
|
|
|
(define log-calls (make-parameter #t))
|
|
|
|
|
|
|
|
;; Default output path
|
|
|
|
(define output-bin-path (make-parameter (build-path (find-system-path 'home-dir) ".local")))
|
|
|
|
|
|
|
|
(define (display-function-call func args)
|
|
|
|
(when (log-calls)
|
2023-05-04 23:26:57 +02:00
|
|
|
(fprintf (current-error-port)
|
2023-06-01 16:27:35 +02:00
|
|
|
"\x1b[1;30m(\x1b[1;32m~s\x1b[1;33m~a\x1b[1;30m)\x1b[0m\n"
|
2023-05-04 23:26:57 +02:00
|
|
|
func
|
2023-06-01 16:27:35 +02:00
|
|
|
(string-append (if (null? args) "" " ") (apply ~a #:separator " " args)))))
|
2023-05-04 23:19:34 +02:00
|
|
|
|
|
|
|
;; Defines an alias to a function which will log it's parameters on invokation.
|
|
|
|
(define-syntax-rule (define-logging name func)
|
|
|
|
(define (name . args)
|
2023-10-31 15:51:21 +01:00
|
|
|
(display-function-call 'name args)
|
2023-05-04 23:19:34 +02:00
|
|
|
(apply func args)))
|
|
|
|
|
2023-10-31 15:51:21 +01:00
|
|
|
;; Defines a script installer with a backing function which will only run when install-script? returns #t.
|
|
|
|
(define-syntax-rule (define-script-installer name func)
|
|
|
|
(define (name p)
|
|
|
|
(if ((install-script?) p)
|
|
|
|
(begin
|
|
|
|
(display-function-call 'name (list p))
|
|
|
|
(func p))
|
|
|
|
(fprintf (current-error-port) "skipping script ~s\n" p))))
|
|
|
|
|
2023-05-27 21:51:04 +02:00
|
|
|
(define-logging cmd
|
|
|
|
(λ (exe . args)
|
|
|
|
(unless (apply system* (find-executable-path exe) args)
|
|
|
|
(raise-user-error "Command Failed"))))
|
2023-09-10 12:06:24 +02:00
|
|
|
(define-logging rm (λ (path) (delete-directory/files path #:must-exist? false)))
|
2023-05-04 23:19:34 +02:00
|
|
|
(define-logging copy copy-directory/files)
|
2023-05-07 15:53:25 +02:00
|
|
|
|
2023-10-31 15:51:21 +01:00
|
|
|
(define-script-installer
|
|
|
|
install-zig
|
2023-05-27 01:27:08 +02:00
|
|
|
(λ (path [mode "ReleaseFast"])
|
|
|
|
(parameterize ([current-directory path] [log-calls #f])
|
|
|
|
(cmd "zig" "build" "-p" (output-bin-path) (string-append "-Doptimize=" mode)))))
|
2023-05-17 21:42:04 +02:00
|
|
|
|
2023-10-31 15:51:21 +01:00
|
|
|
(define-script-installer install-rust
|
2023-05-27 01:27:08 +02:00
|
|
|
(λ (path)
|
|
|
|
(parameterize ([current-directory path] [log-calls #f])
|
|
|
|
(cmd "cargo"
|
|
|
|
"-Z"
|
|
|
|
"unstable-options"
|
|
|
|
"build"
|
|
|
|
"--release"
|
|
|
|
"--out-dir"
|
|
|
|
(build-path (output-bin-path) "bin")))))
|
2023-05-19 16:23:34 +02:00
|
|
|
|
2023-08-19 16:03:22 +02:00
|
|
|
(define-logging build-haxe
|
|
|
|
(λ (path)
|
|
|
|
(parameterize ([current-directory path] [log-calls #f])
|
|
|
|
(cmd "haxe" "build.hxml"))))
|
|
|
|
|
2023-06-01 16:27:35 +02:00
|
|
|
(define-logging generate-cgopt-json
|
|
|
|
(λ ()
|
|
|
|
(unless (directory-exists? "cgout")
|
|
|
|
(make-directory "cgout"))
|
2023-10-31 15:51:21 +01:00
|
|
|
(call-with-output-file* #:exists 'truncate/replace
|
|
|
|
"cgout/opts.json"
|
|
|
|
(λ (outfile)
|
|
|
|
(parameterize ([log-calls #f]
|
|
|
|
[current-output-port outfile])
|
|
|
|
(cmd "confgen" "--json-opt" "confgen.lua"))))))
|
2023-06-01 16:27:35 +02:00
|
|
|
|
2023-10-31 15:51:21 +01:00
|
|
|
(define-script-installer
|
2023-05-27 01:27:08 +02:00
|
|
|
install-roswell
|
|
|
|
(λ (path)
|
|
|
|
(parameterize ([log-calls #f])
|
|
|
|
(match-let*-values ([(_ filename _) (split-path path)]
|
|
|
|
[(outpath)
|
|
|
|
(build-path (output-bin-path) "bin" (path-replace-extension filename ""))])
|
|
|
|
(cmd "ros" "dump" "executable" path "-o" outpath)))))
|