-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.clj
104 lines (87 loc) · 3.38 KB
/
build.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(ns build
"Tasks for compiling and building artifacts for deployment.
Each task will check to see if its output has already been computed, and if it
has, it will not execute. To resolve this, just run [[clean]] first.
Tasks can be chained with the default function, [[run-tasks]], which runs each
of a sequence of tasks in order, passing the options map from one to the next.
Each task takes arguments in its options of a form `:task-name/option` so that
when the options map is passed between them no conflicts will arise.
While these tasks do construct artifacts, they do not provide for making
deployments. Use the `:deploy` alias to deploy to clojars."
(:require
[clojure.java.io :as io]
[clojure.tools.build.api :as b]))
(def lib-coord 'org.suskalo/glfw-clj)
(def version (format "1.0.%s" (b/git-count-revs nil)))
(def resource-dirs ["resources/"])
(def source-dirs ["src/"])
(def target-dir "target/")
(def class-dir (str target-dir "classes/"))
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (str target-dir "glfw-clj.jar"))
(defn clean
"Deletes the `target/` directory."
[opts]
(b/delete {:path target-dir})
opts)
(defn- exists?
"Checks if a file composed of the given path segments exists."
[& path-components]
(.exists ^java.io.File (apply io/file path-components)))
(defn- write-pom
"Writes a pom file if one does not already exist."
[opts]
(when-not (exists? (b/pom-path {:lib lib-coord
:class-dir class-dir}))
(b/write-pom {:basis basis
:class-dir class-dir
:lib lib-coord
:version version
:scm {:url "https://github.com/IGJoshua/glfw-clj"
:connection "scm:git:git://github.com/IGJoshua/glfw-clj.git"
:developerConnection "scm:git:ssh://[email protected]/IGJoshua/glfw-clj.git"
:tag (str "v" version)}
:src-dirs source-dirs})
(b/copy-file {:src (b/pom-path {:lib lib-coord
:class-dir class-dir})
:target (str target-dir "pom.xml")}))
opts)
(defn pom
"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."
[opts]
(write-pom opts)
(when-some [path (:output-path opts)]
(b/copy-file {:src (b/pom-path {:lib lib-coord
:class-dir class-dir})
:target path}))
opts)
(defn- copy-resources
"Copies the resources from the [[resource-dirs]] to the [[class-dir]]."
[opts]
(b/copy-dir {:target-dir class-dir
:src-dirs resource-dirs})
opts)
(defn jar
"Generates a `coffi.jar` file in the `target/` directory.
This is a thin jar including only the sources."
[opts]
(write-pom opts)
(copy-resources opts)
(when-not (exists? target-dir jar-file)
(b/copy-dir {:target-dir class-dir
:src-dirs source-dirs})
(b/jar {:class-dir class-dir
:jar-file jar-file}))
opts)
(defn run-tasks
"Runs a series of tasks with a set of options.
The `:tasks` key is a list of symbols of other task names to call. The rest of
the option keys are passed unmodified."
[opts]
(binding [*ns* (find-ns 'build)]
(reduce
(fn [opts task]
((resolve task) opts))
opts
(:tasks opts))))