summary refs log tree commit diff
path: root/pkgs/build-support/rust
diff options
context:
space:
mode:
authorAndreas Rammhold <andreas@rammhold.de>2019-12-11 22:27:12 +0100
committerAndreas Rammhold <andreas@rammhold.de>2019-12-11 22:35:44 +0100
commit50b2ef28f72a824efc0dde96094133fc07a36433 (patch)
tree5e9217617b1580a14a9f1af288ee2fa54b18f2df /pkgs/build-support/rust
parent0aac0e8d2c9c129bf1ed868bdc735b738b17b44e (diff)
downloadnixpkgs-50b2ef28f72a824efc0dde96094133fc07a36433.tar
nixpkgs-50b2ef28f72a824efc0dde96094133fc07a36433.tar.gz
nixpkgs-50b2ef28f72a824efc0dde96094133fc07a36433.tar.bz2
nixpkgs-50b2ef28f72a824efc0dde96094133fc07a36433.tar.lz
nixpkgs-50b2ef28f72a824efc0dde96094133fc07a36433.tar.xz
nixpkgs-50b2ef28f72a824efc0dde96094133fc07a36433.tar.zst
nixpkgs-50b2ef28f72a824efc0dde96094133fc07a36433.zip
buildRustCrate: move the color loggign & remove some runtime checks
The expression is already long and confusing enough without the color
stuff sprinkled in. Moving it to a dedicated file makes sense.

I switched a bit of the color support code to pure Nix since there
wasn't much point in doing that in bash while we can just do it in Nix.
Diffstat (limited to 'pkgs/build-support/rust')
-rw-r--r--pkgs/build-support/rust/build-rust-crate/build-crate.nix10
-rw-r--r--pkgs/build-support/rust/build-rust-crate/default.nix52
-rw-r--r--pkgs/build-support/rust/build-rust-crate/log.nix33
3 files changed, 48 insertions, 47 deletions
diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix
index 2cac9df9166..c3880a1fc87 100644
--- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix
+++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix
@@ -15,16 +15,6 @@
     rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}";
   in ''
     runHook preBuild
-    norm=""
-    bold=""
-    green=""
-    boldgreen=""
-    if [[ "${colors}" == "always" ]]; then
-      norm="$(printf '\033[0m')" #returns to "normal"
-      bold="$(printf '\033[0;1m')" #set bold
-      green="$(printf '\033[0;32m')" #set green
-      boldgreen="$(printf '\033[0;1;32m')" #set bold, and set green.
-    fi
     ${echo_build_heading colors}
     ${noisily colors verbose}
 
diff --git a/pkgs/build-support/rust/build-rust-crate/default.nix b/pkgs/build-support/rust/build-rust-crate/default.nix
index 7a3cd12afe0..67e2106ef98 100644
--- a/pkgs/build-support/rust/build-rust-crate/default.nix
+++ b/pkgs/build-support/rust/build-rust-crate/default.nix
@@ -14,7 +14,7 @@ let
       else stdenv.hostPlatform.parsed.kernel.name;
 
     makeDeps = dependencies: crateRenames:
-      (lib.concatMapStringsSep " " (dep:
+      lib.concatMapStringsSep " " (dep:
         let
           extern = lib.replaceStrings ["-"] ["_"] dep.libName;
           name = if lib.hasAttr dep.crateName crateRenames then
@@ -25,42 +25,20 @@ let
            " --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}.rlib"
          else
            " --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
-      ) dependencies);
-
-    echo_build_heading = colors: ''
-      echo_build_heading() {
-       start=""
-       end=""
-       if [[ "${colors}" == "always" ]]; then
-         start="$(printf '\033[0;1;32m')" #set bold, and set green.
-         end="$(printf '\033[0m')" #returns to "normal"
-       fi
-       if (( $# == 1 )); then
-         echo "$start""Building $1""$end"
-       else
-         echo "$start""Building $1 ($2)""$end"
-       fi
-      }
-    '';
-    noisily = colors: verbose: ''
-      noisily() {
-        start=""
-        end=""
-        if [[ "${colors}" == "always" ]]; then
-          start="$(printf '\033[0;1;32m')" #set bold, and set green.
-          end="$(printf '\033[0m')" #returns to "normal"
-        fi
-	${lib.optionalString verbose ''
-            echo -n "$start"Running "$end"
-            echo $@
-	''}
-	$@
-      }
-    '';
-
-    configureCrate = import ./configure-crate.nix { inherit lib stdenv echo_build_heading noisily makeDeps; };
-    buildCrate = import ./build-crate.nix { inherit lib stdenv echo_build_heading noisily makeDeps rust; };
-    installCrate = import ./install-crate.nix;
+      ) dependencies;
+
+
+   inherit (import ./log.nix { inherit lib; }) noisily echo_build_heading;
+
+   configureCrate = import ./configure-crate.nix {
+     inherit lib stdenv echo_build_heading noisily makeDeps;
+   };
+
+   buildCrate = import ./build-crate.nix {
+     inherit lib stdenv echo_build_heading noisily makeDeps rust;
+   };
+
+   installCrate = import ./install-crate.nix;
 in
 
 crate_: lib.makeOverridable ({ rust, release, verbose, features, buildInputs, crateOverrides,
diff --git a/pkgs/build-support/rust/build-rust-crate/log.nix b/pkgs/build-support/rust/build-rust-crate/log.nix
new file mode 100644
index 00000000000..25181c787e2
--- /dev/null
+++ b/pkgs/build-support/rust/build-rust-crate/log.nix
@@ -0,0 +1,33 @@
+{ lib }:
+{
+  echo_build_heading = colors: ''
+    echo_build_heading() {
+     start=""
+     end=""
+     ${lib.optionalString (colors == "always") ''
+       start="$(printf '\033[0;1;32m')" #set bold, and set green.
+       end="$(printf '\033[0m')" #returns to "normal"
+     ''}
+     if (( $# == 1 )); then
+       echo "$start""Building $1""$end"
+     else
+       echo "$start""Building $1 ($2)""$end"
+     fi
+    }
+  '';
+  noisily = colors: verbose: ''
+    noisily() {
+      start=""
+      end=""
+      ${lib.optionalString (colors == "always") ''
+        start="$(printf '\033[0;1;32m')" #set bold, and set green.
+        end="$(printf '\033[0m')" #returns to "normal"
+      ''}
+  	  ${lib.optionalString verbose ''
+        echo -n "$start"Running "$end"
+        echo $@
+  	  ''}
+  	  $@
+    }
+  '';
+}