revert build.clj changes

This commit is contained in:
Kristin Rutenkolk 2024-06-27 16:07:38 +02:00
parent 56481ea9e3
commit b68f8af549

View file

@ -36,8 +36,9 @@
(defn clean (defn clean
"Deletes the `target/` directory." "Deletes the `target/` directory."
[] [opts]
(b/delete {:path target-dir})) (b/delete {:path target-dir})
opts)
(defn- exists? (defn- exists?
"Checks if a file composed of the given path segments exists." "Checks if a file composed of the given path segments exists."
@ -46,17 +47,18 @@
(defn compile-java (defn compile-java
"Compiles java classes required for interop." "Compiles java classes required for interop."
[] [opts]
(.mkdirs (io/file class-dir)) (.mkdirs (io/file class-dir))
(b/process {:command-args ["javac" "--enable-preview" (b/process {:command-args ["javac" "--enable-preview"
"src/java/coffi/ffi/Loader.java" "src/java/coffi/ffi/Loader.java"
"-d" class-dir "-d" class-dir
"-target" "22" "-target" "22"
"-source" "22"]})) "-source" "22"]})
opts)
(defn- write-pom (defn- write-pom
"Writes a pom file if one does not already exist." "Writes a pom file if one does not already exist."
[] [opts]
(when-not (exists? (b/pom-path {:lib lib-coord (when-not (exists? (b/pom-path {:lib lib-coord
:class-dir class-dir})) :class-dir class-dir}))
(b/write-pom {:basis basis (b/write-pom {:basis basis
@ -70,40 +72,44 @@
:src-dirs source-dirs}) :src-dirs source-dirs})
(b/copy-file {:src (b/pom-path {:lib lib-coord (b/copy-file {:src (b/pom-path {:lib lib-coord
:class-dir class-dir}) :class-dir class-dir})
:target (str target-dir "pom.xml")}))) :target (str target-dir "pom.xml")})
opts))
(defn pom (defn pom
"Generates a `pom.xml` file in the `target/classes/META-INF` directory. "Generates a `pom.xml` file in the `target/classes/META-INF` directory.
If `:pom/output-path` is specified, copies the resulting pom file to it." If `:pom/output-path` is specified, copies the resulting pom file to it."
[opts] [opts]
(write-pom) (write-pom opts)
(when-some [path (:output-path opts)] (when-some [path (:output-path opts)]
(b/copy-file {:src (b/pom-path {:lib lib-coord (b/copy-file {:src (b/pom-path {:lib lib-coord
:class-dir class-dir}) :class-dir class-dir})
:target path}))) :target path}))
opts)
(defn- copy-resources (defn- copy-resources
"Copies the resources from the [[resource-dirs]] to the [[class-dir]]." "Copies the resources from the [[resource-dirs]] to the [[class-dir]]."
[] [opts]
(b/copy-dir {:target-dir class-dir (b/copy-dir {:target-dir class-dir
:src-dirs resource-dirs})) :src-dirs resource-dirs})
opts)
(defn jar (defn jar
"Generates a `coffi.jar` file in the `target/` directory. "Generates a `coffi.jar` file in the `target/` directory.
This is a thin jar including only the sources." This is a thin jar including only the sources."
[opts] [opts]
(write-pom) (write-pom opts)
(compile-java) (compile-java opts)
(copy-resources) (copy-resources opts)
(when-not (exists? target-dir jar-file) (when-not (exists? target-dir jar-file)
(b/copy-dir {:target-dir class-dir (b/copy-dir {:target-dir class-dir
:src-dirs source-dirs}) :src-dirs source-dirs})
(b/jar {:class-dir class-dir (b/jar {:class-dir class-dir
:jar-file jar-file}))) :jar-file jar-file}))
opts)
(defn compile-test-library (defn compile-test-library
"Compiles the C test code for running the tests." "Compiles the C test code for running the tests."
[] [opts]
(let [c-files (->> c-test-dirs (let [c-files (->> c-test-dirs
(map io/file) (map io/file)
(mapcat file-seq) (mapcat file-seq)
@ -112,20 +118,8 @@
(.mkdirs (io/file target-dir)) (.mkdirs (io/file target-dir))
(b/process {:command-args (concat ["clang" "-fpic" "-shared"] (b/process {:command-args (concat ["clang" "-fpic" "-shared"]
c-files c-files
["-o" test-c-library])}))) ["-o" test-c-library])})
opts))
(defn- arities [fn-var] (:arglists (meta fn-var)))
(defn- niladic-only? [fn-var]
(let [ari (arities fn-var)
one-arity? (= 1 (count ari))
niladic? (= 0 (count (first ari)))]
(and one-arity? niladic?)))
(defn- call-optionally [fn-sym arg]
(let [fn-var (resolve fn-sym)]
(if (niladic-only? fn-var)
(fn-var)
(fn-var arg))))
(defn- call-optionally-with [arg] #(call-optionally % arg))
(defn run-tasks (defn run-tasks
"Runs a series of tasks with a set of options. "Runs a series of tasks with a set of options.
@ -133,20 +127,8 @@
the option keys are passed unmodified." the option keys are passed unmodified."
[opts] [opts]
(binding [*ns* (find-ns 'build)] (binding [*ns* (find-ns 'build)]
(run! (call-optionally-with opts) (:tasks opts)))) (reduce
(fn [opts task]
((resolve task) opts))
(def prep-all ['compile-java 'compile-test-library]) opts
(:tasks opts))))
(comment
(compile-java)
(compile-test-library)
(run-tasks prep-all)
(compile-test-library)
)