-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiffevents.sh
executable file
·106 lines (95 loc) · 2.93 KB
/
diffevents.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
mapp() { while IFS= read -r line; do "$1" "$2" "$line"; done; }
hashKey() {
# replace non-alphanumeric characters with underscore to make keys valid BASH identifiers
echo "$1_$2" | sed -E "s/[^a-zA-Z0-9]+/_/g" | sed -E "s/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+\$//g"
}
hashPut() {
local KEY=$(hashKey "$1" "$2")
eval "$KEY"="$3"
}
hashGet() {
local KEY=$(hashKey "$1" "$2")
echo "${!KEY}"
}
MC_VER=0
lastVer=""
readarray -d '' entries < <(printf '%s\0' versionProperties/*.properties | sort -zV)
for entry in "${entries[@]}"; do
entry="${entry:18:6}"
lastVer="$entry"
hashPut MC "$entry" "$MC_VER"
((++MC_VER))
done
lastFile=""
allowIfLayer=()
function g2() {
ver="$(hashGet MC "$1")"
currFile="$(cut -d : -f 1 <<< "$2")"
line="$(cut -d : -f 2 <<< "$2")"
if [[ "${line:0:3}" == "#if" ]]; then
if [[ "${#allowIfLayer[@]}" -ne "0" && "${allowIfLayer[-1]}" -ne "0" ]]; then
# auto deny if previous layer is denied
allowIfLayer+=("1")
else
ifcond="$(sed -re 's/#if MC_VER ([^ ]+) MC_([0-9]+_[0-9]+(_[0-9]+)?)(.+?)/\1/' <<< "$line")"
ifver="$(sed -re 's/#if MC_VER ([^ ]+) MC_([0-9]+_[0-9]+(_[0-9]+)?)(.+?)/\2/' <<< "$line")"
tooMuch="$(sed -re 's/#if MC_VER ([^ ]+) MC_([0-9]+_[0-9]+(_[0-9]+)?)(.+?)/\2/' <<< "$line")"
if [[ -z "$tooMuch" ]]; then
echo "Too much triggered for line: $line"
exit 1
fi
# 0 if matches
matches=0
ifver="$(hashGet MC "$ifver")"
case "$ifcond" in
"==")
matches=$( [[ "$ver" -eq "$ifver" ]] ; echo $? )
;;
"!=")
matches=$( [[ "$ver" -ne "$ifver" ]] ; echo $? )
;;
">")
matches=$( [[ "$ver" -gt "$ifver" ]] ; echo $? )
;;
"<")
matches=$( [[ "$ver" -lt "$ifver" ]] ; echo $? )
;;
">=")
matches=$( [[ "$ver" -ge "$ifver" ]] ; echo $? )
;;
"<=")
matches=$( [[ "$ver" -le "$ifver" ]] ; echo $? )
;;
*)
echo "Unknown condition: $ifcond"
exit 1
;;
esac
allowIfLayer+=("$matches")
fi
elif [[ "${line:0:6}" == "#endif" ]]; then
unset 'allowIfLayer[${#allowIfLayer[@]}-1]'
elif [[ "${#allowIfLayer[@]}" -eq "0" || "${allowIfLayer[${#allowIfLayer[@]}-1]}" -eq "0" ]]; then
echo "$line"
fi
}
function g() {
cd "$1" || exit
grep -R -E 'Event<[^>]+> [^ ]+ =|^\w*#(if (.+$)|endif)' -o | mapp g2 "$2"
cd - || exit
}
if [ ! -d "../architectury-api" ]; then
gh repo clone architectury/architectury-api ../architectury-api
cd ../architectury-api
git switch "$lastVer"
cd -
fi
for entry in "${entries[@]}"; do
entry="${entry:18:6}"
echo "=== Diff $entry ==="
echo "Entries with a left arrow are in Architectury but missing from Infrastructury"
diff \
<(g "../architectury-api/common/src/main/java/dev/architectury/event/events") \
<(g "./common/src/main/java/com/mrmelon54/infrastructury/event/events" "$entry")
done