summaryrefslogtreecommitdiffstats
path: root/.travis.yml
blob: 570341998a5e009a03a06e31e0d8ea55fb29f551 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
dist: trusty
language: python

install:
    - ./.travis/install.sh

# python 3 is not fulling passing at this time
# so allow failure so the coverage stage can be reached with python 2
matrix:
  allow_failures:
    - python: 3.5
    - python: 3.6
    - python: pypy


jobs:
  include:
    - &test_job
      stage: Test
      script: 
      # WORKAROUND: attempt to retry JobTests.py if it fails and then continue if it passes, if it fails ten times
      # then it is a real failure not related to intermittent travis failures
        - n=0; while [[ $n -lt 10 ]]; do python runtest.py src/engine/SCons/JobTests.py && break; n=$((n+1)); done; if [ "$n" -gt "9" ]; then false; fi
        - echo "src/engine/SCons/JobTests.py" > exclude_jobtest
        - python runtest.py -a --exclude-list exclude_jobtest || if [[ $? == 2 ]]; then true; else false; fi
      before_script: skip
      after_success: skip
      python: 2.7
      env: PYVER=27
      sudo: required

    - <<: *test_job
      python: 3.5
      env: PYVER=35
      sudo: required

    - <<: *test_job
      python: 3.6
      env: PYVER=36
      sudo: required

    - <<: *test_job
      python: pypy
      env: PYVER=pypy
      sudo: required


    - &coverage_jobs
      stage: Coverage
      
      before_script:
        - sudo pip install coverage
        - sudo pip install coveralls
        # set this ensure user sites are available
        - export PYTHONNOUSERSITE=
        # we need to preserve the test directories because they have the coverage data
        - export PRESERVE=1
        # attempt to get a location where we can store the usercustomize.py fiel
        - python -m site
        - export PYSITEDIR=$(python -m site --user-site)
        - sudo mkdir -p $PYSITEDIR
        - sudo touch ${PYSITEDIR}/usercustomize.py
        # write the usercustomize.py file so all python processes use coverage and know where the config file is
        - echo "import os" | sudo tee --append ${PYSITEDIR}/usercustomize.py
        - echo "os.environ['COVERAGE_PROCESS_START'] = '$PWD/.coveragerc'" | sudo tee --append ${PYSITEDIR}/usercustomize.py
        - echo "import coverage" | sudo tee --append ${PYSITEDIR}/usercustomize.py
        - echo "coverage.process_startup()" | sudo tee --append ${PYSITEDIR}/usercustomize.py

      script: 
        - export TOTAL_BUILD_JOBS=8
        # write the coverage config file
        - export COVERAGE_PROCESS_START=$PWD/.coveragerc
        - echo "[run]" >> .coveragerc
        - echo "source = $PWD/src" >> .coveragerc
        - echo "parallel = True" >> .coveragerc
        - printf "omit =\n\t*Tests.py\n\tsrc/test_*\n\tsrc/setup.py\n\n" >> .coveragerc
        - echo "[path] = $PWD" >> .coveragerc
      # Not including this workaround in the coverage report, because it will result
      # in constantly changing coverage reports depending on the number of times
      # the JobTests.py had to run to pass
      # TODO: figure out how to cover JobTests.py
      # - n=0; while [[ $n -lt 10 ]]; do coverage run --rcfile=$PWD/.coveragerc runtest.py src/engine/SCons/JobTests.py && break; n=$((n+1)); done; if [ "$n" -gt "9" ]; then false; fi
      # exclude JobTest.py becuase we already ran that
        - echo "src/engine/SCons/JobTests.py" > exclude_jobtest
      # also exclude this test since it overides the exit function which doesnt work with coverage 
      # more info here: https://coverage.readthedocs.io/en/coverage-4.4.2/subprocess.html#
      # TODO: figure out how to cover test/exitfns.py
        - echo "test/exitfns.py" >> exclude_jobtest
        - python runtest.py -l -a --exclude-list exclude_jobtest > all_tests
        - let "start = ($(wc -l < all_tests) / ${TOTAL_BUILD_JOBS}) * (${BUILD_JOB_NUM} - 1)"; true;
        - let "end = ($(wc -l < all_tests) / ${TOTAL_BUILD_JOBS}) * ${BUILD_JOB_NUM}"
        - if (( ${BUILD_JOB_NUM} == ${TOTAL_BUILD_JOBS} )); then end=$(wc -l < all_tests); fi
        - if (( ${start} == 0 )); then start=1; fi
        - sed -n ${start},${end}p all_tests > build_tests
        - coverage run -p --rcfile=$PWD/.coveragerc runtest.py -f build_tests || if [[ $? == 2 ]]; then true; else false; fi

      after_success:
        # get all the coverage data files from the tests and configure them into 
        # a command line arg list of directories
        - find /tmp -name '.coverage.*' -print > coverage_reports.txt
        # get just the directories
        - sed -i 's/\/\.coverage\..*$//g' coverage_reports.txt
        # remove duplicates
        - awk '!seen[$0]++' coverage_reports.txt > coverage_reports.txt.tmp
        - mv coverage_reports.txt.tmp coverage_reports.txt
        # switch newlines for spaces
        - sed -i -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' coverage_reports.txt
        # use all the tmp dir's as locations to collect coverage data
        - coverage combine $PWD `cat coverage_reports.txt`
        - coverage report
        - coveralls --rcfile=$PWD/.coveragerc

      env: BUILD_JOB_NUM=1

    - <<: *coverage_jobs
      env: BUILD_JOB_NUM=2
    - <<: *coverage_jobs
      env: BUILD_JOB_NUM=3
    - <<: *coverage_jobs
      env: BUILD_JOB_NUM=4
    - <<: *coverage_jobs
      env: BUILD_JOB_NUM=5
    - <<: *coverage_jobs
      env: BUILD_JOB_NUM=6
    - <<: *coverage_jobs
      env: BUILD_JOB_NUM=7
    - <<: *coverage_jobs
      env: BUILD_JOB_NUM=8