Skip to content

rustdoc should not assume current_exe() is infallible #61377

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

Closed
rotty opened this issue May 30, 2019 · 1 comment · Fixed by #61459
Closed

rustdoc should not assume current_exe() is infallible #61377

rotty opened this issue May 30, 2019 · 1 comment · Fixed by #61459
Assignees
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@rotty
Copy link

rotty commented May 30, 2019

On OpenBSD, the std::env::current_exe() function fails if the binary is not invoked with a full path (see this comment). This leads to the following crash when running doc tests:

% cargo test
[...]
   Doc-tests zmq
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: StringError("no current exe available (short)") }', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

Note that this using rustc/cargo 1.33.0, installed on OpenBSD 6.5 using its native package (pkg_add rust).

The offending code, I believe, must be one of the current_exe() calls in src/librustdoc/test.rs, which are both unwrapped, and have to do with figuring out the sysroot, if not already known.

The issue can be worked around by adjusting the command line like this:

% RUSTDOCFLAGS='--sysroot /usr/local' cargo test

I guess solving this completely may be tricky, but I think the code should definitely not panic, and ideally cargo/rustdoc would issue an error message pointing (OpenBSD) users to the workaround.

@jonas-schievink jonas-schievink added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 30, 2019
@GuillaumeGomez GuillaumeGomez self-assigned this Jun 2, 2019
@rotty
Copy link
Author

rotty commented Jun 2, 2019

It seems that simply using the code of get_or_default_sysroot() from librustc::session::filesearch would be an improvement over using current_exe() directly; the latter is patched on OpenBSD to consider the LOCALBASE environment variable; see the patch in the port collection.

bors added a commit that referenced this issue Jun 30, 2019
…lie27,bjorn3,QuietMisdreavus

Prevent panic when sysroot cannot be computed

Fixes #61377.

cc @rotty @rust-lang/rustdoc

r? @Manishearth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants