git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commite71a5cb87841f0af4a2279517b77a9a07ba394c0 authorzimbatm <zimbatm@zimbatm.com> dateThu 23 Jun 2016, 11:53 (10 years ago) parent7060eaf
12 files changed+38−29
doc/stdenv.xml+17−13 nixos/modules/services/networking/ircd-hybrid/builder.sh+2−2 pkgs/build-support/vm/default.nix+1−2 pkgs/data/fonts/droid/default.nix+1−1 pkgs/data/sgml+xml/schemas/xml-dtd/docbook-ebnf/builder.sh+1−2 pkgs/stdenv/generic/setup.sh+9−2 pkgs/tools/typesetting/tex/nix/animatedot.sh+1−1 pkgs/tools/typesetting/tex/nix/default.nix+1−1 pkgs/tools/typesetting/tex/nix/dot2pdf.sh+1−1 pkgs/tools/typesetting/tex/nix/dot2ps.sh+1−1 pkgs/tools/typesetting/tex/nix/lhs2tex.sh+1−1 pkgs/tools/typesetting/tex/nix/run-latex.sh+2−2
doc/stdenv.xml+17−13
@@ -1191,31 +1191,35 @@ echo @foo@
11911191 <replaceable>file</replaceable>.</para></listitem>
11921192 </varlistentry>
11931193
1194−
1195− <varlistentry xml:id='fun-stripHash'>
1196− <term><function>stripHash</function>
1197− <replaceable>path</replaceable></term>
1194+ <varlistentry xml:id='fun-baseHash'>
1195+ <term>
1196+ <function>baseHash</function>
1197+ <replaceable>path</replaceable>
1198+ <replaceable>suffix</replaceable>
1199+ </term>
11981200 <listitem><para>Strips the directory and hash part of a store
11991201 path, storing the name part in the environment variable
1200− <literal>strippedName</literal>. For example:
1202+ <literal>strippedName</literal>. If <literal>suffix</literal> is also
1203+ provided, the suffix will also be removed. For example:</para>
12011204
12021205<programlisting>
1203−stripHash "/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
1206+baseHash "/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
12041207# prints coreutils-8.24
1205−echo $strippedName
12061208</programlisting>
12071209
1208− If you wish to store the result in another variable, then the
1209− following idiom may be useful:
1210−
12111210<programlisting>
1212−name="/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
1213−someVar=$(stripHash $name; echo $strippedName)
1211+baseHash "/nix/store/0016702zbydafsr20n9l1dcw7x2bf6jj-arraysugar-0.1.0.gem" .gem
1212+# prints arraysugar-0.1.0
12141213</programlisting>
1214+ </listitem>
12151215
1216− </para></listitem>
12171216 </varlistentry>
12181217
1218+ <varlistentry xml:id='fun-stripHash'>
1219+ <term><function>stripHash</function>
1220+ <replaceable>path</replaceable></term>
1221+ <listitem><para>Deprecated. Use baseHash instead.</para></listitem>
1222+ </varlistentry>
12191223
12201224</variablelist>
12211225
nixos/modules/services/networking/ircd-hybrid/builder.sh+2−2
@@ -12,7 +12,7 @@ for i in $scripts; do
1212 if test "$(echo $i | cut -c1-2)" = "=>"; then
1313 subDir=$(echo $i | cut -c3-)
1414 else
15− dst=$out/$subDir/$((stripHash $i; echo $strippedName) | sed 's/\.in//')
15+ dst=$out/$subDir/$(baseHash $i | sed 's/\.in//')
1616 doSub $i $dst
1717 chmod +x $dst # !!!
1818 fi
@@ -23,7 +23,7 @@ for i in $substFiles; do
2323 if test "$(echo $i | cut -c1-2)" = "=>"; then
2424 subDir=$(echo $i | cut -c3-)
2525 else
26− dst=$out/$subDir/$((stripHash $i; echo $strippedName) | sed 's/\.in//')
26+ dst=$out/$subDir/$(baseHash $i | sed 's/\.in//')
2727 doSub $i $dst
2828 fi
2929done
pkgs/build-support/vm/default.nix+1−2
@@ -531,8 +531,7 @@ rec {
531531
532532 # Hacky: RPM looks for <basename>.spec inside the tarball, so
533533 # strip off the hash.
534− stripHash "$src"
535− srcName="$strippedName"
534+ srcName=$(baseHash "$src")
536535 cp "$src" "$srcName" # `ln' doesn't work always work: RPM requires that the file is owned by root
537536
538537 export HOME=/tmp/home
pkgs/data/fonts/droid/default.nix+1−1
@@ -41,7 +41,7 @@ stdenv.mkDerivation rec {
4141 sourceRoot = "./";
4242
4343 unpackCmd = ''
44− ttfName=$(basename $(stripHash $curSrc; echo $strippedName))
44+ ttfName=$(baseHash $curSrc)
4545 cp $curSrc ./$ttfName
4646 '';
4747
pkgs/data/sgml+xml/schemas/xml-dtd/docbook-ebnf/builder.sh+1−2
@@ -3,5 +3,4 @@ source $stdenv/setup
33mkdir -p $out/xml/dtd/docbook-ebnf
44cd $out/xml/dtd/docbook-ebnf
55cp -p $dtd dbebnf.dtd
6−stripHash $catalog
7−cp -p $catalog $strippedName
6+cp -p $catalog $(baseHash $catalog)
pkgs/stdenv/generic/setup.sh+9−2
@@ -484,8 +484,7 @@ dumpVars() {
484484}
485485
486486
487−# Utility function: return the base name of the given path, with the
488−# prefix `HASH-' removed, if present.
487+# DEPRECATED, use baseHash - 2016-06-23
489488stripHash() {
490489 strippedName=$(basename $1);
491490 if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
@@ -493,6 +492,14 @@ stripHash() {
493492 fi
494493}
495494
495+# Print NAME with any leading directory components and hash removed.
496+# If specified, also remove a trailing SUFFIX.
497+#
498+# Usage: baseHash NAME [SUFFIX]
499+# Usage: baseName -a [-s SUFFIX] NAME...
500+baseHash() {
501+ basename "$@" | sed -s 's/^[a-z0-9]\{32\}-//g'
502+}
496503
497504unpackCmdHooks+=(_defaultUnpack)
498505_defaultUnpack() {
pkgs/tools/typesetting/tex/nix/animatedot.sh+1−1
@@ -4,6 +4,6 @@ mkdir -p $out
44
55for ((i = 1; i <= $nrFrames; i++)); do
66 echo "producing frame $i...";
7− targetName=$out/$(basename $(stripHash $dotGraph; echo $strippedName) .dot)-f-$i.dot
7+ targetName=$out/$(baseHash $dotGraph .dot)-f-$i.dot
88 cpp -DFRAME=$i < $dotGraph > $targetName
99done
pkgs/tools/typesetting/tex/nix/default.nix+1−1
@@ -185,7 +185,7 @@ rec {
185185 if test -d $postscript; then
186186 input=$(ls $postscript/*.ps)
187187 else
188− input=$(stripHash $postscript; echo $strippedName)
188+ input=$(baseHash $postscript)
189189 ln -s $postscript $input
190190 fi
191191
pkgs/tools/typesetting/tex/nix/dot2pdf.sh+1−1
@@ -4,7 +4,7 @@ mkdir -p $out
44
55dot2pdf() {
66 sourceFile=$1
7− targetName=$out/$(basename $(stripHash $sourceFile; echo $strippedName) .dot).pdf
7+ targetName=$out/$(baseHash $sourceFile .dot).pdf
88 echo "converting $sourceFile to $targetName..."
99 export FONTCONFIG_FILE=$fontsConf
1010 dot -Tpdf $sourceFile > $targetName
pkgs/tools/typesetting/tex/nix/dot2ps.sh+1−1
@@ -4,7 +4,7 @@ mkdir -p $out
44
55dot2ps() {
66 sourceFile=$1
7− targetName=$out/$(basename $(stripHash $sourceFile; echo $strippedName) .dot).ps
7+ targetName=$out/$(baseHash $sourceFile .dot).ps
88 echo "converting $sourceFile to $targetName..."
99 dot -Tps $sourceFile > $targetName
1010}
pkgs/tools/typesetting/tex/nix/lhs2tex.sh+1−1
@@ -10,7 +10,7 @@ cd $startDir
1010
1111lhstex() {
1212 sourceFile=$1
13− targetName=$out/$(basename $(stripHash $sourceFile; echo $strippedName) .lhs).tex
13+ targetName=$out/$(baseHash $sourceFile .lhs).tex
1414 echo "converting $sourceFile to $targetName..."
1515 lhs2TeX -o "$targetName" $flags "$sourceFile"
1616}
pkgs/tools/typesetting/tex/nix/run-latex.sh+2−2
@@ -16,11 +16,11 @@ for i in $extraFiles; do
1616 if test -d $i; then
1717 ln -s $i/* .
1818 else
19− ln -s $i $(stripHash $i; echo $strippedName)
19+ ln -s $i $(baseHash $i)
2020 fi
2121done
2222
23−rootName=$(basename $(stripHash "$rootFile"; echo $strippedName))
23+rootName=$(baseHash "$rootFile")
2424
2525rootNameBase=$(echo "$rootName" | sed 's/\..*//')
2626