Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAB containers #1992

Merged
merged 1 commit into from
Feb 8, 2014
Merged
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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: objective-c
before_install: brew update
before_install:
- brew update
- brew install cabextract
install: bundle
script: bundle exec rake test
notifications:
Expand Down
2 changes: 2 additions & 0 deletions lib/cask/container.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Cask::Container; end

require 'cask/container/base'
require 'cask/container/cab'
require 'cask/container/criteria'
require 'cask/container/dmg'
require 'cask/container/naked'
Expand All @@ -10,6 +11,7 @@ class Cask::Container; end
class Cask::Container
def self.containers
[
Cask::Container::Cab,
Cask::Container::Dmg,
Cask::Container::Tar,
Cask::Container::Zip,
Expand Down
20 changes: 20 additions & 0 deletions lib/cask/container/cab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'tmpdir'

class Cask::Container::Cab < Cask::Container::Base
def self.me?(criteria)
(criteria.file.include? 'application/octet-stream;' or
criteria.file.include? 'application/vnd.ms-cab-compressed;') and
criteria.cabextract.include? 'All done, no errors'
end

def extract
cabextract = HOMEBREW_PREFIX.join('bin/cabextract')
if ! Pathname.new(cabextract).exist?
raise "Expected to find cabextract executable. Cask #{@cask} must add 'depends_on_formula'"
end
Dir.mktmpdir do |staging_dir|
@command.run!(cabextract, :args => ['-d', staging_dir, '--', @path])
@command.run!('/usr/bin/ditto', :args => ['--', staging_dir, @cask.destination_path])
end
end
end
9 changes: 9 additions & 0 deletions lib/cask/container/criteria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ def imageinfo
:print => false
)
end

def cabextract
@cabextract ||= @command.run(
HOMEBREW_PREFIX.join('bin/cabextract'),
:args => ['-t', '--', path],
:stderr => :silence,
:print => false
)
end
end
19 changes: 19 additions & 0 deletions test/cask/installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@
application.must_be :directory?
end

it "works with cab-based casks" do
skip unless HOMEBREW_PREFIX.join('bin/cabextract').exist?
cab_container = Cask.load('cab-container')

# because I don't know how to do the mocking properly
def cab_container.depends_on_formula
[]
end

shutup do
Cask::Installer.new(cab_container).install
end

dest_path = Cask.caskroom/'cab-container'/cab_container.version
dest_path.must_be :directory?
application = dest_path/'cabcontainer/Application.app'
application.must_be :directory?
end

it "blows up on a bad checksum" do
bad_checksum = Cask.load('bad-checksum')
lambda {
Expand Down
8 changes: 8 additions & 0 deletions test/support/Casks/cab-container.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CabContainer < TestCask
url TestHelper.local_binary('cabcontainer.cab')
homepage 'http://example.com/cab-container'
version '1.2.3'
sha1 '85bfbcfc8887a995ae0e724796a0c242341b3071'
depends_on_formula 'cabextract'
link 'cabcontainer/Application.app'
end
Binary file added test/support/binaries/cabcontainer.cab
Binary file not shown.
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ def self.install_without_artifacts(cask)
project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../"))
taps_dest = HOMEBREW_LIBRARY/"Taps"

# create directories
taps_dest.mkdir
HOMEBREW_PREFIX.join('bin').mkdir

FileUtils.ln_s project_root, taps_dest/"phinze-cask"

# Common superclass for tests casks for when we need to filter them out
class TestCask < Cask; end

# jack in some optional utilities
FileUtils.ln_s '/usr/local/bin/cabextract', HOMEBREW_PREFIX.join('bin/cabextract')

# also jack in some test casks
FileUtils.ln_s project_root/'test'/'support', taps_dest/"phinze-testcasks"