aboutsummaryrefslogtreecommitdiffstats
path: root/tools/travis-cache-windows.sh
blob: 515f8649eefab81fbd47c59abf3067520f790ae4 (plain)
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
#!/bin/bash
# Packs and unpacks files for Travis CI cache.
#
# Copyright (C) 2019 Peter Wu <peter@lekensteyn.nl>
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Travis CI currently has a bug that prevents absolute paths from being cached.
# See https://github.com/travis-ci/casher/pull/38
# As a workaround, manually pack directories into an uncompressed tarball
# (which will be bzip2-compressed by casher). An additional advantage is that
# casher has to check fewer files to determine whether it is out of date.

pre_restore() {
    restored_files=()
    echo "Contents of ${cachedir}:"
    ls -la "$cachedir"
    echo
}

do_restore() {
    local tarball="$cachedir/$1" path="$2"
    if [ -e "$tarball" ]; then
        echo "Restoring ${path}..."
        time tar -xPf "$tarball" "$path"
        restored_files+=("$1")
    fi
}

post_restore() {
    # Remove old cache entries if any.
    mkdir "${cachedir}.new"
    for file in "${restored_files[@]}"; do
        mv "$cachedir/$file" "${cachedir}.new/"
    done
    if oldfiles=$(ls -lA "$cachedir" | grep -v ^total); then
        echo "Removed stale cache entries:"
        echo "$oldfiles"
        echo
    fi
    rm -rf "$cachedir"
    mv "${cachedir}.new" "$cachedir"
}

pre_save() { :;}

do_save() {
    local tarball="$cachedir/$1" path="$2"
    if [ ! -e "$path" ]; then
        echo "Cannot cache $path as it is missing."
        return
    fi
    if [ -e "$tarball" ]; then
        if ! [ "$path" -nt "$tarball" ]; then
            echo "No changes detected in ${path}."
            return
        fi
        echo "Saving new version of ${path}..."
    else
        echo "Saving $path for the first time..."
    fi
    time tar -cPf "$tarball" "$path"
}

post_save() {
    echo "New contents of ${cachedir}:"
    ls -la "$cachedir"
    echo
}

main() {
    # Cache directories are relative to this path.
    cd "$TRAVIS_BUILD_DIR"
    pwd
    cachedir=travis-cache
    mkdir -p "$cachedir"

    "pre_$1"

    "do_$1" wireshark-libs.tar              "$WIRESHARK_BASE_DIR"
    "do_$1" Qt.tar                          "$QT5_BASE_DIR"

    "post_$1"
}

# Merge stderr to stdout to prevent stderr from ending up in future output.
main "$1" 2>&1