Add brp-python-hardlink script
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 27 Jan 2010 12:03:10 +0000 (14:03 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 27 Jan 2010 12:03:10 +0000 (14:03 +0200)
- hardlink identical .pyc and .pyo files to same some space
- not enabled by default
- originally from Ville Skyttä for redhat-rpm-config but the functionality
  is not specific to Fedora or derivates in any way

scripts/Makefile.am
scripts/brp-python-hardlink [new file with mode: 0755]

index 25d5e36..753c4a5 100644 (file)
@@ -6,7 +6,7 @@ CLEANFILES =
 
 EXTRA_DIST = \
        brp-compress brp-python-bytecompile brp-java-gcjcompile \
-       brp-strip brp-strip-comment-note \
+       brp-strip brp-strip-comment-note brp-python-hardlink \
        brp-strip-shared brp-strip-static-archive \
        check-files check-prereqs \
        check-buildroot check-rpaths check-rpaths-worker \
@@ -24,7 +24,7 @@ EXTRA_DIST = \
 
 rpmconfig_SCRIPTS = \
        brp-compress brp-python-bytecompile brp-java-gcjcompile \
-       brp-strip brp-strip-comment-note \
+       brp-strip brp-strip-comment-note brp-python-hardlink \
        brp-strip-shared brp-strip-static-archive \
        check-files check-prereqs \
        check-buildroot check-rpaths check-rpaths-worker \
diff --git a/scripts/brp-python-hardlink b/scripts/brp-python-hardlink
new file mode 100755 (executable)
index 0000000..a937529
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# If using normal root, avoid changing anything.
+if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
+       exit 0
+fi
+
+# Hardlink identical *.pyc and *.pyo, originally from PLD's rpm-build-macros
+# Modified to use sha1sum instead of cmp to avoid a diffutils dependency.
+find "$RPM_BUILD_ROOT" -type f -name "*.pyc" | while read pyc ; do
+       pyo="$(echo $pyc | sed -e 's/.pyc$/.pyo/')"
+       if [ -f "$pyo" ] ; then
+               csha="$(sha1sum -b $pyc | cut -d' ' -f 1)" && \
+               osha="$(sha1sum -b $pyo | cut -d' ' -f 1)" && \
+               if [ "$csha" = "$osha" ] ; then
+                       ln -f "$pyc" "$pyo"
+               fi
+       fi
+done