-
Notifications
You must be signed in to change notification settings - Fork 20
/
transform
executable file
·67 lines (62 loc) · 1.6 KB
/
transform
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
UPSTREAM=$1
shift
TARGET=$1
set -e
COCCI_CACHE_DIR=transform.d/cocci-cache
TRANSFORMATIONS=transform.d/*
DIR=${TARGET%/*}
TMP=$TARGET.tmp
msg()
{
if test "$V"; then
printf "$@"
else
echo -n .
fi
}
mkdir -p $DIR
cp $UPSTREAM $TMP
for TRANS in $TRANSFORMATIONS; do
test -d $TRANS && continue
EXT=${TRANS##*.}
TRANS_NAME=${TRANS##*/}
TARGET_FILE=${TARGET##*/}
case $EXT in
patch)
FIRST_LINE_OF_PATCH="$(grep ^diff < $TRANS)"
PATCH_TARGET=${FIRST_LINE_OF_PATCH##*/}
if [ $PATCH_TARGET = $TARGET_FILE ]; then
msg " PATCH : %-40s %s\n" $TRANS_NAME $TARGET
patch -N --batch --silent $TMP $TRANS
fi
;;
cocci)
mkdir -p $COCCI_CACHE_DIR/$TARGET_FILE
CACHE_FILE=$COCCI_CACHE_DIR/$TARGET_FILE/$TRANS_NAME
CACHE_FILE=${CACHE_FILE/.cocci/.patch}
if test -e $CACHE_FILE && \
test $CACHE_FILE -nt $TRANS && \
test $CACHE_FILE -nt $UPSTREAM && \
patch --batch --dry-run --fuzz 0 --silent $TMP $CACHE_FILE 2> /dev/null > /dev/null; then
msg " CACHED CO: %-40s %s\n" $TRANS_NAME $TARGET
patch --batch --fuzz 0 --silent $TMP $CACHE_FILE
else
msg " GEN COCCI: %-40s %s\n" $TRANS_NAME $TARGET
rm -f "$CACHE_FILE"
spatch --sp-file $TRANS --verbose-parsing --in-place $TMP > $CACHE_FILE.tmp 2> $CACHE_FILE.err
rm $CACHE_FILE.err
mv "$CACHE_FILE.tmp" "$CACHE_FILE"
fi
;;
*)
if test -x $TRANS; then
msg " TRANSFORM: %-40s %s\n" $TRANS_NAME $TARGET
$TRANS $TMP
else
msg " IGNORED : %-40s %s\n" $TRANS_NAME $TARGET
fi
esac
done
mv $TMP $TARGET
msg " MOVE : %-40s %s\n" $TMP $TARGET