appbundler 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0348af66452b0695266e8851955c74cb513c6d33
4
- data.tar.gz: b433848ae1903bf318a884ec0f9488d2c348b08a
3
+ metadata.gz: 8a1fd7bc87996da30552d62721509d3a484bae9a
4
+ data.tar.gz: baa24d302fe668c28c6effde641deefb15bd7d4c
5
5
  SHA512:
6
- metadata.gz: 4a8a09d3e326fc70173eccf345d80b08d9ac02bb1b06eeafcbb0f59cd9983dc43dc259616f000dd187e9426ba024aefdd92a9ef4c859b4191176893aa1951e7c
7
- data.tar.gz: a4aca9f94ff5ce9ab7a57724ef189f6f847e4350fd675b3cdb32c56700d3d8a94917a38bf16910e64713a7f814c6e4097ef9bc99de6dfbace7900a890e9984bc
6
+ metadata.gz: 18bf2d0045537e2470b3e207bf8d440735fdeb1d3d176365b70d8c177b366b33aa9f652830da18e45777c014f42c4142ba668cfd9110fdd21ca9ef68e488013a
7
+ data.tar.gz: bdf6397f23af82894d6abab6a01728ee484b11a4c394f2bcaac88cf7c42767cfd18db858cb6cd9b625f21ada3145e02abefbd6f139935f270a6e77b46e44c030
@@ -107,18 +107,50 @@ E
107
107
  activate_code = ""
108
108
  activate_code << env_sanitizer << "\n"
109
109
  activate_code << statements.join("\n") << "\n"
110
- activate_code << %Q|$:.unshift "#{app_lib_dir}"\n|
110
+ activate_code << %Q|$:.unshift(File.expand_path("#{relative_app_lib_dir}", File.dirname(__FILE__)))\n|
111
111
  activate_code
112
112
  end
113
113
  end
114
114
 
115
115
  def binstub(bin_file)
116
- shebang + file_format_comment + runtime_activate + "Kernel.load '#{bin_file}'\n"
116
+ shebang + file_format_comment + runtime_activate + load_statement_for(bin_file)
117
+ end
118
+
119
+ def load_statement_for(bin_file)
120
+ "Kernel.load(File.expand_path('#{relative_bin_file(bin_file)}', File.dirname(__FILE__)))\n"
121
+ end
122
+
123
+ def relative_bin_file(bin_file)
124
+ bin_file_pathname = Pathname.new(bin_file)
125
+ bindir_pathname = Pathname.new(target_bin_dir)
126
+ bin_file_pathname.relative_path_from(bindir_pathname).to_s
117
127
  end
118
128
 
119
129
  def executables
120
- bin_dir_glob = File.join(app_root, "bin", "*")
121
- Dir[bin_dir_glob]
130
+ spec_path = ["#{app_root}/#{name}-#{RUBY_PLATFORM}.gemspec",
131
+ "#{app_root}/#{name}.gemspec"].detect do |f|
132
+ File.exists?(f)
133
+ end
134
+
135
+ if spec_path
136
+ spec = nil
137
+ Dir.chdir(app_root) do
138
+ spec = Gem::Specification::load(spec_path)
139
+ end
140
+ spec.executables.map do |e|
141
+ File.join(app_root, spec.bindir, e)
142
+ end
143
+ else
144
+ bin_dir_glob = File.join(app_root, "bin", "*")
145
+ Dir[bin_dir_glob]
146
+ end
147
+
148
+ end
149
+
150
+ def relative_app_lib_dir
151
+ lib_dir_pathname = Pathname.new(app_lib_dir)
152
+ bindir_pathname = Pathname.new(target_bin_dir)
153
+ lib_dir_pathname.relative_path_from(bindir_pathname).to_s
122
154
  end
123
155
 
124
156
  def app_lib_dir
@@ -1,3 +1,3 @@
1
1
  module Appbundler
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -93,7 +93,16 @@ describe Appbundler do
93
93
  end
94
94
 
95
95
  it "adds the app code to the load path" do
96
- expect(app.runtime_activate).to include('$:.unshift "/opt/app/embedded/apps/app/lib"')
96
+ # Our test setup makes an executable that needs to load a path in the
97
+ # fictitious /opt/app/embedded/apps/app/lib path, so the relative path
98
+ # will traverse all the way to the root and then back up. Therefore, the
99
+ # expected output is dependent on how many directories deep this source
100
+ # clone is from the root:
101
+ relpath_to_root = Pathname.new("/").relative_path_from(Pathname.new(File.dirname(__FILE__))).to_s
102
+
103
+ expected_code_path =
104
+ %Q[$:.unshift(File.expand_path("#{relpath_to_root}/../opt/app/embedded/apps/app/lib", File.dirname(__FILE__)))]
105
+ expect(app.runtime_activate).to include(expected_code_path)
97
106
  end
98
107
 
99
108
  it "generates code to override GEM_HOME and GEM_PATH (e.g., rvm)" do
@@ -198,10 +207,14 @@ gem "puma", "= 1.6.3"
198
207
  gem "rest-client", "= 1.6.7"
199
208
  E
200
209
  expect(app.runtime_activate).to include(expected_gem_activates)
201
- expected_load_path = '$:.unshift "' + File.join(app_root, "lib") + '"'
210
+ expected_load_path = %q[$:.unshift(File.expand_path("../../fixtures/example-app/lib", File.dirname(__FILE__)))]
202
211
  expect(app.runtime_activate).to include(expected_load_path)
203
212
  end
204
213
 
214
+ it "should not contain exclude-me as a binary" do
215
+ expect(app.executables).not_to include(File.join(app_root, "/bin", "exclude-me"))
216
+ end
217
+
205
218
  it "lists the app's executables" do
206
219
  expected_executables = %w[app-binary-1 app-binary-2].map do |basename|
207
220
  File.join(app_root, "/bin", basename)
@@ -220,15 +233,20 @@ E
220
233
  expect(executable_content).to include(app.runtime_activate)
221
234
 
222
235
  load_binary = executable_content.lines.to_a.last
223
- expect(load_binary).to eq(%Q[Kernel.load '#{app_binary_1_path}'\n])
236
+
237
+ expected_load_path = %Q[Kernel.load(File.expand_path('../../fixtures/example-app/bin/app-binary-1', File.dirname(__FILE__)))\n]
238
+
239
+ expect(load_binary).to eq(expected_load_path)
224
240
  end
225
241
 
226
242
  it "generates executable stubs for all executables in the app" do
227
243
  app.write_executable_stubs
228
244
  binary_1 = File.join(target_bindir, "app-binary-1")
229
245
  binary_2 = File.join(target_bindir, "app-binary-2")
246
+ excluded_binary = File.join(target_bindir, "exclude-me")
230
247
  expect(File.exist?(binary_1)).to be_true
231
248
  expect(File.exist?(binary_2)).to be_true
249
+ expect(File.exist?(excluded_binary)).to be_false
232
250
  expect(File.executable?(binary_1)).to be_true
233
251
  expect(File.executable?(binary_1)).to be_true
234
252
  expect(shellout!(binary_1).stdout).to eq("binary 1 ran\n")
@@ -261,6 +279,7 @@ E
261
279
  expect(IO.read(binary_1)).to eq(expected_batch_code)
262
280
  expect(IO.read(binary_2)).to eq(expected_batch_code)
263
281
  end
282
+
264
283
  end
265
284
 
266
285
  end
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ puts "exclude-me should not have run"
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.homepage = ""
11
11
  spec.license = "Apache2"
12
12
 
13
- spec.files = Dir.glob("{bin,lib,spec}/**/*").reject {|f| File.directory?(f) }
14
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.files = Dir.glob("{lib,spec}/**/*").reject {|f| File.directory?(f) }
14
+ spec.executables = %w(app-binary-1 app-binary-2)
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ["lib"]
17
17
 
data/spec/spec_helper.rb CHANGED
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |c|
2
+ c.treat_symbols_as_metadata_keys_with_true_values = true
3
+ c.filter_run :focus => true
4
+ c.run_all_when_everything_filtered = true
5
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appbundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - danielsdeleo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-02 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.13'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.13'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mixlib-shellout
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
69
  description: Extracts a dependency solution from bundler's Gemfile.lock to speed gem
@@ -75,9 +75,9 @@ executables:
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
79
- - .rspec
80
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
81
  - Gemfile
82
82
  - LICENSE.txt
83
83
  - README.md
@@ -94,6 +94,7 @@ files:
94
94
  - spec/fixtures/example-app/README.md
95
95
  - spec/fixtures/example-app/bin/app-binary-1
96
96
  - spec/fixtures/example-app/bin/app-binary-2
97
+ - spec/fixtures/example-app/bin/exclude-me
97
98
  - spec/fixtures/example-app/example-app.gemspec
98
99
  - spec/fixtures/example-app/lib/example_app.rb
99
100
  - spec/spec_helper.rb
@@ -107,17 +108,17 @@ require_paths:
107
108
  - lib
108
109
  required_ruby_version: !ruby/object:Gem::Requirement
109
110
  requirements:
110
- - - '>='
111
+ - - ">="
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0'
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - '>='
116
+ - - ">="
116
117
  - !ruby/object:Gem::Version
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.0.3
121
+ rubygems_version: 2.2.2
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Extracts a dependency solution from bundler's Gemfile.lock to speed gem activation
@@ -128,6 +129,7 @@ test_files:
128
129
  - spec/fixtures/example-app/README.md
129
130
  - spec/fixtures/example-app/bin/app-binary-1
130
131
  - spec/fixtures/example-app/bin/app-binary-2
132
+ - spec/fixtures/example-app/bin/exclude-me
131
133
  - spec/fixtures/example-app/example-app.gemspec
132
134
  - spec/fixtures/example-app/lib/example_app.rb
133
135
  - spec/spec_helper.rb