|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 | ls "$HOME/.cache/"
|
| 4 | + |
| 5 | +PYX_CACHE_DIR="$HOME/.cache/pyxfiles" |
| 6 | +pyx_file_list=`find ${TRAVIS_BUILD_DIR} -name "*.pyx"` |
| 7 | +pyx_cache_file_list=`find ${PYX_CACHE_DIR} -name "*.pyx"` |
| 8 | + |
4 | 9 | CACHE_File="$HOME/.cache/cython_files.tar"
|
5 | 10 |
|
| 11 | +# Clear the cython cache 0 = NO, 1 = YES |
6 | 12 | clear_cache=0
|
| 13 | + |
| 14 | +pyx_files=`echo "$pyx_file_list" | wc -l` |
| 15 | +pyx_cache_files=`echo "$pyx_cache_file_list" | wc -l` |
| 16 | + |
| 17 | +if [[ pyx_files -ne pyx_cache_files ]] |
| 18 | +then |
| 19 | + echo "Different number of pyx files" |
| 20 | + clear_cache=1 |
| 21 | +fi |
| 22 | + |
7 | 23 | home_dir=$(pwd)
|
8 | 24 |
|
9 |
| -if [ -f "$CACHE_File" ] && [ "$USE_CACHE" ]; then |
| 25 | +if [ -f "$CACHE_File" ] && [ "$USE_CACHE" ] && [ -d "$PYX_CACHE_DIR" ]; then |
| 26 | + |
| 27 | + echo "Cache available - checking pyx diff" |
| 28 | + |
| 29 | + for i in ${pyx_file_list} |
| 30 | + do |
| 31 | + diff=`diff -u $i $PYX_CACHE_DIR${i}` |
| 32 | + if [[ $? -eq 2 ]] |
| 33 | + then |
| 34 | + echo "${i##*/} can't be diffed; probably not in cache" |
| 35 | + clear_cache=1 |
| 36 | + fi |
| 37 | + if [[ ! -z $diff ]] |
| 38 | + then |
| 39 | + echo "${i##*/} has changed:" |
| 40 | + echo $diff |
| 41 | + clear_cache=1 |
| 42 | + fi |
| 43 | + done |
10 | 44 |
|
11 |
| - echo "Cache available" |
12 |
| - clear_cache=1 |
13 |
| - # did the last commit change cython files? |
14 |
| - # go back 2 commits |
15 | 45 | if [ "$TRAVIS_PULL_REQUEST" == "false" ]
|
16 | 46 | then
|
17 |
| - echo "Not a PR: checking for cython files changes from last 2 commits" |
18 |
| - git diff HEAD~2 --numstat | grep -E "pyx|pxd" |
19 |
| - retval=$(git diff HEAD~2 --numstat | grep -E "pyx|pxd"| wc -l) |
| 47 | + echo "Not a PR" |
| 48 | + # Uncomment next 2 lines to turn off cython caching not in a PR |
| 49 | + # echo "Non PR cython caching is disabled" |
| 50 | + # clear_cache=1 |
20 | 51 | else
|
21 |
| - echo "PR: checking for any cython file changes from last 5 commits" |
22 |
| - git diff PR_HEAD~5 --numstat | grep -E "pyx|pxd" |
23 |
| - retval=$(git diff PR_HEAD~5 --numstat | grep -E "pyx|pxd"| wc -l) |
24 |
| - echo "Forcing cython rebuild due to possibility of history rewritting in PR" |
25 |
| - retval=-1 |
| 52 | + echo "In a PR" |
| 53 | + # Uncomment next 2 lines to turn off cython caching in a PR |
| 54 | + # echo "PR cython caching is disabled" |
| 55 | + # clear_cache=1 |
26 | 56 | fi
|
27 |
| - echo "number of cython files changed: $retval" |
| 57 | + |
28 | 58 | fi
|
29 | 59 |
|
30 |
| -if [ $clear_cache -eq 1 ] && [ $retval -eq 0 ] && [ "$USE_CACHE" ] |
| 60 | +if [ $clear_cache -eq 0 ] && [ "$USE_CACHE" ] |
31 | 61 | then
|
32 |
| - # nope, reuse cython files |
| 62 | + # No and use_cache is set |
33 | 63 | echo "Will reuse cached cython file"
|
34 | 64 | cd /
|
35 | 65 | tar xvmf $CACHE_File
|
36 | 66 | cd $home_dir
|
37 | 67 | else
|
38 | 68 | echo "Rebuilding cythonized files"
|
39 |
| - echo "Use cache = $USE_CACHE" |
40 |
| - echo "Clear cache = $clear_cache" |
| 69 | + echo "Use cache (Blank if not set) = $USE_CACHE" |
| 70 | + echo "Clear cache (1=YES) = $clear_cache" |
41 | 71 | fi
|
42 | 72 |
|
43 | 73 |
|
|
0 commit comments