Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adds batchfile generation (not integrated with binstub generation yet) #2

Merged
merged 1 commit into from

2 participants

@danielsdeleo

Putting this up here for early feedback:

  • Is the batch file code correct?
  • How do we pass paths into the appbundler CLI at the moment? If we want the CLI to accept paths with backslashes, we'll need to translate them on the way in since ruby only deals with '/' separators internally.
@adamedx adamedx commented on the diff
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('/', '\\')
@adamedx Owner
adamedx added a note

Good defense here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@adamedx
Owner

Looks good -- batch file code is correct. Can you explain more about the issue with passing in "\" in cli? Seems like all inputs here are derived from Ruby methods that will give you "/" before you use other Ruby library calls, so I don't see the "\" issue.

@danielsdeleo
Owner

@adamedx the ruby apps that I've tried don't translate paths that they get as command line arguments. For example, rspec spec/something/my_code_spec.rb works, but rspec spec\something\my_code_spec.rb does not, which can be pretty annoying in powershell. I haven't tried running appbundler on windows yet, but I suspect the same would be true for appbundler's CLI.

@danielsdeleo danielsdeleo merged commit 9122afb into from
@danielsdeleo danielsdeleo deleted the branch
@danielsdeleo
Owner

I've decided to merge this now even though it's not 100% complete. We still have some work to do to get ChefDK building on windows, so we can't verify that this works correctly until that's done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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('/', '\\')
@adamedx Owner
adamedx added a note

Good defense here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ <<-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
Something went wrong with that request. Please try again.