spitball 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/spitball +6 -1
- data/lib/ext/bundler_fake_dsl.rb +6 -0
- data/lib/spitball.rb +35 -21
- data/lib/spitball/file_lock.rb +0 -2
- data/lib/spitball/remote.rb +5 -6
- data/lib/spitball/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/spitball_spec.rb +38 -4
- data/spitball.gemspec +1 -0
- metadata +18 -4
data/bin/spitball
CHANGED
@@ -30,6 +30,10 @@ opts = OptionParser.new do |opts|
|
|
30
30
|
args[:without] = without
|
31
31
|
end
|
32
32
|
|
33
|
+
opts.on('-g', '--generate-only', "Only generate, don't download") do
|
34
|
+
args[:generate] = true
|
35
|
+
end
|
36
|
+
|
33
37
|
opts.separator ""
|
34
38
|
opts.separator "environment variables:"
|
35
39
|
opts.separator "\tSPITBALL_CACHE\t\t Specifies the cache dir. Defaults to /tmp/spitball"
|
@@ -53,4 +57,5 @@ ball = args[:host] ?
|
|
53
57
|
Spitball::Remote.new(gemfile, gemfile_lock, :host => args[:host], :port => (args[:port] || 8080).to_i, :without => args[:without]) :
|
54
58
|
Spitball.new(gemfile, gemfile_lock, :without => args[:without])
|
55
59
|
|
56
|
-
ball.copy_to
|
60
|
+
args[:generate] ? ball.cache! : ball.copy_to(args[:destination])
|
61
|
+
|
data/lib/ext/bundler_fake_dsl.rb
CHANGED
@@ -3,6 +3,7 @@ module Bundler
|
|
3
3
|
|
4
4
|
def initialize(file)
|
5
5
|
@groups = Hash.new{|h, k| h[k] = []}
|
6
|
+
@gem_names = []
|
6
7
|
instance_eval(file)
|
7
8
|
end
|
8
9
|
|
@@ -10,6 +11,10 @@ module Bundler
|
|
10
11
|
@groups
|
11
12
|
end
|
12
13
|
|
14
|
+
def __gem_names
|
15
|
+
@gem_names
|
16
|
+
end
|
17
|
+
|
13
18
|
def group(name, &blk)
|
14
19
|
@current_group = name.to_sym
|
15
20
|
instance_eval(&blk)
|
@@ -18,6 +23,7 @@ module Bundler
|
|
18
23
|
alias_method :groups, :group
|
19
24
|
|
20
25
|
def gem(*args)
|
26
|
+
@gem_names << args.first
|
21
27
|
@groups[@current_group] << args.first
|
22
28
|
end
|
23
29
|
|
data/lib/spitball.rb
CHANGED
@@ -25,10 +25,14 @@ class Spitball
|
|
25
25
|
attr_reader :gemfile, :gemfile_lock, :without, :options
|
26
26
|
|
27
27
|
def initialize(gemfile, gemfile_lock, options = {})
|
28
|
+
Spitball::Repo.make_cache_dirs
|
28
29
|
@gemfile = gemfile
|
29
30
|
@gemfile_lock = gemfile_lock
|
30
31
|
@options = options
|
31
32
|
@without = (options[:without] || []).map{|w| w.to_sym}
|
33
|
+
@parsed_lockfile, @dsl = Bundler::FakeLockfileParser.new(gemfile_lock), Bundler::FakeDsl.new(gemfile)
|
34
|
+
raise "You need to run bundle install before you can use spitball" unless (@parsed_lockfile.dependencies.map{|d| d.name}.uniq.sort == @dsl.__gem_names.uniq.sort)
|
35
|
+
@groups_to_install = @dsl.__groups.keys - @without
|
32
36
|
end
|
33
37
|
|
34
38
|
def cached?
|
@@ -36,18 +40,16 @@ class Spitball
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def cache!(sync = true)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
lock.release_lock
|
47
|
-
end
|
48
|
-
elsif sync
|
49
|
-
sleep 0.1 until cached?
|
43
|
+
return if cached?
|
44
|
+
lock = Spitball::FileLock.new(bundle_path('lock'))
|
45
|
+
if lock.acquire_lock
|
46
|
+
begin
|
47
|
+
create_bundle
|
48
|
+
ensure
|
49
|
+
lock.release_lock
|
50
50
|
end
|
51
|
+
elsif sync
|
52
|
+
sleep 0.1 until cached?
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
@@ -59,7 +61,6 @@ class Spitball
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def create_bundle
|
62
|
-
ENV['BUNDLE_GEMFILE'] = gemfile_path # make bundler happy! :) *cry*
|
63
64
|
Spitball::Repo.make_cache_dirs
|
64
65
|
FileUtils.mkdir_p bundle_path
|
65
66
|
|
@@ -67,11 +68,9 @@ class Spitball
|
|
67
68
|
File.open(gemfile_path, 'w') {|f| f.write gemfile }
|
68
69
|
File.open(gemfile_lock_path, 'w') {|f| f.write gemfile_lock }
|
69
70
|
|
70
|
-
parsed_lockfile, dsl = Bundler::FakeLockfileParser.new(gemfile_lock), Bundler::FakeDsl.new(gemfile)
|
71
|
-
|
72
71
|
Dir.chdir(Repo.gemcache_path) do
|
73
|
-
|
74
|
-
install_gem(
|
72
|
+
@dsl.__gem_names.each do |spec_name|
|
73
|
+
install_gem(@parsed_lockfile.specs.find {|spec| spec.name == spec_name})
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
@@ -89,12 +88,27 @@ class Spitball
|
|
89
88
|
FileUtils.rm_rf bundle_path
|
90
89
|
end
|
91
90
|
|
92
|
-
def install_gem(spec
|
93
|
-
|
91
|
+
def install_gem(spec)
|
92
|
+
if @groups_to_install.any?{|group| @dsl.__groups[group].include?(spec.name)}
|
93
|
+
install_and_copy_spec(spec)
|
94
|
+
spec.dependencies.each do |dep|
|
95
|
+
install_gem(@parsed_lockfile.specs.find {|spec| spec.name == dep.name})
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
def install_and_copy_spec(spec)
|
102
|
+
cache_dir = File.join(Repo.gemcache_path, "#{spec.name}-#{::Digest::MD5.hexdigest([spec.name, spec.version, sources_opt(@parsed_lockfile.sources)].join('/'))}")
|
94
103
|
unless File.exist?(cache_dir)
|
95
104
|
FileUtils.mkdir_p(cache_dir)
|
96
|
-
out = `gem install #{spec.name} -v'#{spec.version}' --no-rdoc --no-ri --ignore-dependencies -i#{cache_dir} #{sources_opt(sources)} 2>&1`
|
97
|
-
$? == 0
|
105
|
+
out = `gem install #{spec.name} -v'#{spec.version}' --no-rdoc --no-ri --ignore-dependencies -i#{cache_dir} #{sources_opt(@parsed_lockfile.sources)} 2>&1`
|
106
|
+
if $? == 0
|
107
|
+
puts out
|
108
|
+
else
|
109
|
+
FileUtils.rm_rf(cache_dir)
|
110
|
+
raise BundleCreationFailure, out
|
111
|
+
end
|
98
112
|
else
|
99
113
|
puts "Using cached version of #{spec.name} (#{spec.version})"
|
100
114
|
end
|
@@ -128,4 +142,4 @@ class Spitball
|
|
128
142
|
def tarball_path
|
129
143
|
Repo.bundle_path(digest, 'tgz')
|
130
144
|
end
|
131
|
-
end
|
145
|
+
end
|
data/lib/spitball/file_lock.rb
CHANGED
data/lib/spitball/remote.rb
CHANGED
@@ -7,12 +7,11 @@ class Spitball::Remote
|
|
7
7
|
include Spitball::ClientCommon
|
8
8
|
|
9
9
|
def initialize(gemfile, gemfile_lock, opts = {})
|
10
|
-
@gemfile = gemfile
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@cache_dir = '/tmp/spitball/client'
|
10
|
+
@gemfile, @gemfile_lock = gemfile, gemfile_lock
|
11
|
+
@host = opts[:host]
|
12
|
+
@port = opts[:port]
|
13
|
+
@without = (opts[:without] || []).map{|w| w.to_sym}
|
14
|
+
@cache_dir = File.join(ENV['SPITBALL_CACHE'] || '/tmp/spitball', 'client')
|
16
15
|
FileUtils.mkdir_p(@cache_dir)
|
17
16
|
use_cache_file
|
18
17
|
end
|
data/lib/spitball/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/spitball_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe Spitball do
|
|
28
28
|
describe "cached?" do
|
29
29
|
it "returns true if the tarball has already been cached" do
|
30
30
|
@spitball.should_not be_cached
|
31
|
-
mock(@spitball).install_gem(anything
|
31
|
+
mock(@spitball).install_gem(anything).times(any_times)
|
32
32
|
@spitball.cache!
|
33
33
|
@spitball.should be_cached
|
34
34
|
end
|
@@ -82,7 +82,7 @@ describe Spitball do
|
|
82
82
|
|
83
83
|
describe "create_bundle" do
|
84
84
|
it "generates a bundle at the bundle_path" do
|
85
|
-
mock(@spitball).install_gem(anything
|
85
|
+
mock(@spitball).install_gem(anything).times(any_times)
|
86
86
|
capture_stdout { @spitball.send :create_bundle }
|
87
87
|
File.exist?(@spitball.send(:tarball_path)).should == true
|
88
88
|
end
|
@@ -127,10 +127,10 @@ describe Spitball do
|
|
127
127
|
|
128
128
|
it "should use without" do
|
129
129
|
@spitball = Spitball.new(@gemfile, @lockfile)
|
130
|
-
mock(@spitball).
|
130
|
+
mock(@spitball).install_and_copy_spec(anything).times(1)
|
131
131
|
@spitball.send :create_bundle
|
132
132
|
@spitball = Spitball.new(@gemfile, @lockfile, :without => 'development')
|
133
|
-
mock(@spitball).
|
133
|
+
mock(@spitball).install_and_copy_spec(anything).times(0)
|
134
134
|
@spitball.send :create_bundle
|
135
135
|
end
|
136
136
|
end
|
@@ -255,3 +255,37 @@ describe Spitball::Digest do
|
|
255
255
|
spitball.hash.should == spitball.digest.hash
|
256
256
|
end
|
257
257
|
end
|
258
|
+
|
259
|
+
describe Spitball do
|
260
|
+
context "mismatched" do
|
261
|
+
before do
|
262
|
+
use_success_bundler
|
263
|
+
|
264
|
+
@gemfile = <<-end_gemfile
|
265
|
+
source :rubygems
|
266
|
+
gem "json_pure"
|
267
|
+
gem "somethingelse"
|
268
|
+
end_gemfile
|
269
|
+
|
270
|
+
@lockfile = <<-end_lockfile.strip.gsub(/\n[ ]{6}/m, "\n")
|
271
|
+
GEM
|
272
|
+
remote: http://rubygems.org/
|
273
|
+
specs:
|
274
|
+
json_pure (1.4.6)
|
275
|
+
|
276
|
+
PLATFORMS
|
277
|
+
ruby
|
278
|
+
|
279
|
+
DEPENDENCIES
|
280
|
+
json_pure
|
281
|
+
end_lockfile
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "create_bundle failure" do
|
286
|
+
it "should raise on create_bundle" do
|
287
|
+
proc { Spitball.new(@gemfile, @lockfile) }.should raise_error
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
data/spitball.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_development_dependency 'rspec', "~> 1.3.0"
|
19
19
|
s.add_development_dependency 'rr'
|
20
20
|
s.add_development_dependency 'rake'
|
21
|
+
s.add_development_dependency 'phocus'
|
21
22
|
|
22
23
|
s.files = `git ls-files`.split("\n")
|
23
24
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spitball
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Freels
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date:
|
20
|
+
date: 2011-01-06 00:00:00 -08:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -79,6 +79,20 @@ dependencies:
|
|
79
79
|
version: "0"
|
80
80
|
type: :development
|
81
81
|
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: phocus
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
type: :development
|
95
|
+
version_requirements: *id005
|
82
96
|
description: Use bundler to generate gem tarball packages.
|
83
97
|
email: freels@twitter.com
|
84
98
|
executables:
|