From 31629acbb0c7ef16670756690fa3f1c3df49b0e8 Mon Sep 17 00:00:00 2001 From: niten Date: Wed, 1 Jun 2022 09:37:39 -0700 Subject: [PATCH] Evolving, not working --- build.tools.nix | 52 ++++++++++++++++++++++++++++++++++++++++++------ flake.nix | 1 + mkClojureLib.nix | 2 +- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/build.tools.nix b/build.tools.nix index 821779c..34a5c41 100644 --- a/build.tools.nix +++ b/build.tools.nix @@ -1,10 +1,9 @@ { lib, stdenv, build-tools-src, clojure, callPackage, writeText -, writeShellScript, gitignoreSource, jre, ... }: +, writeShellScript, gitignoreSource, jre, version, ... }: with lib; let base-name = "clojure-build-tools"; - version = "0.8.2"; full-name = "${base-name}-${version}.jar"; cljdeps = callPackage ./deps.nix { }; tools-classpath = cljdeps.makeClasspaths { }; @@ -21,8 +20,7 @@ let java-compile = classpath: ns: ''java -cp .:${classpath} clojure.main -e "(compile ${ns})"''; head-or-null = lst: if (lst == [ ]) then null else head lst; - matches-ext = ext: filename: type: - (builtins.match ".+[.]${ext}$" filename) != null; + matches-ext = ext: filename: (builtins.match ".+[.]${ext}$" filename) != null; strip-ext = ext: filename: head-or-null (builtins.match "(.+)[.]${ext}$" filename); ext-files = ext: path: @@ -33,7 +31,32 @@ let task-namespaces = map (ns: "'clojure.tools.build.tasks.${ns}") tasks; all-namespaces = task-namespaces ++ [ "'clojure.tools.build.api" ]; + 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}"; + + 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; + + tools-namespaces = let base = "${build-tools-src}/src/main/clojure"; + in map (file-to-namespace base) (find-files (matches-ext "clj") base); + in stdenv.mkDerivation { + name = full-name; src = gitignoreSource "${build-tools-src}/src/main/clojure"; nativeBuildInputs = [ jre ]; @@ -45,8 +68,25 @@ in stdenv.mkDerivation { cp ${./src}/build.clj . ${concatStringsSep "\n" (map extract-jar dep-jars)} ${concatStringsSep "\n" - (map (java-compile tools-classpath) (all-namespaces ++ [ "'build" ]))} - jar cmf ${manifest} ./out.jar -C . cljs cognitect com javax mozilla plugin.xml about.html clojure cognitect_aws_http.edn data_readers.cljc licenses org + (map (java-compile tools-classpath) (tools-namespaces ++ [ "'build" ]))} + jar cmf ${manifest} ./out.jar -C . ${ + concatStringsSep " " [ + "build" + "cljs" + "cognitect" + "com" + "javax" + "mozilla" + "plugin.xml" + "about.html" + "clojure" + "cognitect_aws_http.edn" + "data_readers.cljc" + "licenses" + "org" + ] + } + cat /tmp/*.edn ''; in "${build-script}"; diff --git a/flake.nix b/flake.nix index 3296ee0..afc3fbd 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,7 @@ system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages."${system}"; build-tools-jar = pkgs.callPackage ./build.tools.nix { + version = "0.8.2"; inherit build-tools-src; inherit (gitignore.lib) gitignoreSource; }; diff --git a/mkClojureLib.nix b/mkClojureLib.nix index 7ac7f08..8b30385 100644 --- a/mkClojureLib.nix +++ b/mkClojureLib.nix @@ -42,7 +42,7 @@ in stdenv.mkDerivation { nativeBuildInputs = [ clojure jre ]; buildInputs = (map (x: x.paths) clj-deps.packages); - buildPhase = builtins.trace "${build-script}" "${build-script}"; + buildPhase = "${build-script}"; installPhase = '' mv ${target}/${name}-${version}-standalone.jar $out