Skip to content

Commit 1d888b9

Browse files
committed
implement local::lib caching
1 parent a619a8c commit 1d888b9

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,17 @@ There are various environment variables that will control how a build is done.
116116
generation process if it has heavy dependencies, such as Dist::Zilla, and
117117
testing is being done on a freshly built perl.
118118

119+
Makes a local::lib that is blank.
120+
119121
Defaults to true.
120122

123+
* `LOCAL_LIB_CACHE`
124+
125+
The directory used to cache the local::lib used if you specify
126+
`local-lib cache`.
127+
128+
Defaults to `$HOME/.perlbrew-cache`.
129+
121130
* `CPAN_MIRROR`
122131

123132
The CPAN mirror that dependencies will be installed from.
@@ -278,6 +287,52 @@ Commands
278287
or built if not, and added to the library path. This is taken care
279288
of by the `build-perl` step.
280289

290+
There is a special local::lib name you can give:
291+
`cache`, which works together with [Travis's caching
292+
feature](https://docs.travis-ci.com/user/caching). Its location
293+
defaults to `$HOME/.perlbrew-cache` but can be overridden
294+
by supplying the environment variable `LOCAL_LIB_CACHE`. Use it
295+
like this:
296+
297+
cache:
298+
directories:
299+
- $HOME/.perlbrew-cache # keeps between builds here
300+
perl:
301+
- "5.8.4@moo"
302+
before_install:
303+
- git clone git://github.com/travis-perl/helpers ~/travis-perl-helpers
304+
- source ~/travis-perl-helpers/init
305+
- build-perl
306+
- local-lib cache # makes a local::lib from cached
307+
- perl -V
308+
- build-dist
309+
- cd $BUILD_DIR
310+
install:
311+
- cpan-install --deps # installs prereqs, including recommends
312+
before_cache:
313+
- local-lib-cachestore # saves for local::lib next time
314+
315+
Alternatively, this will also work and the `build-perl` will do the
316+
`local-lib` step for you:
317+
318+
cache:
319+
directories:
320+
- $HOME/.perlbrew-cache # keeps between builds here
321+
perl:
322+
- "5.8.4@cache"
323+
before_install:
324+
- git clone git://github.com/travis-perl/helpers ~/travis-perl-helpers
325+
- source ~/travis-perl-helpers/init
326+
- build-perl
327+
# no need for local-lib cache
328+
- perl -V
329+
- build-dist
330+
- cd $BUILD_DIR
331+
install:
332+
- cpan-install --deps # installs prereqs, including recommends
333+
before_cache:
334+
- local-lib-cachestore # saves for local::lib next time
335+
281336
local::lib
282337
----------
283338
A number of [predefined local::lib](share/local-libs.txt) directories are

bin/local-lib

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ if [ -z "$1" ]; then
77
ll_roots=("$(mktemp -d -t local-lib-XXXXXX)")
88
else
99
for lib; do
10-
if [ -z "$LL_NO_INSTALL" ]; then
11-
# redirect since output of this gets eval-ed
12-
if $HELPERS_ROOT/bin/local-lib-installer "$lib" 1>&2; then
13-
ll_roots+=("$PERLBREW_HOME/libs/$PERLBREW_PERL@$lib")
10+
if [ "$lib" == "cache" ]; then
11+
$HELPERS_ROOT/bin/local-lib-cache use
12+
else
13+
if [ -z "$LL_NO_INSTALL" ]; then
14+
# redirect since output of this gets eval-ed
15+
if $HELPERS_ROOT/bin/local-lib-installer "$lib" 1>&2; then
16+
ll_roots+=("$PERLBREW_HOME/libs/$PERLBREW_PERL@$lib")
17+
fi
1418
fi
1519
fi
20+
ll_roots+=("$PERLBREW_HOME/libs/$PERLBREW_PERL@$lib")
1621
done
1722
fi
1823

bin/local-lib-cache

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# usage:
4+
# $0 use
5+
# copies from cache location to perlbrew location
6+
# $0 store
7+
# copies from perlbrew location to cache location
8+
9+
# locations:
10+
cache_location="$LOCAL_LIB_CACHE"
11+
full_version="$PERLBREW_PERL@cache"
12+
perlbrew_location="$PERLBREW_HOME/libs/$full_version"
13+
14+
[ -z "$HELPERS_ROOT" ] && export HELPERS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
15+
source "$HELPERS_ROOT/lib/debug.sh"
16+
exec 1>&2 # since local-lib calls this, then evals stdout - any echo to stderr
17+
18+
if [ -z "$PERLBREW_ROOT" ]; then
19+
echo "Must be run under perlbrew!"
20+
exit 1
21+
fi
22+
23+
source "$PERLBREW_ROOT/etc/bashrc"
24+
25+
set -e
26+
27+
if [ "$1" == "use" ]; then
28+
perlbrew lib create "$full_version"
29+
perlbrew use "$full_version"
30+
mkdir -p "$perlbrew_location"
31+
cp -pr "$cache_location"/* "$perlbrew_location"
32+
elif [ "$1" == "store" ]; then
33+
id
34+
echo "BEFORE"; find "$perlbrew_location" "$cache_location" -ls
35+
mkdir -p "$cache_location"
36+
cp -pr "$perlbrew_location"/* "$cache_location"
37+
echo "AFTER"; find "$cache_location" -ls
38+
else
39+
echo "Unknown arg '$1'"
40+
exit 1
41+
fi

init

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export SYSTEM_CORES="$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n
1919
[ -z "$AUTHOR_TESTING" ] && export AUTHOR_TESTING=1
2020
[ -z "$SPLIT_BUILD" ] && export SPLIT_BUILD=1
2121
[ "$COVERAGE" == "1" ] && export COVERAGE=coveralls # drop this eventually
22+
[ -z "$LOCAL_LIB_CACHE" ] && export LOCAL_LIB_CACHE="$HOME/.perlbrew-cache"
2223
[ -z "$PERL_AUTOINSTALL_PREFER_CPAN" ] && export PERL_AUTOINSTALL_PREFER_CPAN=1
2324
[ -z "$PERL_MM_USE_DEFAULT" ] && export PERL_MM_USE_DEFAULT=1
2425
[ -z "$NONINTERACTIVE_TESTING" ] && export NONINTERACTIVE_TESTING=1
@@ -52,6 +53,10 @@ function local-lib {
5253
eval "$("$HELPERS_ROOT/bin/local-lib" "$@")"
5354
}
5455

56+
function local-lib-cachestore {
57+
$HELPERS_ROOT/bin/local-lib-cache store
58+
}
59+
5560
function build-perl {
5661
local TRAVIS_PERL_VERSION="$TRAVIS_PERL_VERSION"
5762
if [[ ( "$TRAVIS_PERL_VERSION" =~ ^5\.6[.-] || \

0 commit comments

Comments
 (0)