/
rust.rb
101 lines (86 loc) · 2.65 KB
/
rust.rb
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
module Travis
module Build
class Script
class Rust < Script
RUST_RUSTUP = 'https://sh.rustup.rs'
RUSTUP_CMD = "curl -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=$TRAVIS_RUST_VERSION --profile=minimal -y"
DEFAULTS = {
rust: 'stable',
}
CARGO_CACHE_CLEANUP_DIRS = %W(
$HOME/.cargo/registry/src
)
def export
super
sh.export 'TRAVIS_RUST_VERSION', version.shellescape, echo: false
end
def setup_cache
if data.cache?(:cargo) && !cache_dirs.empty?
sh.fold 'cache.cargo' do
directory_cache.add cache_dirs
end
end
sh.fold('rustup-install') do
sh.echo 'Installing Rust', ansi: :yellow
unless app_host.empty?
sh.cmd "curl -sSf https://#{app_host}/files/rustup-init.sh | sh -s -- --default-toolchain=$TRAVIS_RUST_VERSION --profile=minimal -y", echo: true, assert: false
sh.if "$? -ne 0" do
sh.cmd RUSTUP_CMD, echo: true, assert: true
end
else
sh.cmd RUSTUP_CMD, echo: true, assert: true
end
sh.export 'PATH', "${TRAVIS_HOME}/.cargo/bin:$PATH"
if version =~ /nightly|stable|beta/
sh.cmd 'rustup update', echo: true
end
end
end
def announce
super
sh.cmd 'rustc --version', assert: true
sh.cmd 'rustup --version', assert: true
sh.cmd 'cargo --version', assert: true
sh.newline
end
def script
sh.cmd 'cargo build --verbose'
sh.cmd 'cargo test --verbose'
end
def cache_slug
super << "--cargo-" << version
end
def use_directory_cache?
super || data.cache?(:cargo)
end
def before_cache
sh.cmd "rm -rf \"#{CARGO_CACHE_CLEANUP_DIRS.join(" ")}\"", timing: false, echo: false
end
private
def version
Array(config[:rust]).first.to_s
end
def cache_dirs
case config[:os]
when 'linux'
%W(
${TRAVIS_HOME}/.cargo
target
${TRAVIS_HOME}/.rustup
${TRAVIS_HOME}/.cache/sccache
)
when 'osx'
%W(
${TRAVIS_HOME}/.cargo
target
${TRAVIS_HOME}/.rustup
${TRAVIS_HOME}/Library/Caches/Mozilla.sccache
)
else
[]
end
end
end
end
end
end