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.
This commit is contained in:
Rich Felker 2020-01-21 02:49:07 -05:00
parent 431a47af9e
commit c7557051a5
2 changed files with 112 additions and 15 deletions

View File

@ -26,6 +26,8 @@ LINUX_HEADERS_SITE = http://ftp.barfooze.de/pub/sabotage/tarballs/
DL_CMD = wget -c -O DL_CMD = wget -c -O
COWPATCH = $(PWD)/cowpatch.sh
HOST = $(if $(NATIVE),$(TARGET)) HOST = $(if $(NATIVE),$(TARGET))
BUILD_DIR = build/$(if $(HOST),$(HOST),local)/$(TARGET) BUILD_DIR = build/$(if $(HOST),$(HOST),local)/$(TARGET)
OUTPUT = $(CURDIR)/output$(if $(HOST),-$(HOST)) OUTPUT = $(CURDIR)/output$(if $(HOST),-$(HOST))
@ -97,39 +99,41 @@ musl-git-%:
cd $@.tmp && git fsck cd $@.tmp && git fsck
mv $@.tmp $@ mv $@.tmp $@
%: $(SOURCES)/%.tar.gz | $(SOURCES)/config.sub %.orig: $(SOURCES)/%.tar.gz | $(SOURCES)/config.sub
rm -rf $@.tmp rm -rf $@.tmp
mkdir $@.tmp mkdir $@.tmp
( cd $@.tmp && tar zxvf - ) < $< ( 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 $@ rm -rf $@
touch $@.tmp/$@ touch $@.tmp/$(patsubst %.orig,%,$@)
mv $@.tmp/$@ $@ mv $@.tmp/$(patsubst %.orig,%,$@) $@
rm -rf $@.tmp rm -rf $@.tmp
%: $(SOURCES)/%.tar.bz2 | $(SOURCES)/config.sub %.orig: $(SOURCES)/%.tar.bz2 | $(SOURCES)/config.sub
rm -rf $@.tmp rm -rf $@.tmp
mkdir $@.tmp mkdir $@.tmp
( cd $@.tmp && tar jxvf - ) < $< ( 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 $@ rm -rf $@
touch $@.tmp/$@ touch $@.tmp/$(patsubst %.orig,%,$@)
mv $@.tmp/$@ $@ mv $@.tmp/$(patsubst %.orig,%,$@) $@
rm -rf $@.tmp rm -rf $@.tmp
%: $(SOURCES)/%.tar.xz | $(SOURCES)/config.sub %.orig: $(SOURCES)/%.tar.xz | $(SOURCES)/config.sub
rm -rf $@.tmp rm -rf $@.tmp
mkdir $@.tmp mkdir $@.tmp
( cd $@.tmp && tar Jxvf - ) < $< ( 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 $@ rm -rf $@
touch $@.tmp/$@ touch $@.tmp/$(patsubst %.orig,%,$@)
mv $@.tmp/$@ $@ mv $@.tmp/$(patsubst %.orig,%,$@) $@
rm -rf $@.tmp 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) 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) $@ cd $(BUILD_DIR) && $(MAKE) OUTPUT=$(OUTPUT) $@
endif endif
.SECONDARY:

91
cowpatch.sh Executable file
View File

@ -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 "$@"