Skip to content

Commit

Permalink
refactor for mac os x platform support
Browse files Browse the repository at this point in the history
* split default recipe into source and package recipe (follows pattern of other cookbooks)
* externalize source installation metadata into attributes
* verify mac os x platform support
  • Loading branch information
schisamo committed Sep 2, 2011
1 parent 7408077 commit 5abdbbe
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 62 deletions.
39 changes: 25 additions & 14 deletions gecode/README.md
Expand Up @@ -6,34 +6,45 @@ Installs Gecode 3.5.0+ development package.
Requirements
============

Tested on Ubuntu and Debian with Opscode APT repository and build from source.
Platform
--------

Tested on CentOS for build from source. See USAGE for information on installing RPMs.
* Debian, Ubuntu
* Red Hat, CentOS, Fedora
* Mac OS X 10.6+

Requires the following cookbooks:
Cookbooks
---------

* apt - for installing packages from apt.opscode.com
* build-essential - for compiling from source

Attributes
==========

* `node['gecode']['install_method']` - Specifies the recipe to use for installing gecode.
* `node['gecode']['url']` - base url to download from. Default is the Gecode distribution server.
* `node['gecode']['version']` - version of gecode to install.
* `node['gecode']['checksum']` - checksum of the source tarball.
* `node['gecode']['configure_options']` - array of options to pass to ./configure for compiling gecode.

Usage
=====

The recipe is primarily used to install gecode's development package or from source in order to install the `dep_selector` gem, which needs to compile native extensions.
default
-------

Note that compiling gecode takes a long time, up to ~30 minutes on a 4 core Macbook Pro.
Include default recipe in a run list, to get some Gecode installed. Installs Gecode by package or source depending on the platform. The recipe is primarily used to install gecode's development package or from source in order to install the `dep_selector` gem, which needs to compile native extensions.

On Debian and Ubuntu systems, the recipe will attempt to install packages from apt.opscode.com. It uses the apt repository LWRP in Opscode's apt cookbook to enable the repository. For releases after Debian 7.0 (Wheezy) and Ubuntu 11.04 (Natty), Gecode 3.5.0+ exists in the main repositories.
package
-------

On Red Hat family distros, the recipe will attempt to install gecode from source. To install using a package the recipe needs to be updated to account for a package repository. Implementation varies depending on the package repository. For example, to retrieve the /etc/yum.repos.d/somewhere.repo that has the package available, add a condition to the main 'if' block:
Installs Gecode from packages. On Debian and Ubuntu systems, the recipe will attempt to install packages from apt.opscode.com. It uses the apt repository LWRP in Opscode's apt cookbook to enable the repository. For releases after Debian 7.0 (Wheezy) and Ubuntu 11.04 (Natty), Gecode 3.5.0+ exists in the main repositories.

remote_file "/etc/yum.repos.d/somewhere.repo" do
source "http://somewhere.example.com/yum/el5/somewhere.repo"
owner "root"
group "root"
mode 0644
end
source
------

package "gecode-devel"
Installs Gecode from source. Note that compiling gecode takes a long time, up to ~30 minutes on a 4 core Macbook Pro.

Changes/Roadmap
===============
Expand Down
38 changes: 38 additions & 0 deletions gecode/attributes/default.rb
@@ -0,0 +1,38 @@
#
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: gecode
# Attribute:: default
#
# Copyright 2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

case node['platform']
when 'debian', 'ubuntu'
default['gecode']['install_method'] = 'package'
else
default['gecode']['install_method'] = 'source'
end

default['gecode']['url'] = 'http://www.gecode.org/download'
default['gecode']['version'] = '3.5.0'
default['gecode']['checksum'] = '0b2602ce647dd23814d2a7f5f0e757e09f98581b14b95aafbcd9e4c7e0ab4d2a'

default['gecode']['configure_options'] = %w{
--disable-debug
--disable-dependency-tracking
--disable-qt
--prefix=/usr/local
--with-architectures=i386,x86_64
}
10 changes: 8 additions & 2 deletions gecode/metadata.rb
Expand Up @@ -4,5 +4,11 @@
description "Installs gecode"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.0.0"
depends "apt"
depends "build-essential"

%w{ debian ubuntu redhat centos fedora mac_os_x }.each do |os|
supports os
end

%w{ build-essential apt }.each do |cb|
depends cb
end
47 changes: 1 addition & 46 deletions gecode/recipes/default.rb
@@ -1,7 +1,4 @@
#
# Author:: Christopher Walters (<cw@opscode.com>)
# Author:: Nuo Yan (<nuo@opscode.com>)
# Author:: Joshua Timberman (<joshua@opscode.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: gecode
# Recipe:: default
Expand All @@ -20,46 +17,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

case node['platform']
when 'ubuntu','debian'

include_recipe 'apt'

# use opscode apt repo for older releases
if (platform?("debian") && (node.platform_version.to_f < 7.0)) ||
(platform?("ubuntu") && (node.platform_version.to_f < 11.0))

# add Opscode's apt repo to sources
apt_repository "opscode" do
uri "http://apt.opscode.com"
components ["main"]
distribution node['lsb']['codename']
key "2940ABA983EF826A"
keyserver "pgpkeys.mit.edu"
action :add
end

end

apt_package 'libgecode-dev' do
action :install
end

when 'redhat','centos'

include_recipe 'build-essential'

bash "build gecode from source" do
cwd "/tmp"
code <<-EOH
curl -C - -O http://www.gecode.org/download/gecode-3.5.0.tar.gz
tar zxvf gecode-3.5.0.tar.gz
cd gecode-3.5.0 && ./configure
make && make install
EOH
not_if {::File.exists? "/usr/local/lib/libgecodekernel.so" }
end

else
raise "This recipe does not yet support installing Gecode 3.5.0+ for your platform"
end
include_recipe "gecode::#{node['gecode']['install_method']}"
50 changes: 50 additions & 0 deletions gecode/recipes/package.rb
@@ -0,0 +1,50 @@
#
# Author:: Christopher Walters (<cw@opscode.com>)
# Author:: Nuo Yan (<nuo@opscode.com>)
# Author:: Joshua Timberman (<joshua@opscode.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: gecode
# Recipe:: package
#
# Copyright:: Copyright (c) 2011 Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

case node['platform']
when 'ubuntu','debian'

include_recipe 'apt'

# use opscode apt repo for older releases
if (platform?("debian") && (node.platform_version.to_f < 7.0)) ||
(platform?("ubuntu") && (node.platform_version.to_f < 11.0))

# add Opscode's apt repo to sources
apt_repository "opscode" do
uri "http://apt.opscode.com"
components ["main"]
distribution node['lsb']['codename']
key "2940ABA983EF826A"
keyserver "pgpkeys.mit.edu"
action :add
end

end

apt_package 'libgecode-dev' do
action :install
end

else
raise "This recipe does not yet support installing Gecode 3.5.0+ from packages on your platform"
end
40 changes: 40 additions & 0 deletions gecode/recipes/source.rb
@@ -0,0 +1,40 @@
#
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: gecode
# Recipe:: source
#
# Copyright:: Copyright (c) 2011 Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_recipe 'build-essential'

version = node['gecode']['version']

remote_file "#{Chef::Config[:file_cache_path]}/gecode-#{version}.tar.gz" do
source "#{node['gecode']['url']}/gecode-#{version}.tar.gz"
checksum node['gecode']['checksum']
mode 0644
end

lib_name = value_for_platform("mac_os_x" => { "default" => "libgecodekernel.dylib" }, "default" => "libgecodekernel.so")

bash "build gecode from source" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
tar zxvf gecode-#{version}.tar.gz
(cd gecode-#{version} && ./configure #{node['gecode']['configure_options'].join(" ")})
(cd gecode-#{version} && make && make install)
EOH
not_if { ::File.exists?("/usr/local/lib/#{lib_name}") }
end

0 comments on commit 5abdbbe

Please sign in to comment.