Ver Fonte

integrate cowpatch for preservation of original source trees

this makes it far easier to iterate testing of patches, and sets the
stage for enforcing re-patching with makefile-level dependencies.

the pristine sources are kept in directories suffixed with ".orig",
and the unsuffixed directory now contains the result of running
cowpatch -- that is, a mix of symlinks to the original files, and
modified copies of the files/directories affected by patches.
Rich Felker há 5 anos atrás
pai
commit
c7557051a5
2 ficheiros alterados com 112 adições e 15 exclusões
  1. 21 15
      Makefile
  2. 91 0
      cowpatch.sh

+ 21 - 15
Makefile

@@ -26,6 +26,8 @@ LINUX_HEADERS_SITE = http://ftp.barfooze.de/pub/sabotage/tarballs/
 
 DL_CMD = wget -c -O
 
+COWPATCH = $(PWD)/cowpatch.sh
+
 HOST = $(if $(NATIVE),$(TARGET))
 BUILD_DIR = build/$(if $(HOST),$(HOST),local)/$(TARGET)
 OUTPUT = $(CURDIR)/output$(if $(HOST),-$(HOST))
@@ -97,38 +99,40 @@ musl-git-%:
 	cd $@.tmp && git fsck
 	mv $@.tmp $@
 
-%: $(SOURCES)/%.tar.gz | $(SOURCES)/config.sub
+%.orig: $(SOURCES)/%.tar.gz | $(SOURCES)/config.sub
 	rm -rf $@.tmp
 	mkdir $@.tmp
 	( cd $@.tmp && tar zxvf - ) < $<
-	test ! -d patches/$@ || cat patches/$@/* | ( cd $@.tmp/$@ && patch -p1 )
-	test ! -f $@.tmp/$@/config.sub || cp -f $(SOURCES)/config.sub $@.tmp/$@
 	rm -rf $@
-	touch $@.tmp/$@
-	mv $@.tmp/$@ $@
+	touch $@.tmp/$(patsubst %.orig,%,$@)
+	mv $@.tmp/$(patsubst %.orig,%,$@) $@
 	rm -rf $@.tmp
 
-%: $(SOURCES)/%.tar.bz2 | $(SOURCES)/config.sub
+%.orig: $(SOURCES)/%.tar.bz2 | $(SOURCES)/config.sub
 	rm -rf $@.tmp
 	mkdir $@.tmp
 	( cd $@.tmp && tar jxvf - ) < $<
-	test ! -d patches/$@ || cat patches/$@/* | ( cd $@.tmp/$@ && patch -p1 )
-	test ! -f $@.tmp/$@/config.sub || cp -f $(SOURCES)/config.sub $@.tmp/$@
 	rm -rf $@
-	touch $@.tmp/$@
-	mv $@.tmp/$@ $@
+	touch $@.tmp/$(patsubst %.orig,%,$@)
+	mv $@.tmp/$(patsubst %.orig,%,$@) $@
 	rm -rf $@.tmp
 
-%: $(SOURCES)/%.tar.xz | $(SOURCES)/config.sub
+%.orig: $(SOURCES)/%.tar.xz | $(SOURCES)/config.sub
 	rm -rf $@.tmp
 	mkdir $@.tmp
 	( cd $@.tmp && tar Jxvf - ) < $<
-	test ! -d patches/$@ || cat patches/$@/* | ( cd $@.tmp/$@ && patch -p1 )
-	test ! -f $@.tmp/$@/config.sub || cp -f $(SOURCES)/config.sub $@.tmp/$@
 	rm -rf $@
-	touch $@.tmp/$@
-	mv $@.tmp/$@ $@
+	touch $@.tmp/$(patsubst %.orig,%,$@)
+	mv $@.tmp/$(patsubst %.orig,%,$@) $@
+	rm -rf $@.tmp
+
+%: %.orig
 	rm -rf $@.tmp
+	mkdir $@.tmp
+	( cd $@.tmp && ln -s ../$</* . )
+	test ! -d patches/$@ || cat patches/$@/* | ( cd $@.tmp && $(COWPATCH) -p1 )
+	test ! -f $</config.sub || ( rm -f $@.tmp/config.sub && cp -f $(SOURCES)/config.sub $@.tmp/ )
+	mv $@.tmp $@
 
 extract_all: | $(SRC_DIRS)
 
@@ -170,3 +174,5 @@ install: | $(SRC_DIRS) $(BUILD_DIR) $(BUILD_DIR)/Makefile $(BUILD_DIR)/config.ma
 	cd $(BUILD_DIR) && $(MAKE) OUTPUT=$(OUTPUT) $@
 
 endif
+
+.SECONDARY:

+ 91 - 0
cowpatch.sh

@@ -0,0 +1,91 @@
+#!/bin/sh
+#
+# cowpatch.sh, by Rich Felker
+#
+# Permission to use, copy, modify, and/or distribute this software for
+# any purpose with or without fee is hereby granted.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+#
+# Take the above disclaimer seriously! This is an experimental tool
+# still and does not yet take precautions against malformed/malicious
+# patch files like patch(1) does. It may act out-of-tree and clobber
+# stuff you didn't intend for it to clobber.
+#
+
+set -e
+
+echo () { printf "%s\n" "$*" ; }
+
+cow () {
+test -h "$1" || return 0
+if test -d "$1" ; then
+case "$1" in
+*/*) set -- "${1%/*}/" "${1##*/}" ;;
+*) set -- "" "$1" ;;
+esac
+mkdir "$1$2.tmp.$$"
+mv "$1$2" "$1.$2.orig"
+mv "$1$2.tmp.$$" "$1$2"
+( cd "$1$2" && ln -s ../".$2.orig"/* . )
+else
+cp "$1" "$1.tmp.$$"
+mv "$1.tmp.$$" "$1"
+fi
+}
+
+cowp () {
+while test "$1" ; do
+case "$1" in
+*/*) set -- "${1#*/}" "$2${2:+/}${1%%/*}" ;;
+*) set -- "" "$2${2:+/}$1" ;;
+esac
+cow "$2"
+done
+}
+
+cowpatch () {
+
+plev=0
+while getopts ":p:i:RNE" opt ; do
+test "$opt" = p && plev="$OPTARG"
+done
+
+while IFS= read -r l ; do
+case "$l" in
++++*)
+IFS=" 	" read -r junk pfile junk <<EOF
+$l
+EOF
+i=0; while test "$i" -lt "$plev" ; do pfile=${pfile#*/}; i=$((i+1)) ; done
+cowp "$pfile"
+echo "$l"
+;;
+@@*)
+echo "$l"
+IFS=" ," read -r junk junk i junk j junk <<EOF
+$l
+EOF
+while test $i -gt 0 || test $j -gt 0 ; do
+IFS= read -r l
+echo "$l"
+case "$l" in
++*) j=$((j-1)) ;;
+-*) i=$((i-1)) ;;
+*) i=$((i-1)) ; j=$((j-1)) ;;
+esac
+done ;;
+*) echo "$l" ;;
+esac
+done
+
+}
+
+cowpatch "$@" | patch "$@"