771b6bc4103c6ae3f1c50fb7e873469b097c2ada
[patchq.git] / test-functions
1 # -*- shell-script -*-
2 # These are some common functions used to test libguestfs.
3
4 function pick_project ()
5 {
6     # Try to guess which project this patch series is for.
7     # You should put [PATCH hivex ...] or [PATCH supermin ...]
8     # in the subject line.
9     subject="$(grep -i -m1 '^Subject: ' $1)"
10     project=libguestfs
11     if [[ "$subject" =~ \[PATCH.*hivex.*\] ]]; then
12         project=hivex
13     elif [[ "$subject" =~ \[PATCH.*supermin.*\] ]]; then
14         project=supermin
15     elif [[ "$subject" =~ \[PATCH.*nbdkit.*\] ]]; then
16         project=nbdkit
17     fi
18     url=https://github.com/libguestfs/$project
19 }
20
21 function checkout_sources ()
22 {
23     echo
24     echo "Checking out sources from $url ..."
25     echo
26
27     # Save network by using the local copy if it exists.
28     if [ -d $HOME/d/$project ]; then
29         cp -a $HOME/d/$project .
30         pushd $project
31         git checkout -f origin/master -B master
32         git clean -xdf
33         git pull
34         popd
35     else
36         git clone $url
37     fi
38 }
39
40 # Try to apply the patches.
41 function apply_patches ()
42 {
43     echo
44     echo "Applying patches ..."
45     echo
46     cp "$@" $project/
47     pushd $project
48     git am "$@"
49     popd
50 }
51
52 # Set up localconfigure and localenv appropriately.
53 function local_config ()
54 {
55     pushd $project
56     case "$project" in
57         libguestfs)
58             cat > localconfigure <<'EOF'
59 ./autogen.sh \
60     --prefix /usr \
61     --libdir /usr/lib64 \
62     --disable-static \
63     --enable-werror \
64     --disable-golang \
65     -C \
66     "$@"
67 EOF
68             cat > localenv <<'EOF'
69 export SKIP_TEST_PARALLEL_MOUNT_LOCAL=1
70 export SKIP_TEST_FUSE_UMOUNT_RACE_SH=1
71 export SKIP_TEST_GUESTMOUNT_FD=1
72 export SKIP_TEST_XFS_ADMIN=1
73 export SKIP_TEST_XFS_MISC_PL=1
74 export SKIP_TEST_SYSLINUX_PL=1
75 EOF
76             ;;
77
78         hivex)
79             cat > localconfigure <<'EOF'
80 ./autogen.sh \
81     --prefix /usr \
82     --libdir /usr/lib64 \
83     --enable-gcc-warnings
84 EOF
85             ;;
86
87         supermin)
88             cat > localconfigure <<'EOF'
89 ./autogen.sh \
90     --prefix /usr \
91     --libdir /usr/lib64 \
92     --enable-werror
93 EOF
94             ;;
95
96         nbdkit)
97             cat > localconfigure <<'EOF'
98 ./configure \
99     --prefix /usr \
100     --libdir /usr/lib64 \
101     --enable-gcc-warnings \
102     "$@"
103 EOF
104             ;;
105     esac
106     chmod +x localconfigure
107     popd
108 }