Am I even using this?
This commit is contained in:
parent
5cb0123393
commit
df2d481553
|
@ -21,7 +21,6 @@ let
|
||||||
echo "building namespace: ${ns}"...
|
echo "building namespace: ${ns}"...
|
||||||
java -cp .:${classpath} clojure.main -e "(compile ${ns})"
|
java -cp .:${classpath} clojure.main -e "(compile ${ns})"
|
||||||
'';
|
'';
|
||||||
head-or-null = lst: if (lst == [ ]) then null else head lst;
|
|
||||||
matches-ext = ext: filename: (builtins.match ".+[.]${ext}$" filename) != null;
|
matches-ext = ext: filename: (builtins.match ".+[.]${ext}$" filename) != null;
|
||||||
strip-ext = ext: filename:
|
strip-ext = ext: filename:
|
||||||
head-or-null (builtins.match "(.+)[.]${ext}$" filename);
|
head-or-null (builtins.match "(.+)[.]${ext}$" filename);
|
||||||
|
|
106
mkClojureLib.nix
106
mkClojureLib.nix
|
@ -1,58 +1,96 @@
|
||||||
{ lib, stdenv, callPackage, clojure, jre, writeText, writeShellScript, toEDN }:
|
{ lib, stdenv, callPackage, clojure, jre, writeText, writeShellScript, toEDN }:
|
||||||
{ src, name, group, version, deps-edn, clj-deps, src-paths, build-tools-jar, ...
|
{ src, name, group, version, clj-deps, src-paths, ... }:
|
||||||
}:
|
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
build-tools-deps = toEDN {
|
|
||||||
aliases.build = {
|
|
||||||
extra-deps."'io.github.clojure/tools.build"."local/root" =
|
|
||||||
''\"${build-tools-jar}\"'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
classpath = clj-deps.makeClasspaths { };
|
classpath = clj-deps.makeClasspaths { };
|
||||||
|
deps-jars = splitString ":" classpath;
|
||||||
|
|
||||||
build-deps = callPackage ./deps.nix { };
|
full-name = "${name}-${version}-standalone";
|
||||||
build-classpath = build-deps.makeClasspaths { };
|
|
||||||
|
|
||||||
full-name = "${name}-${version}-standalone.jar";
|
manifest = writeText "MANIFEST.MF" ''
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
|
||||||
target = "$TEMP/target";
|
'';
|
||||||
|
|
||||||
build-script = writeShellScript "create-uberjar.sh" ''
|
extract-jar = jar: ''
|
||||||
HOME=$TEMP/home
|
echo jar -xf ${jar}
|
||||||
mkdir -p $HOME
|
jar -xf ${jar}
|
||||||
mkdir -p ${target}
|
'';
|
||||||
|
|
||||||
clojure \
|
clj-compile = classpath: ns: ''
|
||||||
-Scp ${build-classpath}:${classpath}:${build-tools-jar}:. \
|
echo java -cp .:${classpath} clojure.main -e "(compile ${ns})"
|
||||||
-Sdeps "${build-tools-deps}" \
|
java -cp .:${classpath} clojure.main -e "(compile ${ns})"
|
||||||
-X:build \
|
'';
|
||||||
build/lib-uberjar \
|
|
||||||
:project ${group}/${name} \
|
|
||||||
:version ${version} \
|
|
||||||
:src-dirs ${concatStringsSep "," src-paths} \
|
|
||||||
:target '"${target}"' \
|
|
||||||
:deps-edn '"${deps-edn}"'
|
|
||||||
|
|
||||||
[ $? -eq 0 ] || cat /tmp/*.edn
|
matches-ext = ext: filename: (builtins.match ".+[.]${ext}$" filename) != null;
|
||||||
|
strip-ext = ext: filename:
|
||||||
|
builtins.head (builtins.match "(.+)[.]${ext}$" filename);
|
||||||
|
|
||||||
|
concatMapAttrs = f: attrs: concatLists (mapAttrsToList f attrs);
|
||||||
|
|
||||||
|
find-files = pred: path:
|
||||||
|
let
|
||||||
|
find-files-impl = base:
|
||||||
|
concatMapAttrs (handle-file base) (builtins.readDir base);
|
||||||
|
handle-file = base: name: type:
|
||||||
|
if (type == "directory") then
|
||||||
|
find-files-impl "${base}/${name}"
|
||||||
|
else
|
||||||
|
(if (pred name) then [ "${base}/${name}" ] else [ ]);
|
||||||
|
in find-files-impl path;
|
||||||
|
|
||||||
|
file-to-namespace = base: filename:
|
||||||
|
let
|
||||||
|
swap-chars = replaceStrings [ "_" "/" ] [ "-" "." ];
|
||||||
|
strip-clj = strip-ext "clj";
|
||||||
|
strip-base = replaceStrings [ "${base}/" ] [ "" ];
|
||||||
|
ns = swap-chars (strip-base (strip-clj (toString filename)));
|
||||||
|
in "'${ns}";
|
||||||
|
|
||||||
|
target-namespaces = concatMap (subdir:
|
||||||
|
let dir = src + "/${subdir}";
|
||||||
|
in map (file-to-namespace dir) (find-files (matches-ext "clj") dir))
|
||||||
|
src-paths;
|
||||||
|
|
||||||
|
copy-source-path = target: subdir: "cp -R ${src}/${subdir}/* ${target}";
|
||||||
|
|
||||||
|
build-script = let
|
||||||
|
join-lines = concatStringsSep "\n";
|
||||||
|
srcs = concatStringsSep ":" (map (path: "./${path}") src-paths);
|
||||||
|
in writeShellScript "create-${full-name}-uberjar.sh" ''
|
||||||
|
HOME=./home
|
||||||
|
mkdir $HOME
|
||||||
|
mkdir classes
|
||||||
|
|
||||||
|
mkdir ./deps
|
||||||
|
cd ./deps
|
||||||
|
${join-lines (map extract-jar deps-jars)}
|
||||||
|
cd ..
|
||||||
|
${join-lines
|
||||||
|
(map (clj-compile "${classpath}:${srcs}:./deps") target-namespaces)}
|
||||||
|
mkdir target
|
||||||
|
cp -R classes/* target/
|
||||||
|
${join-lines (map (copy-source-path "./target/") src-paths)}
|
||||||
|
cp -R deps/* target/
|
||||||
|
cp ./deps.edn ./target/deps.edn
|
||||||
|
cd target
|
||||||
|
jar cmf ${manifest} ../out.jar -C . ./*
|
||||||
'';
|
'';
|
||||||
|
|
||||||
pthru = o: builtins.trace o o;
|
pthru = o: builtins.trace o o;
|
||||||
|
|
||||||
in stdenv.mkDerivation {
|
in stdenv.mkDerivation {
|
||||||
name = full-name;
|
name = "${full-name}.jar";
|
||||||
|
|
||||||
src = src;
|
src = src;
|
||||||
|
|
||||||
nativeBuildInputs = [ clojure jre ];
|
nativeBuildInputs = [ jre ];
|
||||||
buildInputs = (map (x: x.paths) clj-deps.packages)
|
buildInputs = map (x: x.paths) clj-deps.packages;
|
||||||
++ (map (x: x.paths) build-deps.packages);
|
|
||||||
|
|
||||||
buildPhase = pthru "${build-script}";
|
buildPhase = "${build-script}";
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mv ${target}/${name}-${version}-standalone.jar $out
|
mv out.jar $out
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue