appbundler 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a1fd7bc87996da30552d62721509d3a484bae9a
4
- data.tar.gz: baa24d302fe668c28c6effde641deefb15bd7d4c
3
+ metadata.gz: dd0a654c110cf3a6b807f33d19689b79efd7a262
4
+ data.tar.gz: 16c4a093480e83d996a0c5dfc57445a734f80897
5
5
  SHA512:
6
- metadata.gz: 18bf2d0045537e2470b3e207bf8d440735fdeb1d3d176365b70d8c177b366b33aa9f652830da18e45777c014f42c4142ba668cfd9110fdd21ca9ef68e488013a
7
- data.tar.gz: bdf6397f23af82894d6abab6a01728ee484b11a4c394f2bcaac88cf7c42767cfd18db858cb6cd9b625f21ada3145e02abefbd6f139935f270a6e77b46e44c030
6
+ metadata.gz: acf6f4adf3b2c5b276c67f5c052b43b71d6bf1edec7bb81eed0c77e7df50742f7ed2250a106d3e3beea53c4b86dba01e2a2f15518ad7c5d576c86da64bf48c1b
7
+ data.tar.gz: a655313efa7c602cb1f700fdcdf0ce876627a61b8149d808c7e4ea792116ab19cce9b16ae4eb860fac490f51645b8b97cd1de90afb8d720cfd5580a5245a18a8
@@ -107,7 +107,6 @@ 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(File.expand_path("#{relative_app_lib_dir}", File.dirname(__FILE__)))\n|
111
110
  activate_code
112
111
  end
113
112
  end
@@ -117,7 +116,15 @@ E
117
116
  end
118
117
 
119
118
  def load_statement_for(bin_file)
120
- "Kernel.load(File.expand_path('#{relative_bin_file(bin_file)}', File.dirname(__FILE__)))\n"
119
+ <<-E
120
+ bin_dir = File.dirname(__FILE__)
121
+ if File.symlink?(__FILE__)
122
+ bin_dir = File.dirname(File.readlink(__FILE__))
123
+ end
124
+
125
+ $:.unshift(File.expand_path("#{relative_app_lib_dir}", bin_dir))
126
+ Kernel.load(File.expand_path('#{relative_bin_file(bin_file)}', bin_dir))
127
+ E
121
128
  end
122
129
 
123
130
  def relative_bin_file(bin_file)
@@ -127,24 +134,8 @@ E
127
134
  end
128
135
 
129
136
  def executables
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
-
137
+ bin_dir_glob = File.join(app_root, "bin", "*")
138
+ Dir[bin_dir_glob]
148
139
  end
149
140
 
150
141
  def relative_app_lib_dir
@@ -1,3 +1,3 @@
1
1
  module Appbundler
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'tmpdir'
2
3
  require 'fileutils'
3
4
  require 'mixlib/shellout'
4
5
  require 'appbundler/app'
@@ -51,6 +52,8 @@ describe Appbundler do
51
52
  double_spec(:app, "1.0.0", [:first_level_dep_a, :first_level_dep_b])
52
53
  end
53
54
 
55
+ let(:bin_path) { File.join(target_bindir, "foo") }
56
+
54
57
  let(:app_root) { "/opt/app/embedded/apps/app" }
55
58
 
56
59
  let(:app) do
@@ -92,6 +95,17 @@ describe Appbundler do
92
95
  expect(app.runtime_activate).to_not include(%q{gem "app"})
93
96
  end
94
97
 
98
+ it "adds symlink resolution to the code that activates the app" do
99
+ symlink_code = <<-E
100
+ bin_dir = File.dirname(__FILE__)
101
+ if File.symlink?(__FILE__)
102
+ bin_dir = File.dirname(File.readlink(__FILE__))
103
+ end
104
+ E
105
+
106
+ expect(app.load_statement_for(bin_path)).to include(symlink_code)
107
+ end
108
+
95
109
  it "adds the app code to the load path" do
96
110
  # Our test setup makes an executable that needs to load a path in the
97
111
  # fictitious /opt/app/embedded/apps/app/lib path, so the relative path
@@ -101,8 +115,8 @@ describe Appbundler do
101
115
  relpath_to_root = Pathname.new("/").relative_path_from(Pathname.new(File.dirname(__FILE__))).to_s
102
116
 
103
117
  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)
118
+ %Q[$:.unshift(File.expand_path("#{relpath_to_root}/../opt/app/embedded/apps/app/lib", bin_dir))]
119
+ expect(app.load_statement_for(bin_path)).to include(expected_code_path)
106
120
  end
107
121
 
108
122
  it "generates code to override GEM_HOME and GEM_PATH (e.g., rvm)" do
@@ -207,12 +221,6 @@ gem "puma", "= 1.6.3"
207
221
  gem "rest-client", "= 1.6.7"
208
222
  E
209
223
  expect(app.runtime_activate).to include(expected_gem_activates)
210
- expected_load_path = %q[$:.unshift(File.expand_path("../../fixtures/example-app/lib", File.dirname(__FILE__)))]
211
- expect(app.runtime_activate).to include(expected_load_path)
212
- end
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
224
  end
217
225
 
218
226
  it "lists the app's executables" do
@@ -234,7 +242,7 @@ E
234
242
 
235
243
  load_binary = executable_content.lines.to_a.last
236
244
 
237
- expected_load_path = %Q[Kernel.load(File.expand_path('../../fixtures/example-app/bin/app-binary-1', File.dirname(__FILE__)))\n]
245
+ expected_load_path = %Q[Kernel.load(File.expand_path('../../fixtures/example-app/bin/app-binary-1', bin_dir))\n]
238
246
 
239
247
  expect(load_binary).to eq(expected_load_path)
240
248
  end
@@ -243,16 +251,45 @@ E
243
251
  app.write_executable_stubs
244
252
  binary_1 = File.join(target_bindir, "app-binary-1")
245
253
  binary_2 = File.join(target_bindir, "app-binary-2")
246
- excluded_binary = File.join(target_bindir, "exclude-me")
247
254
  expect(File.exist?(binary_1)).to be_true
248
255
  expect(File.exist?(binary_2)).to be_true
249
- expect(File.exist?(excluded_binary)).to be_false
250
256
  expect(File.executable?(binary_1)).to be_true
251
257
  expect(File.executable?(binary_1)).to be_true
252
258
  expect(shellout!(binary_1).stdout).to eq("binary 1 ran\n")
253
259
  expect(shellout!(binary_2).stdout).to eq("binary 2 ran\n")
254
260
  end
255
261
 
262
+ context "and the executable is symlinked to a different directory" do
263
+
264
+ let(:symlinks_root_dir) do
265
+ Dir.mktmpdir
266
+ end
267
+
268
+ let(:symlinks_bin_dir) do
269
+ d = File.join(symlinks_root_dir, "bin")
270
+ FileUtils.mkdir(d)
271
+ d
272
+ end
273
+
274
+ let(:binary_symlinked_path) { File.join(symlinks_bin_dir, "app-binary-1") }
275
+
276
+ let(:binary_orignal_path) { File.join(target_bindir, "app-binary-1") }
277
+
278
+ before do
279
+ app.write_executable_stubs
280
+ FileUtils.ln_s(binary_orignal_path, binary_symlinked_path)
281
+ end
282
+
283
+ after do
284
+ FileUtils.rm_rf(symlinks_root_dir)
285
+ end
286
+
287
+ it "correctly runs the executable via the symlinked executable" do
288
+ expect(shellout!(binary_symlinked_path).stdout).to eq("binary 1 ran\n")
289
+ end
290
+
291
+ end
292
+
256
293
  context "on windows" do
257
294
 
258
295
  let(:expected_ruby_relpath) do
@@ -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("{lib,spec}/**/*").reject {|f| File.directory?(f) }
14
- spec.executables = %w(app-binary-1 app-binary-2)
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) }
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ["lib"]
17
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appbundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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-11-04 00:00:00.000000000 Z
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -94,7 +94,6 @@ 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
98
97
  - spec/fixtures/example-app/example-app.gemspec
99
98
  - spec/fixtures/example-app/lib/example_app.rb
100
99
  - spec/spec_helper.rb
@@ -129,7 +128,6 @@ test_files:
129
128
  - spec/fixtures/example-app/README.md
130
129
  - spec/fixtures/example-app/bin/app-binary-1
131
130
  - spec/fixtures/example-app/bin/app-binary-2
132
- - spec/fixtures/example-app/bin/exclude-me
133
131
  - spec/fixtures/example-app/example-app.gemspec
134
132
  - spec/fixtures/example-app/lib/example_app.rb
135
133
  - spec/spec_helper.rb
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ruby
2
- puts "exclude-me should not have run"