Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ vendor/bundle
build/*
.kitchen/
*.lock
.kitchen.local.yml
11 changes: 10 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ suites:
cmake:
install_method: source
source:
version: 2.8.12.2
version: 3.2.3
checksum: "a1ebcaf6d288eb4c966714ea457e3b9677cdfde78820d0f088712d7320850297"
- name: binary
run_list:
- recipe[cmake]
attributes:
cmake:
install_method: binary
binary:
prefix: "/opt/local"
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ This cookbook installs the cmake components if not present, and pulls updates if
## Attributes

```ruby
default["cmake"]["install_method"] = "package" # `package` or `source`
default["cmake"]["install_method"] = "package" # `package`, `source`, or `binary`

default["cmake"]["source"]["version"] = "2.8.12.2"
default["cmake"]["source"]["checksum"] = "8c6574e9afabcb9fc66f463bb1f2f051958d86c85c37fccf067eb1a44a120e5e"
default["cmake"]["source"]["version"] = "3.2.3"
default["cmake"]["source"]["checksum"] = "e7be87a6cfc403785ab9d5846a70be2c27b17fda6a9b7442e9fc7af45c077d63"

default["cmake"]["binary"]["version"] = "LATEST"
default["cmake"]["binary"]["prefix"] = "/usr/local"
```


Expand Down
27 changes: 27 additions & 0 deletions attributes/binary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Cookbook:: cmake
# Attributes:: binary
#

# have to defer getting latest version until after git is installed.
# Ideally, git would be run on the host rather than the guest so that
# git didn't have to be installed
default["cmake"]["binary"]["version"] = "LATEST"
default["cmake"]["binary"]["repo"] = "https://github.com/Kitware/CMake.git"
default["cmake"]["binary"]["prefix"] = "/usr/local"

case node["kernel"]["machine"]
when "amd64", "x86_64"
default["cmake"]["binary"]["architecture"] = "x86_64"
when "i386", "i686"
default["cmake"]["binary"]["architecture"] = "i386"
else
fail "Unsupported processor: '#{node['kernel']['machine']}'"
end

case node["platform"]
when "debian", "ubuntu", "redhat", "centos", "fedora"
default["cmake"]["binary"]["platform"] = "Linux"
else
fail "Unsupported platform: '#{node['platform']}'"
end
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# Attributes:: default
#

default["cmake"]["install_method"] = "package" # `package` or `source`
# `package`, `source`, or `binary`
default["cmake"]["install_method"] = "package"
5 changes: 3 additions & 2 deletions attributes/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
# Attributes:: source
#

default["cmake"]["source"]["version"] = "2.8.12.2"
default["cmake"]["source"]["checksum"] = "8c6574e9afabcb9fc66f463bb1f2f051958d86c85c37fccf067eb1a44a120e5e"
# TODO: make this use the "LATEST", like `binary`
default["cmake"]["source"]["version"] = "3.2.3"
default["cmake"]["source"]["checksum"] = "a1ebcaf6d288eb4c966714ea457e3b9677cdfde78820d0f088712d7320850297"
1 change: 1 addition & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
supports "fedora"

suggests "build-essential"
suggests "git"
51 changes: 51 additions & 0 deletions recipes/_binary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Cookbook:: cmake
# Recipe:: _binary
#

cache_dir = Chef::Config[:file_cache_path]
cmake_platform = node["cmake"]["binary"]["platform"]
cmake_arch = node["cmake"]["binary"]["architecture"]
cmake_repo = node["cmake"]["binary"]["repo"]
cmake_prefix = node["cmake"]["binary"]["prefix"]

package "git" do
action :install
only_if { node["cmake"]["binary"]["version"] == "LATEST" }
end

ruby_block "get latest" do
block do
if node["cmake"]["binary"]["version"] == "LATEST"
vers = []
IO.popen("git ls-remote -t #{cmake_repo}").each do |line|
m = line.match(%r{^\S+\s+refs\/tags\/v(\d+.\d+.\d+)$})
if m
vers.push(Gem::Version.new(m[1])) # sort semver-ly
end
end
vers.sort
node.set["cmake"]["binary"]["version"] = vers[-1].to_s
end
node.set["cmake"]["binary"]["sh"] = "cmake-#{node['cmake']['binary']['version']}-#{cmake_platform}-#{cmake_arch}.sh" # rubocop:disable LineLength
end
end

remote_file "get sh" do
path lazy { "#{cache_dir}/#{node['cmake']['binary']['sh']}" }
source lazy { "http://www.cmake.org/files/v#{node['cmake']['binary']['version'][/^\d\.\d/, 0]}/#{node['cmake']['binary']['sh']}" } # rubocop:disable LineLength
end

directory "prefix" do
path lazy { cmake_prefix }
owner 'root'
group 'root'
mode '0755'
action :create
end

execute "cmake install" do
command lazy { "bash #{cache_dir}/#{node['cmake']['binary']['sh']} --prefix=#{cmake_prefix} --exclude-subdir" } # rubocop:disable LineLength
cwd "/tmp"
creates "#{cmake_prefix}/bin/cmake"
end
10 changes: 10 additions & 0 deletions spec/binary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "spec_helper"

describe "cmake::_binary" do
let(:chef_run) do
ChefSpec::Runner.new do |node|
node.set["cmake"]["install_method"] = "binary"
end.converge("git", described_recipe)
end

end