Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix-shell: Fixes use with ruby shebangs. #2056

Merged
merged 3 commits into from Apr 9, 2018

Conversation

samueldr
Copy link
Member

@samueldr samueldr commented Apr 8, 2018

The ported code in 80ebc55 was incorrectly ported.

-            $envCommand = "exec $execArgs $interpreter -e 'load(\"$script\")' -- ${\(join ' ', (map shellEscape, @savedArgs))}";
...
+                    envCommand = (format("exec %1% %2% -e 'load(\"%3%\") -- %4%") % execArgs % interpreter % script % joined.str()).str();

The single-quote finishing the small ruby snippet was lost in
translation.


Symptoms:

/tmp/nix-shell-1953-0/rc: line 1: unexpected EOF while looking for matching `''
/tmp/nix-shell-1953-0/rc: line 2: syntax error: unexpected end of file

In addition, I will be looking at how tests work, but I would really like to add a test for this regression. Any help is welcome.

The ported code in 80ebc55 was incorrectly ported.

```
-            $envCommand = "exec $execArgs $interpreter -e 'load(\"$script\")' -- ${\(join ' ', (map shellEscape, @savedArgs))}";
...
+                    envCommand = (format("exec %1% %2% -e 'load(\"%3%\") -- %4%") % execArgs % interpreter % script % joined.str()).str();
```

The single-quote finishing the small ruby snippet was lost in
translation.
The test fakes the interpreter only to verify the arguments it would be
given.
@samueldr
Copy link
Member Author

samueldr commented Apr 8, 2018

I have added a (partially dubious) good enough test.

The test only verifies the command line that would be passed to the ruby interpreter and does not actually test with a ruby interpreter.

For the purpose of this PR, the test is sufficient. Executing the test after reverting the fix commit gives me these errors:

    /run/user/1000/nix-shell-30420-0/rc: line 1: unexpected EOF while looking for matching `''
    /run/user/1000/nix-shell-30420-0/rc: line 2: syntax error: unexpected end of file

This matches with what was observable without tests.

A similar test could be added for the perl shebang handling if pertinent.

I would like feedback about what I did wrong with the test :).

Copy link
Member

@shlevy shlevy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one small nit. Good catch!

# Test nix-shell shebang mode for ruby
# This uses a fake interpreter that returns the arguments passed
# This, in turn, verifies the `rc` script is valid and the `load()` script (given using `-e`) is as expected.
sed -e "s|@ENV_PROG@|$(type -p env)|" shell.shebang.rb > $TEST_ROOT/shell.shebang.rb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just hard-code the path to nix-shell instead?

@shlevy shlevy self-assigned this Apr 9, 2018
@samueldr
Copy link
Member Author

samueldr commented Apr 9, 2018

It has been amended so it uses the path to nix-shell.

While I did make the change, I would like to know why shoult it use the path to nix-shell instead of the equivalent of /usr/bin/env for that test, while the previous test uses the equivalent to /usr/bin/env?

@shlevy
Copy link
Member

shlevy commented Apr 9, 2018

Mostly just to remove the unnecessary indirection and need to resolve env.. I didn't realize we already had a test doing this, sorry!

@shlevy shlevy merged commit a4c9b25 into NixOS:master Apr 9, 2018
@samueldr
Copy link
Member Author

samueldr commented Apr 9, 2018

No problem! Thanks!

@samueldr samueldr deleted the fix/ruby-shebang branch April 9, 2018 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants