Skip to content

Commit edca299

Browse files
committed
Add xip support
1 parent 73f8d45 commit edca299

File tree

13 files changed

+208
-8
lines changed

13 files changed

+208
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ bin/*
1414

1515
.kitchen/
1616
.kitchen.local.yml
17+
18+
.idea

.kitchen.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
driver:
3+
name: vagrant
4+
5+
provisioner:
6+
name: chef_zero
7+
require_chef_omnibus: latest
8+
9+
platforms:
10+
- name: mac_osx_elcapitan
11+
os_type: mac_os_x
12+
driver:
13+
provision: true
14+
network:
15+
- ["private_network", {ip: "192.168.33.33"}]
16+
gui: false
17+
box: jhcook/osx-elcapitan-10.11
18+
19+
suites:
20+
- name: xcode_dmg_installer
21+
run_list:
22+
- recipe[xcode_test::default]
23+
attributes:
24+
xcode:
25+
url: "http://192.168.33.1/Xcode_7.3.1.dmg"
26+
checksum: "bb0dedf613e86ecb46ced945913fa5069ab716a0ade1035e239d70dee0b2de1b"
27+
last_gm_license: "EA1327"
28+
version: "7.3.1"
29+
cli:
30+
url: "http://192.168.33.1/Command_Line_Tools_OS_X_10.11_for_Xcode_7.3.1.dmg"
31+
checksum: "0c80753d207fa2254bcc1c880d4d8907071241f3f2e092c7caa87e340245835a"
32+
package_name: "Command Line Tools (OS X 10.11)"
33+
34+
- name: xcode_xip_archive
35+
run_list:
36+
- recipe[xcode_test::default]
37+
attributes:
38+
xcode:
39+
url: "http://192.168.33.1/Xcode_8.1.xip"
40+
checksum: "30378e76f7d1adcf3573fc990bd7b46e0939b466b83338ba8f4290444462e5da"
41+
last_gm_license: "8B62"
42+
version: "8.1"
43+
cli:
44+
url: "http://192.168.33.1/Command_Line_Tools_macOS_10.12_for_Xcode_8.1.dmg"
45+
checksum: "d1697a3f76a1241f32793dee24166415dd64bfbac07dbbf84b02b0b59bf713c5"
46+
package_name: "Command Line Tools (macOS 10.12)"

Berksfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
source 'https://supermarket.chef.io'
22

33
metadata
4+
5+
cookbook 'xcode_test', path: 'test/fixtures/cookbooks/xcode_test', group: 'test'

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ Just include `xcode` in your node's `run_list` and set the attributes above.
4444
}
4545
```
4646

47+
Test
48+
----
49+
Prerequisites:
50+
- HTTP server which provides `Xcode` installers.
51+
If the host machine has installed python, just run in the directory where `Xcode` installers are:
52+
```
53+
python -m SimpleHTTPServer 80
54+
```
55+
- Vagrant 1.8.6
56+
- VirtualBox 5.1.10 + ExtensionPack
57+
- ChefDK latest
58+
59+
This cookbook use the test-kitchen tool for developing infrastructure code. To verify cookbook execute command in terminal
60+
```
61+
kitchen test
62+
```
63+
4764
Bugs
4865
----
4966

metadata.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
77
version '1.3.1'
88
supports 'mac_os_x'
9+
910
depends 'dmg'
11+
depends 'homebrew'

recipes/default.rb

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,93 @@
1717
# limitations under the License.
1818
#
1919

20-
dmg_package "Xcode" do
21-
source node['xcode']['url']
22-
checksum node['xcode']['checksum']
23-
action :install
20+
file_basename = ::File.basename(node['xcode']['url'])
21+
installer_path = "#{Chef::Config[:file_cache_path]}/#{file_basename}"
22+
installer_extension = ::File.extname installer_path
23+
24+
if ::Dir.exist? '/Applications/Xcode.app'
25+
Chef::Log.info('Xcode already installed.')
26+
else
27+
remote_file "Download #{file_basename}" do
28+
backup false
29+
path installer_path
30+
source node['xcode']['url']
31+
checksum node['xcode']['checksum']
32+
not_if { ::File.exist? installer_path }
33+
end
34+
35+
case installer_extension
36+
when '.dmg'
37+
dmg_package 'Xcode' do
38+
file installer_path
39+
action :install
40+
end
41+
when '.xip'
42+
include_recipe 'homebrew'
43+
package 'xz'
44+
45+
remote_file 'Download PBZX v2 unpacker' do
46+
backup false
47+
path "#{Chef::Config[:file_cache_path]}/parse_pbzx2.py"
48+
source 'https://gist.githubusercontent.com/pudquick/ff412bcb29c9c1fa4b8d/raw/24b25538ea8df8d0634a2a6189aa581ccc6a5b4b/parse_pbzx2.py'
49+
not_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content" }
50+
end
51+
52+
execute 'Verify the signature and certificate chain that signed the archive' do
53+
command "pkgutil --check-signature #{installer_path}"
54+
cwd Chef::Config[:file_cache_path]
55+
end
56+
57+
execute 'Extract the PBZX stream from the archive' do
58+
command "xar -xf #{file_basename} Content -C ./"
59+
cwd Chef::Config[:file_cache_path]
60+
end
61+
62+
execute 'Unpack PBZX archive' do
63+
command 'python parse_pbzx2.py Content'
64+
cwd Chef::Config[:file_cache_path]
65+
end
66+
67+
file "#{Chef::Config[:file_cache_path]}/Content" do
68+
backup false
69+
action :delete
70+
only_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content" }
71+
end
72+
73+
execute 'Decompress the archive' do
74+
command 'xz -d Content.part00.cpio.xz'
75+
cwd Chef::Config[:file_cache_path]
76+
end
77+
78+
execute 'Unpack the CPIO archive' do
79+
command 'cpio --quiet -idm < ./Content.part00.cpio'
80+
cwd Chef::Config[:file_cache_path]
81+
end
82+
83+
file "#{Chef::Config[:file_cache_path]}/Content.part00.cpio" do
84+
backup false
85+
action :delete
86+
only_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content.part00.cpio" }
87+
end
88+
89+
execute 'Move the resulting Xcode app bundle into /Applications' do
90+
command 'mv Xcode.app /Applications/Xcode.app'
91+
cwd Chef::Config[:file_cache_path]
92+
end
93+
94+
file installer_path do
95+
backup false
96+
action :delete
97+
only_if { ::Dir.exist? installer_path }
98+
end
99+
else
100+
Chef::Log.error("Not supported file extension: '#{installer_extension}'.")
101+
end
102+
end
103+
104+
execute 'Switch Xcode' do
105+
command 'xcode-select --switch /Applications/Xcode.app/Contents/Developer'
106+
not_if { system('xcodebuild -version > /dev/null 2>&1') }
24107
end
25108

26109
dmg_package node['xcode']['cli']['package_name'] do
@@ -32,10 +115,8 @@
32115
action :install
33116
end
34117

35-
template "/Library/Preferences/com.apple.dt.Xcode.plist" do
36-
source "com.apple.dt.Xcode.plist.erb"
37-
owner "root"
38-
group "wheel"
118+
template '/Library/Preferences/com.apple.dt.Xcode.plist' do
119+
source 'com.apple.dt.Xcode.plist.erb'
39120
mode 00644
40121
variables({
41122
:last_gm_license => node['xcode']['last_gm_license'],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test cookbook for use by chefspec and test-kitchen
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name 'xcode_test'
2+
maintainer 'Urbandecoder Labs'
3+
maintainer_email '[email protected]'
4+
license 'Apache 2.0'
5+
description 'Installs Apple XCode and command-line tools'
6+
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7+
version '0.1.0'
8+
9+
depends 'xcode'
10+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include_recipe 'xcode'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
shared_examples 'simple installation of xcode with CLI' do
2+
describe 'Check Xcode CLI' do
3+
describe command('xcode-select -p') do
4+
its(:exit_status) { should eq 0 }
5+
end
6+
7+
describe command('gcc -v') do
8+
its(:exit_status) { should eq 0 }
9+
end
10+
11+
describe command('make -v') do
12+
its(:exit_status) { should eq 0 }
13+
end
14+
end
15+
16+
describe 'Check xcodebuild' do
17+
describe command('xcodebuild -version') do
18+
its(:exit_status) { should eq 0 }
19+
its(:stdout) { should contain('Xcode') }
20+
its(:stdout) { should contain('Build version') }
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)