Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds batchfile generation (not integrated with binstub generation yet)

  • Loading branch information...
commit 9122afb88292ea54729c3c27f6a876a5fad34974 1 parent 53a103b
@danielsdeleo danielsdeleo authored
Showing with 48 additions and 1 deletion.
  1. +23 −1 lib/appbundler/app.rb
  2. +25 −0 spec/appbundler/app_spec.rb
View
24 lib/appbundler/app.rb
@@ -45,8 +45,30 @@ def gemfile_lock
File.join(app_root, "Gemfile.lock")
end
+ def ruby
+ Gem.ruby
+ end
+
+ def batchfile_stub
+ ruby_relpath_windows = ruby_relative_path.gsub('/', '\\')
+ <<-E
+@ECHO OFF
+"%~dp0\\#{ruby_relpath_windows}" "%~dpn0" %*
+E
+ end
+
+ # Relative path from #target_bin_dir to #ruby. This is used to
+ # generate batch files for windows in a way that the package can be
+ # installed in a custom location. On Unix we don't support custom
+ # install locations so this isn't needed.
+ def ruby_relative_path
+ ruby_pathname = Pathname.new(ruby)
+ bindir_pathname = Pathname.new(target_bin_dir)
+ ruby_pathname.relative_path_from(bindir_pathname).to_s
+ end
+
def shebang
- "#!#{Gem.ruby}\n"
+ "#!#{ruby}\n"
end
# A specially formatted comment that documents the format version of the
View
25 spec/appbundler/app_spec.rb
@@ -61,6 +61,10 @@ def shellout!(cmd)
app.stub(:gemfile_lock_specs).and_return(all_specs)
end
+ it "finds the running ruby interpreter" do
+ expect(app.ruby).to eq(Gem.ruby)
+ end
+
it "finds all runtime dependencies of the app" do
# we want to find the minimum set of gems that we need to activate to run
# the application. To do this, we look at the app's runtime deps and
@@ -98,6 +102,27 @@ def shellout!(cmd)
expect(app.runtime_activate).to include(expected)
end
+ context "on windows" do
+
+ let(:target_bindir) { "C:/opscode/chef/bin" }
+
+ before do
+ app.stub(:ruby).and_return("C:/opscode/chef/embedded/bin/ruby.exe")
+ end
+
+ it "computes the relative path to ruby" do
+ expect(app.ruby_relative_path).to eq("../embedded/bin/ruby.exe")
+ end
+
+ it "generates a batchfile stub" do
+ expected_batch_code=<<-E
+@ECHO OFF
+"%~dp0\\..\\embedded\\bin\\ruby.exe" "%~dpn0" %*
+E
+ expect(app.batchfile_stub).to eq(expected_batch_code)
+ end
+ end
+
end
context "when created with the example application" do
Please sign in to comment.
Something went wrong with that request. Please try again.