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

Leading spaces before shebang break custom cargo runner #11254

Open
andre-richter opened this issue Oct 18, 2022 · 8 comments
Open

Leading spaces before shebang break custom cargo runner #11254

andre-richter opened this issue Oct 18, 2022 · 8 comments
Labels
C-bug Category: bug P-low Priority: Low S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

Comments

@andre-richter
Copy link
Member

Problem

Newer versions of cargo fail to execute a test runner shell script which has leading spaces before the shebang.

Earlier versions of cargo were immune to this.

Steps

.cargo/config.toml:

[target.x86_64-unknown-linux-gnu]
runner = "./indented_bash_script.sh"

indented_bash_script.sh:

    #!/bin/bash

echo "I don't work
$ cargo test
error: test failed, to rerun pass '--lib'

Caused by:
  could not execute process `/tmp/foo/./indented_bash_script.sh /tmp/foo/target/debug/deps/foo-918a0726eb7b9123` (never executed)

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.64.0 (387270bc7 2022-09-16)
@andre-richter andre-richter added the C-bug Category: bug label Oct 18, 2022
@weihanglo
Copy link
Member

I did reproduce it with the script you provided, but it is broken in every version of Cargo (on my macbook with either bash v3 or v5).

Would it be that the script itself is broken? I spotted that the last line echo is missing a ".

indented_bash_script.sh:

    #!/bin/bash

echo "I don't work

Though I got a slightly different error message.

/projects/issue11254/broken.sh: line 3: unexpected EOF while looking for matching `"'
/projects/issue11254/broken.sh: line 4: syntax error: unexpected end of file
error: test failed, to rerun pass '--bin xxx'

Is it possible to provide a minimal reproducible example? Also helps if we could have the full version info of cargo, how rust toolchain is installed, environment info (distro?), and bash version info. Thank you.

@weihanglo weihanglo added S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. labels Oct 18, 2022
@weihanglo
Copy link
Member

I am not sure why, but current beta and nightly channels are providing more error contexts, for example.

error: test failed, to rerun pass `--bin issue11254`

Caused by:
  could not execute process `/projects/issue11254/./roken.sh /projects/issue11254/target/debug/deps/issue11254-42ad338b1363e653` (never
 executed)

Caused by:
  No such file or directory (os error 2)

Could you also try it out on beta/nightly channel?

@weihanglo weihanglo added the S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. label Oct 18, 2022
@epage
Copy link
Contributor

epage commented Oct 18, 2022

Newer versions of cargo fail to execute a test runner shell script which has leading spaces before the shebang.

Under what situations are spaces legal? I've not personally dealt with this corner case but in looking around, wikipedia lists #! as the file's magic number which implies it has to be the first bytes.

I did reproduce it with the script you provided, but it is broken in every version of Cargo (on my macbook with either bash v3 or v5).

@andre-richter has anything else about the system changed? I wonder if something else broke this and the symptom is just visible through cargo since weihanglo couldn't reproduce it.

@andre-richter
Copy link
Member Author

Sorry, it was a copy paste error that the closing " was missing in my original post.

With

#!/bin/bash

echo "I don't work"

I get

    Finished test [unoptimized + debuginfo] target(s) in 0.00s
     Running unittests src/lib.rs (target/debug/deps/foo-918a0726eb7b9123)
I don't work
   Doc-tests foo

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

With (four leading spaces)

    #!/bin/bash

echo "I don't work"

I get

    Finished test [unoptimized + debuginfo] target(s) in 0.00s
     Running unittests src/lib.rs (target/debug/deps/foo-918a0726eb7b9123)
error: test failed, to rerun pass '--lib'

Caused by:
  could not execute process `/tmp/foo/./indented_bash_script.sh /tmp/foo/target/debug/deps/foo-918a0726eb7b9123` (never executed)

I haven't found a resource yet whether leading spaces are legal. If the script with leading spaces is provided to bash or zsh, both don't care and execute it, so I thought it should be fine.
I know its an odd example. It results from the bash script being auto generated and the auto generation was introducing the spaces.

cargo from nightly version 2022-08-01 for example works in both cases, so I thought this was a regression.

@epage
Copy link
Contributor

epage commented Oct 18, 2022

What if you try something with syntax that is incompatible with your runner (bash, zsh), like:

    #!/usr/bin/env python3

import pathlib

print("Running in {}".format(pathlib.Path.cwd()))
```

for me
```console
$ ./shebang.py  # without spaces
Running in /home/epage/src/personal/dump

$ ./shebang.py  # with spaces (it "hung", hence ^C)
^C./shebang.py: line 5: syntax error near unexpected token `"Running in {}".format'
./shebang.py: line 5: `print("Running in {}".format(pathlib.Path.cwd()))'
```

@andre-richter
Copy link
Member Author

Attached is a minimal reproducer. In rust-toolchain.toml, change to 2022-08-01 to make it work (again). Tested on Ubuntu 22.04.

foo.zip

@ehuss
Copy link
Contributor

ehuss commented Oct 22, 2022

I think this is a duplicate of rust-lang/rust#101511, and based on that discussion it looks like it is "wontfix". This is due to a change in glibc.

@weihanglo
Copy link
Member

Labelled this as such to be aligned with rust-lang/rust#101511.

@rustbot label +P-low +S-blocked-external -S-needs-info

@rustbot rustbot added P-low Priority: Low S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix and removed S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. labels Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug P-low Priority: Low S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix
Projects
None yet
Development

No branches or pull requests

5 participants