-
Notifications
You must be signed in to change notification settings - Fork 29
/
init
193 lines (171 loc) · 5.23 KB
/
init
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
if [ -z "$BASH_VERSION" ]; then
echo "This script can only used with bash, not other shells." 1>&2
exit 1
elif [ "${BASH_SOURCE[0]}" = "$0" ]; then
echo "This script must be sourced, not run directly." 1>&2
exit 1
elif [ -z "$PERLBREW_ROOT" ]; then
echo "Must be run under perlbrew."
return 1
fi
export HELPERS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export HELPER_ROOT="$HELPERS_ROOT"
. "$HELPERS_ROOT/lib/debug.sh"
export SYSTEM_CORES="$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu || echo 1)"
[ -z "$AUTHOR_TESTING" ] && export AUTHOR_TESTING=1
[ -z "$SPLIT_BUILD" ] && export SPLIT_BUILD=1
[ "$COVERAGE" == "1" ] && export COVERAGE=coveralls # drop this eventually
[ -z "$PERL_AUTOINSTALL_PREFER_CPAN" ] && export PERL_AUTOINSTALL_PREFER_CPAN=1
[ -z "$PERL_MM_USE_DEFAULT" ] && export PERL_MM_USE_DEFAULT=1
[ -z "$NONINTERACTIVE_TESTING" ] && export NONINTERACTIVE_TESTING=1
export MODERN_PERL
if [ "$SPLIT_BUILD" != "0" ] && [ -z "$MODERN_PERL" ]; then
MODERN_PERL="$(
for perl in "$PERLBREW_ROOT/perls/"*/bin/perl; do
"$perl" -MConfig -le'
print(($]*1000000)." ".($^X=~m{/}?$^X:$Config{perlpath}))
unless ($]*1000) % 2;
'
done |
sort -n |
tail -1 |
cut -c9-
)"
fi
[ -z "$MODERN_PERL" ] && MODERN_PERL="$(command -v perl)"
MODERN_PERL="env PERL5LIB= $MODERN_PERL"
# work around potential quoting issues in .travis.yml
[[ "$TRAVIS_PERL_VERSION" =~ ^5\.[1-4]$ ]] && TRAVIS_PERL_VERSION+="0"
function build-dist {
export BUILD_DIR="$(pwd)/build_dir"
"$HELPERS_ROOT/bin/build-dist" "$BUILD_DIR"
}
function local-lib {
eval "$("$HELPERS_ROOT/bin/local-lib" "$@")"
}
function build-perl {
local TRAVIS_PERL_VERSION="$TRAVIS_PERL_VERSION"
if [[ ( "$TRAVIS_PERL_VERSION" =~ ^5\.6[.-] || \
"$TRAVIS_PERL_VERSION" =~ ^5\.6$ ) &&
! "$TRAVIS_PERL_VERSION" =~ @ ]]; then
TRAVIS_PERL_VERSION="[email protected]"
fi
"$HELPERS_ROOT/bin/build-perl" "$TRAVIS_PERL_VERSION" || return 1
if [ "${TRAVIS_PERL_VERSION/@*/}" == "system" ]; then
perlbrew off
if [ "${TRAVIS_PERL_VERSION/*@/}" != "$TRAVIS_PERL_VERSION" ]; then
local-lib "${TRAVIS_PERL_VERSION/*@/}"
fi
else
perlbrew use "$TRAVIS_PERL_VERSION" || return 1
fi
if [ "$SPLIT_BUILD" == "0" ]; then
MODERN_PERL="env PERL5LIB= $(command -v perl)"
fi
}
function cpan-install {
"$HELPERS_ROOT/bin/cpan-install" $CPAN_INSTALL_FLAGS "$@"
}
function coverage-setup {
[ "$COVERAGE" == "0" ] || [ "$COVERAGE" == "" ] && return
cover -delete -silent
export HARNESS_PERL_SWITCHES="${HARNESS_PERL_SWITCHES}${HARNESS_PERL_SWITCHES:+ }"'-MDevel::Cover=-ignore,^x?t/,-blib,0'
}
function _coverage-opts {
local cover_opts
local cover
if [ -n "$COVERAGE" ] && [ "$COVERAGE" != "0" ]; then
if [ "$COVERAGE" != "1" ]; then
for cover in $COVERAGE; do
cover="$(echo "${cover:0:1}" | tr a-z A-Z)${cover:1}"
# drop this when coveralls not implied
if perl -m"Devel::Cover::Report::$cover" -e1 2>/dev/null; then
cover_opts="$cover_opts --report \"$cover\""
fi
done
fi
fi
echo "$cover_opts"
}
function coverage-report {
[ "$COVERAGE" == "0" ] || [ "$COVERAGE" == "" ] && return
if [ "$COVERAGE" == "1" ]; then
cover "$@"
else
for cover in $COVERAGE; do
cover="$(echo "${cover:0:1}" | tr a-z A-Z)${cover:1}"
cover "$@" --report "$cover"
done
fi
}
function test-dirs {
local TEST_DIRS='t'
if [ "$AUTHOR_TESTING" -ne 0 ] && [ -d xt ]; then
TEST_DIRS="$TEST_DIRS xt"
fi
echo "$TEST_DIRS"
}
function test-files {
local file_list=""
if [ -n "$RELEASE_TESTING" ] && [ "$RELEASE_TESTING" != "0" ]; then
file_list="$(find $(test-dirs) -name '*.t' | sort)"
else
file_list="$(find $(test-dirs) -name '*.t' ! -path 'xt/release/*' | sort)"
fi
local IFS=$'\n'
local -a files=($file_list)
if [ -n "$TEST_PARTITION" ]; then
if [ -z "$TEST_PARTITIONS" ]; then
echo "TEST_PARTITIONS required with TEST_PARTITION option" 1>&2
return 1
elif [ "$TEST_PARTITION" -lt 1 ] || [ "$TEST_PARTITION" -gt "$TEST_PARTITIONS" ]; then
echo "TEST_PARTITION must be between 1 and TEST_PARTITIONS ($TEST_PARTITIONS)" 1>&2
return 1
fi
local file_count=${#files[@]}
local partition_size="$(( (file_count + TEST_PARTITIONS - 1) / TEST_PARTITIONS ))"
local partition_start="$(( (TEST_PARTITION - 1) * partition_size ))"
files=("${files[@]:$partition_start:$partition_size}")
fi
echo "${files[@]}"
}
function test-jobs {
if [ -n "$COVERAGE" ] && [ "$COVERAGE" != "0" ]; then
echo 1
else
echo "$(( SYSTEM_CORES + 1))"
fi
}
function setup-auto {
. "$HELPERS_ROOT/lib/auto.bash"
setup-auto
}
. "$HELPERS_ROOT/lib/prove.bash"
echo "Perl Travis Helpers: $(git --git-dir="$HELPERS_ROOT/.git" describe --all --long HEAD)"
for arg; do
case "$arg" in
--auto)
AUTO=1
;;
--perl)
PERL=1
;;
--always-upgrade-modules)
CPAN_INSTALL_FLAGS="--update-prereqs"
;;
--debug)
export HELPERS_DEBUG=1
;;
*)
echo "Invalid argument $arg!" 1>&2
return 1
;;
esac
done
if [ -n "$AUTO" ]; then
setup-auto
elif [ -n "$PERL" ]; then
build-perl
perl -V
fi
# vim: ft=sh