docs: Which API calls were first supported in which upstream versions.
[libguestfs.git] / src / api-support / update-from-tarballs.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2010 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 if [ ! -f HACKING ]; then
20     echo "You should run this script from the top source directory."
21     exit 1
22 fi
23
24 set -e
25
26 cd src/api-support
27
28 tmpdir=$(mktemp -d)
29
30 website=$HOME/d/redhat/websites/libguestfs
31 tarballs="$website/download/1.*-*/libguestfs-*.tar.gz"
32
33 for t in $tarballs; do
34     # libguestfs-x.y.z
35     p=$(basename $t .tar.gz)
36     # x.y.z
37     v=$(echo $p | sed 's/^libguestfs-//')
38
39     if [ $v != "1.2.0" -a $v != "1.3.0" -a ! -f $v ]; then
40         rm -rf "$tmpdir/*"
41         tar -C "$tmpdir" \
42             -zxf $t $p/src/guestfs-actions.c $p/src/actions.c 2>/dev/null ||:
43
44         f="$tmpdir/$p/src/guestfs-actions.c"
45         if [ ! -f "$f" ]; then
46             f="$tmpdir/$p/src/actions.c"
47             if [ ! -f "$f" ]; then
48                 echo "$t does not contain actions file"
49                 exit 1
50             fi
51         fi
52
53         grep -Eo 'guestfs_[a-z0-9][_A-Za-z0-9]+' "$f" |
54             sort -u |
55             grep -v '_ret$' |
56             grep -v '_args$' |
57             grep -v '^guestfs_free_' |
58             grep -v '^guestfs_test0' |
59             grep -v '^guestfs_message_error$' |
60             grep -v '^guestfs_message_header$' > $v
61     fi
62 done
63
64 rm -rf "$tmpdir"
65
66 # GNU ls sorts properly by version with the -v option and backwards by
67 # version with -vr.
68 rev_versions=$(ls -vr [01]*)
69 latest=$(ls -v [01]* | tail -1)
70
71 exec 5>added
72
73 # Get all the symbols from the latest version.
74 # We are implicitly assuming that symbols are not removed.  ABI
75 # guarantee should prevent that from happening.
76 symbols=$(<$latest)
77
78 previous=$latest
79 for v in $rev_versions; do
80     next_symbols=
81     for sym in $symbols; do
82         # If symbol is missing from the file, that indicates it
83         # was added in the previous file we checked ($previous).
84         if ! grep -sq $sym $v; then
85             echo $sym $previous >&5
86         else
87             next_symbols="$next_symbols $sym"
88         fi
89     done
90     symbols="$next_symbols"
91     previous=$v
92 done
93
94 # Any remaining were added in the very first version.
95 for sym in $symbols; do
96     echo $sym $previous >&5
97 done
98
99 # Close and sort the output by symbol name.
100 exec 5>&-
101 sort -o added added