nix-community / bundix

Generates a Nix expression for your Bundler-managed application. [maintainer=@manveru]
160 stars 54 forks source link

Using paths for options causes error #90

Open csmithATsquiz opened 2 years ago

csmithATsquiz commented 2 years ago

If I try to use paths for any of the options I'm supposed to be able to, I get the following error:

% ./bin/bundix -i --lockfile=./Gemfile.lock
won't override existing shell.nix but here is what it'd look like:
Traceback (most recent call last):
    10: from ./bin/bundix:5:in `<main>'
     9: from ./bundix/lib/bundix/commandline.rb:22:in `run'
     8: from ./bundix/lib/bundix/commandline.rb:35:in `run'
     7: from ./bundix/lib/bundix/commandline.rb:127:in `handle_init'
     6: from ./bundix/lib/bundix/commandline.rb:120:in `shell_nix_string'
     5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `result'
     4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `eval'
     3: from (erb):7:in `bind'
     2: from ./bundix/lib/bundix/shell_nix_context.rb:20:in `lockfile_path'
     1: from ./bundix/lib/bundix/shell_nix_context.rb:12:in `path_for'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/pathname.rb:522:in `relative_path_from': different prefix: "/" and "." (ArgumentError)

% ./bin/bundix -i --gemfile=./Gemfile
won't override existing shell.nix but here is what it'd look like:
Traceback (most recent call last):
    10: from ./bin/bundix:5:in `<main>'
     9: from ./bundix/lib/bundix/commandline.rb:22:in `run'
     8: from ./bundix/lib/bundix/commandline.rb:35:in `run'
     7: from ./bundix/lib/bundix/commandline.rb:127:in `handle_init'
     6: from ./bundix/lib/bundix/commandline.rb:120:in `shell_nix_string'
     5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `result'
     4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `eval'
     3: from (erb):6:in `bind'
     2: from ./bundix/lib/bundix/shell_nix_context.rb:16:in `gemfile_path'
     1: from ./bundix/lib/bundix/shell_nix_context.rb:12:in `path_for'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/pathname.rb:522:in `relative_path_from': different prefix: "/" and "." (ArgumentError)

% ./bin/bundix -i --gemset=blah.nix
won't override existing shell.nix but here is what it'd look like:
Traceback (most recent call last):
    10: from ./bin/bundix:5:in `<main>'
     9: from ./bundix/lib/bundix/commandline.rb:22:in `run'
     8: from ./bundix/lib/bundix/commandline.rb:35:in `run'
     7: from ./bundix/lib/bundix/commandline.rb:127:in `handle_init'
     6: from ./bundix/lib/bundix/commandline.rb:120:in `shell_nix_string'
     5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `result'
     4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `eval'
     3: from (erb):8:in `bind'
     2: from ./bundix/lib/bundix/shell_nix_context.rb:24:in `gemset_path'
     1: from ./bundix/lib/bundix/shell_nix_context.rb:12:in `path_for'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/pathname.rb:522:in `relative_path_from': different prefix: "/" and "." (ArgumentError)

I can emulate it if I change the command line test:

% git diff test/commandline.rb
diff --git a/test/commandline.rb b/test/commandline.rb
index 1c411e9..5f9a582 100644
--- a/test/commandline.rb
+++ b/test/commandline.rb
@@ -7,9 +7,9 @@ class CommandLineTest < Minitest::Test
     @cli.options = {
       project: "test-project",
       ruby: "test-ruby",
-      gemfile: "test-gemfile",
-      lockfile: "test-lockfile",
-      gemset: "test-gemset",
+      gemfile: Dir.pwd + File::PATH_SEPARATOR + "test-gemfile",
+      lockfile: Dir.pwd + File::PATH_SEPARATOR + "test-lockfile",
+      gemset: Dir.pwd + File::PATH_SEPARATOR + "test-gemset",
     }
   end

% rake
Run options: --seed 11948

# Running:

....E.....

Finished in 0.181851s, 54.9901 runs/s, 153.9722 assertions/s.

  1) Error:
CommandLineTest#test_shell_nix:
ArgumentError: different prefix: "/" and "."
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/pathname.rb:522:in `relative_path_from'
    ./bundix/lib/bundix/shell_nix_context.rb:12:in `path_for'
    ./bundix/lib/bundix/shell_nix_context.rb:16:in `gemfile_path'
    (erb):6:in `bind'
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `eval'
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `result'
    ./bundix/lib/bundix/commandline.rb:120:in `shell_nix_string'
    ./bundix/test/commandline.rb:17:in `test_shell_nix'

10 runs, 28 assertions, 0 failures, 1 errors, 0 skips
rake aborted!
Command failed with status (1)
/Library/Ruby/Gems/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => default => test
(See full trace by running task with --trace)

I'm happy to write up a patch, I'm not sure how you want it though.

Should lib/bundix/commandline.rb turn the full paths (File.expand_path(value)) back in to relative paths ?

573 commented 9 months ago

+1