Add build.clj

This commit is contained in:
niten 2022-06-02 12:24:10 -07:00
parent 93d3ce91ed
commit bf8e3c7c0d
4 changed files with 61 additions and 63 deletions

View File

@ -1,34 +1,24 @@
{ lib, stdenv, clojure, gitignoreSource, callPackage, writeText
, writeShellScript, ... }:
{ lib, stdenv, clojure, fetchgit, fetchMavenArtifact, gitignoreSource
, callPackage, writeText, writeShellScript, ... }:
let
base-name = "bebot";
version = "0.1";
full-name = "${base-name}-${version}";
jar-name = "${base-name}.jar";
cljdeps = callPackage ./deps.nix { };
uberdeps-edn =
writeText "deps.edn" ''{:deps {uberdeps/uberdeps {:mvn/version "1.1.4"}}}'';
uberdeps-script = writeShellScript "bebot-uberdeps.sh" ''
SRC=$1
TARGET=$2
clojure -M -m uberdeps.uberjar --deps-file $SRC/deps.edn --target $TARGET
'';
cljdeps = callPackage ./deps.nix { inherit fetchgit fetchMavenArtifact lib; };
classpath = cljdeps.makeClasspaths { };
in stdenv.mkDerivation {
name = full-name;
name = "${full-name}.jar";
src = gitignoreSource ./.;
outputs = [ "lib" ];
buildInputs = [ clojure ] ++ map (d: d.paths) cljdeps.packages;
buildPhase = ''
mkdir $TEMP/build
cd $TEMP/build
cp ${uberdeps-edn} .
${uberdeps-script} $src ./${jar-name}
HOME=./home
mkdir -p $HOME
clojure -Scp ${classpath} -X:build build/uberjar :project org.fudo/bebot :version 0.1
'';
installPhase = ''
cp ./target/${jar-name} $out
cp ./target/bebot-${version}-standalone.jar $out
'';
}

View File

@ -1,44 +0,0 @@
(ns build
(:require [clojure.tools.build.api :as b]))
(def target-dir "./target")
(def class-dir (format "%s/classes" target-dir))
(def lib-name 'org.fudo/bebop.client)
(def version (format "0.%s" (b/git-count-revs nil)))
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "%s/%s-%s.jar"
target-dir (name lib-name) version))
(def uber-file (format "%s/%s-%s-standalone.jar"
target-dir (name lib-name) version))
(defn clean [_]
(println (format "removing build target folder \"%s\"" target-dir))
(b/delete {:path target-dir}))
(defn jar [_]
(clean nil)
(b/copy-dir {:src-dirs ["src"]
:target-dir target-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/write-pom {:class-dir class-dir
:lib lib-name
:version version
:basis basis
:src-dirs ["src"]})
(b/jar {:class-dir class-dir
:jar-file jar-file})
(println (format "jar file created at: %s" jar-file)))
(defn uberjar [_]
(clean nil)
(b/copy-dir {:src-dirs ["src"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis basis})
(println (format "uberjar file created at: %s" uber-file)))

View File

@ -11,6 +11,11 @@
:git/url "https://git.fudo.org/fudo-public/fudo-clojure.git"
:sha "2d9303f55f7eac9c2f8989e9a0dde3dc97811220"
}
io.github.clojure/tools.build {
:git/url "https://github.com/clojure/tools.build.git"
:sha "ba1a2bf421838802e7bdefc541b41f57582e53b6"
}
}
:aliases {
:test {
@ -25,5 +30,6 @@
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test
}
:build { :default-ns build }
}
}

46
src/build.clj Normal file
View File

@ -0,0 +1,46 @@
(ns build
(:require [clojure.tools.build.api :as b]))
(def target-dir "./target")
(def class-dir (format "%s/classes" target-dir))
(def basis (b/create-basis {:project "deps.edn"}))
(defn mk-jar-file [lib-name version]
(format "%s/%s-%s.jar"
target-dir (name lib-name) version))
(defn mk-uberjar-file [lib-name version]
(format "%s/%s-%s-standalone.jar"
target-dir (name lib-name) version))
(defn clean [_]
(println (format "removing build target folder \"%s\"" target-dir))
(b/delete {:path target-dir}))
(defn jar [{:keys [project version]}]
(let [jar-file (mk-jar-file project version)]
(clean nil)
(b/copy-dir {:src-dirs ["src"]
:target-dir target-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/write-pom {:class-dir class-dir
:lib project
:version version
:basis basis
:src-dirs ["src"]})
(b/jar {:class-dir class-dir
:jar-file jar-file})
(println (format "jar file created at: %s" jar-file))))
(defn uberjar [{:keys [project version]}]
(let [uber-file (mk-uberjar-file project version)]
(clean nil)
(b/copy-dir {:src-dirs ["src"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis basis})
(println (format "uberjar file created at: %s" uber-file))))