This repository was archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsci_native_test.clj
executable file
·61 lines (54 loc) · 2.51 KB
/
sci_native_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bb
(ns sci-test-gen-native-image
(:require
[babashka.classpath :as cp]
[clojure.java.io :as io]))
(cp/add-classpath "./script")
(require '[helper.env :as env]
'[helper.graal :as graal]
'[helper.shell :as shell]
'[helper.status :as status])
(defn expose-api-to-sci []
(status/line :info "Expose rewrite-cljc API to sci")
(shell/command ["clojure" "-M:script" "-m" "sci-test-gen-publics"]))
(defn generate-reflection-file [fname]
(status/line :info "Generate reflection file for Graal native-image")
(io/make-parents fname)
(shell/command ["clojure" "-M:sci-test:gen-reflection" fname])
(status/line :detail fname))
(defn interpret-tests []
(status/line :info "Interpreting tests with sci using natively compiled binary")
(let [exe-fname (if (= :win (env/get-os))
"target/sci-test-rewrite-cljc.exe"
"target/sci-test-rewrite-cljc")]
(when (not (.exists (io/file exe-fname)))
(status/fatal (str "native image " exe-fname " not found.") 1))
(shell/command [exe-fname "--file" "script/sci_test_runner.clj" "--classpath" "test"])))
(defn -main [ & _args ]
(env/assert-min-versions)
(let [native-image-xmx "6g"
graal-reflection-fname "target/native-image/reflection.json"
target-exe "target/sci-test-rewrite-cljc"]
(status/line :info "Creating native image for testing via sci")
(status/line :detail "java -version" )
(shell/command ["java" "-version"])
(status/line :detail (str "\nnative-image max memory: " native-image-xmx))
(let [graal-native-image (graal/find-graal-native-image)]
(graal/clean)
(expose-api-to-sci)
(let [classpath (graal/compute-classpath "sci-test:native-image"
"jdk11-reflect:jdk11-reflect-sci")]
(graal/aot-compile-sources classpath "sci-test.main")
(generate-reflection-file graal-reflection-fname)
(graal/run-native-image {:graal-native-image graal-native-image
:graal-reflection-fname graal-reflection-fname
:target-exe target-exe
:classpath classpath
:native-image-xmx native-image-xmx
:entry-class "sci_test.main"})))
(status/line :info "build done")
(status/line :detail (format "built: %s, %d bytes"
target-exe (.length (io/file target-exe)))))
(interpret-tests)
nil)
(-main)