summary refs log tree commit diff
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2016-06-23 11:53:45 +0100
committerzimbatm <zimbatm@zimbatm.com>2016-06-25 14:20:56 +0100
commite71a5cb87841f0af4a2279517b77a9a07ba394c0 (patch)
treec233b5bc126f79effc16d5b9ac60bfa3f1c1ea64
parent7060eaf0bb98f3b4b6d10e7e55d20df9527866bf (diff)
downloadnixlib-e71a5cb87841f0af4a2279517b77a9a07ba394c0.tar
nixlib-e71a5cb87841f0af4a2279517b77a9a07ba394c0.tar.gz
nixlib-e71a5cb87841f0af4a2279517b77a9a07ba394c0.tar.bz2
nixlib-e71a5cb87841f0af4a2279517b77a9a07ba394c0.tar.lz
nixlib-e71a5cb87841f0af4a2279517b77a9a07ba394c0.tar.xz
nixlib-e71a5cb87841f0af4a2279517b77a9a07ba394c0.tar.zst
nixlib-e71a5cb87841f0af4a2279517b77a9a07ba394c0.zip
stdenv: introduce baseHash() to replace stripHash()
stripHash uses a global variable to communicate it's computation
results, but it's not necessary. You can just pipe to stdout in a
subshell. A function mostly behaves like just another command.

baseHash() also introduces a suffix-stripping capability since it's
something the users of the function tend to use.
-rw-r--r--doc/stdenv.xml30
-rw-r--r--nixos/modules/services/networking/ircd-hybrid/builder.sh4
-rw-r--r--pkgs/build-support/vm/default.nix3
-rw-r--r--pkgs/data/fonts/droid/default.nix2
-rw-r--r--pkgs/data/sgml+xml/schemas/xml-dtd/docbook-ebnf/builder.sh3
-rw-r--r--pkgs/stdenv/generic/setup.sh11
-rw-r--r--pkgs/tools/typesetting/tex/nix/animatedot.sh2
-rw-r--r--pkgs/tools/typesetting/tex/nix/default.nix2
-rw-r--r--pkgs/tools/typesetting/tex/nix/dot2pdf.sh2
-rw-r--r--pkgs/tools/typesetting/tex/nix/dot2ps.sh2
-rw-r--r--pkgs/tools/typesetting/tex/nix/lhs2tex.sh2
-rw-r--r--pkgs/tools/typesetting/tex/nix/run-latex.sh4
12 files changed, 38 insertions, 29 deletions
diff --git a/doc/stdenv.xml b/doc/stdenv.xml
index b075e0219a54..99c5d30c2db9 100644
--- a/doc/stdenv.xml
+++ b/doc/stdenv.xml
@@ -1191,31 +1191,35 @@ echo @foo@
     <replaceable>file</replaceable>.</para></listitem>
   </varlistentry>
 
-
-  <varlistentry xml:id='fun-stripHash'>
-    <term><function>stripHash</function>
-    <replaceable>path</replaceable></term>
+  <varlistentry xml:id='fun-baseHash'>
+    <term>
+      <function>baseHash</function>
+      <replaceable>path</replaceable>
+      <replaceable>suffix</replaceable>
+    </term>
     <listitem><para>Strips the directory and hash part of a store
     path, storing the name part in the environment variable
-    <literal>strippedName</literal>. For example:
+    <literal>strippedName</literal>. If <literal>suffix</literal> is also
+    provided, the suffix will also be removed. For example:</para>
     
 <programlisting>
-stripHash "/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
+baseHash "/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
 # prints coreutils-8.24
-echo $strippedName
 </programlisting>
 
-    If you wish to store the result in another variable, then the
-    following idiom may be useful:
-    
 <programlisting>
-name="/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
-someVar=$(stripHash $name; echo $strippedName)
+baseHash "/nix/store/0016702zbydafsr20n9l1dcw7x2bf6jj-arraysugar-0.1.0.gem" .gem
+# prints arraysugar-0.1.0
 </programlisting>
+    </listitem>
 
-    </para></listitem>
   </varlistentry>
 
+  <varlistentry xml:id='fun-stripHash'>
+    <term><function>stripHash</function>
+    <replaceable>path</replaceable></term>
+    <listitem><para>Deprecated. Use baseHash instead.</para></listitem>
+  </varlistentry>
   
 </variablelist>
 
diff --git a/nixos/modules/services/networking/ircd-hybrid/builder.sh b/nixos/modules/services/networking/ircd-hybrid/builder.sh
index f2c92878a4dc..489aa1ca9fbe 100644
--- a/nixos/modules/services/networking/ircd-hybrid/builder.sh
+++ b/nixos/modules/services/networking/ircd-hybrid/builder.sh
@@ -12,7 +12,7 @@ for i in $scripts; do
     if test "$(echo $i | cut -c1-2)" = "=>"; then
         subDir=$(echo $i | cut -c3-)
     else
-        dst=$out/$subDir/$((stripHash $i; echo $strippedName) | sed 's/\.in//')
+        dst=$out/$subDir/$(baseHash $i | sed 's/\.in//')
         doSub $i $dst
         chmod +x $dst # !!!
     fi
@@ -23,7 +23,7 @@ for i in $substFiles; do
     if test "$(echo $i | cut -c1-2)" = "=>"; then
         subDir=$(echo $i | cut -c3-)
     else
-        dst=$out/$subDir/$((stripHash $i; echo $strippedName) | sed 's/\.in//')
+        dst=$out/$subDir/$(baseHash $i | sed 's/\.in//')
         doSub $i $dst
     fi
 done
diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix
index 82cb72cb67ea..3753668bcbfb 100644
--- a/pkgs/build-support/vm/default.nix
+++ b/pkgs/build-support/vm/default.nix
@@ -531,8 +531,7 @@ rec {
 
       # Hacky: RPM looks for <basename>.spec inside the tarball, so
       # strip off the hash.
-      stripHash "$src"
-      srcName="$strippedName"
+      srcName=$(baseHash "$src")
       cp "$src" "$srcName" # `ln' doesn't work always work: RPM requires that the file is owned by root
 
       export HOME=/tmp/home
diff --git a/pkgs/data/fonts/droid/default.nix b/pkgs/data/fonts/droid/default.nix
index 784dfe710078..f78c8240809b 100644
--- a/pkgs/data/fonts/droid/default.nix
+++ b/pkgs/data/fonts/droid/default.nix
@@ -41,7 +41,7 @@ stdenv.mkDerivation rec {
   sourceRoot = "./";
 
   unpackCmd = ''
-    ttfName=$(basename $(stripHash $curSrc; echo $strippedName))
+    ttfName=$(baseHash $curSrc)
     cp $curSrc ./$ttfName
   '';
 
diff --git a/pkgs/data/sgml+xml/schemas/xml-dtd/docbook-ebnf/builder.sh b/pkgs/data/sgml+xml/schemas/xml-dtd/docbook-ebnf/builder.sh
index 70fd729297c0..5504c9f3299c 100644
--- a/pkgs/data/sgml+xml/schemas/xml-dtd/docbook-ebnf/builder.sh
+++ b/pkgs/data/sgml+xml/schemas/xml-dtd/docbook-ebnf/builder.sh
@@ -3,5 +3,4 @@ source $stdenv/setup
 mkdir -p $out/xml/dtd/docbook-ebnf
 cd $out/xml/dtd/docbook-ebnf
 cp -p $dtd dbebnf.dtd
-stripHash $catalog
-cp -p $catalog $strippedName
+cp -p $catalog $(baseHash $catalog)
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index 85e74461d2a4..88300db35bcd 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -484,8 +484,7 @@ dumpVars() {
 }
 
 
-# Utility function: return the base name of the given path, with the
-# prefix `HASH-' removed, if present.
+# DEPRECATED, use baseHash - 2016-06-23
 stripHash() {
     strippedName=$(basename $1);
     if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
@@ -493,6 +492,14 @@ stripHash() {
     fi
 }
 
+# Print NAME with any leading directory components and hash removed. 
+# If specified, also remove a trailing SUFFIX.
+#
+# Usage: baseHash NAME [SUFFIX]
+# Usage: baseName -a [-s SUFFIX] NAME...
+baseHash() {
+  basename "$@" | sed -s 's/^[a-z0-9]\{32\}-//g'
+}
 
 unpackCmdHooks+=(_defaultUnpack)
 _defaultUnpack() {
diff --git a/pkgs/tools/typesetting/tex/nix/animatedot.sh b/pkgs/tools/typesetting/tex/nix/animatedot.sh
index 46a2c515e03a..1b5b2ce50795 100644
--- a/pkgs/tools/typesetting/tex/nix/animatedot.sh
+++ b/pkgs/tools/typesetting/tex/nix/animatedot.sh
@@ -4,6 +4,6 @@ mkdir -p $out
 
 for ((i = 1; i <= $nrFrames; i++)); do
     echo "producing frame $i...";
-    targetName=$out/$(basename $(stripHash $dotGraph; echo $strippedName) .dot)-f-$i.dot
+    targetName=$out/$(baseHash $dotGraph .dot)-f-$i.dot
     cpp -DFRAME=$i < $dotGraph > $targetName
 done
diff --git a/pkgs/tools/typesetting/tex/nix/default.nix b/pkgs/tools/typesetting/tex/nix/default.nix
index ce5c025475a0..0d68f1e85f1f 100644
--- a/pkgs/tools/typesetting/tex/nix/default.nix
+++ b/pkgs/tools/typesetting/tex/nix/default.nix
@@ -185,7 +185,7 @@ rec {
         if test -d $postscript; then
           input=$(ls $postscript/*.ps)
         else
-          input=$(stripHash $postscript; echo $strippedName)
+          input=$(baseHash $postscript)
           ln -s $postscript $input
         fi
 
diff --git a/pkgs/tools/typesetting/tex/nix/dot2pdf.sh b/pkgs/tools/typesetting/tex/nix/dot2pdf.sh
index c416bf235a14..93ea9099ad1b 100644
--- a/pkgs/tools/typesetting/tex/nix/dot2pdf.sh
+++ b/pkgs/tools/typesetting/tex/nix/dot2pdf.sh
@@ -4,7 +4,7 @@ mkdir -p $out
 
 dot2pdf() {
     sourceFile=$1
-    targetName=$out/$(basename $(stripHash $sourceFile; echo $strippedName) .dot).pdf
+    targetName=$out/$(baseHash $sourceFile .dot).pdf
     echo "converting $sourceFile to $targetName..."
     export FONTCONFIG_FILE=$fontsConf
     dot -Tpdf $sourceFile > $targetName
diff --git a/pkgs/tools/typesetting/tex/nix/dot2ps.sh b/pkgs/tools/typesetting/tex/nix/dot2ps.sh
index c70e76ce4c73..81debb09228d 100644
--- a/pkgs/tools/typesetting/tex/nix/dot2ps.sh
+++ b/pkgs/tools/typesetting/tex/nix/dot2ps.sh
@@ -4,7 +4,7 @@ mkdir -p $out
 
 dot2ps() {
     sourceFile=$1
-    targetName=$out/$(basename $(stripHash $sourceFile; echo $strippedName) .dot).ps
+    targetName=$out/$(baseHash $sourceFile .dot).ps
     echo "converting $sourceFile to $targetName..."
     dot -Tps $sourceFile > $targetName
 }
diff --git a/pkgs/tools/typesetting/tex/nix/lhs2tex.sh b/pkgs/tools/typesetting/tex/nix/lhs2tex.sh
index f34b3944c8ef..789d100959b1 100644
--- a/pkgs/tools/typesetting/tex/nix/lhs2tex.sh
+++ b/pkgs/tools/typesetting/tex/nix/lhs2tex.sh
@@ -10,7 +10,7 @@ cd $startDir
 
 lhstex() {
     sourceFile=$1
-    targetName=$out/$(basename $(stripHash $sourceFile; echo $strippedName) .lhs).tex
+    targetName=$out/$(baseHash $sourceFile .lhs).tex
     echo "converting $sourceFile to $targetName..."
     lhs2TeX -o "$targetName" $flags "$sourceFile"
 }
diff --git a/pkgs/tools/typesetting/tex/nix/run-latex.sh b/pkgs/tools/typesetting/tex/nix/run-latex.sh
index fa27520d11cd..97079c476fbc 100644
--- a/pkgs/tools/typesetting/tex/nix/run-latex.sh
+++ b/pkgs/tools/typesetting/tex/nix/run-latex.sh
@@ -16,11 +16,11 @@ for i in $extraFiles; do
     if test -d $i; then
         ln -s $i/* .
     else
-        ln -s $i $(stripHash $i; echo $strippedName)
+        ln -s $i $(baseHash $i)
     fi
 done
 
-rootName=$(basename $(stripHash "$rootFile"; echo $strippedName))
+rootName=$(baseHash "$rootFile")
 
 rootNameBase=$(echo "$rootName" | sed 's/\..*//')