/
tarball.rb
94 lines (78 loc) · 2.99 KB
/
tarball.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
#
# Cookbook Name:: clang
# Recipe:: tarball
# Copyright 2012, Travis CI development team
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
arch = case node.clang.version
when "3.1" then
kernel['machine'] =~ /x86_64/ ? "x86_64" : "x86"
else
kernel['machine'] =~ /x86_64/ ? "x86_64" : "i386"
end
platform_name, ext = case [node[:platform], node[:platform_version]]
when ["ubuntu", "11.10"]
["#{node[:platform]}-#{node[:platform_version]}", "tar.bz2"]
when ["ubuntu", "12.04"]
["#{node[:platform]}_#{node[:platform_version]}", "tar.gz"]
end
filename = "clang+llvm-#{node.clang.version}-#{arch}-linux-#{platform_name}"
installation_dir = "/usr/local/clang"
# 1. Download the tarball to /tmp
require "tmpdir"
td = Dir.tmpdir
local_tarball = File.join(td, "#{filename}.#{ext}")
tarball_dir = File.join(td, filename)
remote_file(local_tarball) do
source "http://llvm.org/releases/#{node.clang.version}/#{filename}.#{ext}"
not_if "which clang"
end
tar_args = (ext =~ /gz/ ? 'zfx' : 'jfx')
# 2. Extract it
# 3. Copy to /usr/local/clang, update permissions
bash "extract #{local_tarball}, move it to /usr/local" do
user "root"
cwd "/tmp"
code <<-EOS
rm -rf #{installation_dir}
tar #{tar_args} #{local_tarball}
mv --force #{tarball_dir} #{installation_dir}
chmod +x #{installation_dir}/bin/clang
chmod +x #{installation_dir}/bin/clang++
EOS
creates "#{installation_dir}/bin/clang"
end
# 4. Symlink
%w(clang clang++ llvm-ld llvm-link).each do |f|
# due to a Chef bug that prevents not_if for the link resource from doing the
# correct thing. MK.
bash "Remove the symlink to /usr/local/bin/#{f}" do
user "root"
cwd "/tmp"
code <<-EOS
rm -f /usr/local/bin/#{f}
EOS
end
link "/usr/local/bin/#{f}" do
owner "root"
group "root"
to "#{installation_dir}/bin/#{f}"
not_if "test -L /usr/local/bin/#{f}"
end
end