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

cargo doc and cargo test --doc execute rustdoc in different directories. #8097

Closed
olson-sean-k opened this issue Apr 12, 2020 · 1 comment · Fixed by #8954
Closed

cargo doc and cargo test --doc execute rustdoc in different directories. #8097

olson-sean-k opened this issue Apr 12, 2020 · 1 comment · Fixed by #8954
Labels
A-doctests Area: rustdoc --test C-bug Category: bug

Comments

@olson-sean-k
Copy link

olson-sean-k commented Apr 12, 2020

Problem

It appears that when using workspaces and executing cargo against a manifest with only workspace members (i.e., at the root of a repository), cargo doc and cargo test --doc execute rustdoc in different directories. This interacts poorly with relative paths used in additional flags for rustdoc (either from environment variables or a Cargo configuration file).

Depending on the relative paths involved (e.g., ./path vs. ../path), this causes one of cargo doc or cargo test --doc to fail with an error stating that the path cannot be found.

This is likely complicated, but at first I expected that relative paths would resolve the same way for both cargo doc and cargo test --doc when executed in the same directory.

Steps

  1. Create a repository with a workspace and a member package in a subdirectory.
  2. Create an HTML file at the root of the repository (its contents do not matter).
  3. Pass a relative path to this file to rustdoc via --html-in-header using an environment variable or Cargo configuration file.
  4. Execute cargo doc and cargo test --doc from the root of the repository (using the workspace manifest).

See this commit in a workspace repository for an example of this problem. The CI for that project fails with similar errors on different operating systems.

Possible Solution(s)

I'm really not sure what is acceptable here. I encountered this when I tried to migrate away from using a simple shell script for generating documentation that uses the RUSTDOCFLAGS environment variable.

Notes

I've encountered this using both stable and nightly toolchains on Windows 10 and Arch Linux.

Output of cargo version: cargo 1.42.0 (86334295e 2020-01-31)
Output of cargo +nightly version: cargo 1.44.0-nightly (7019b3ed3 2020-03-17)

@olson-sean-k olson-sean-k added the C-bug Category: bug label Apr 12, 2020
@ehuss
Copy link
Contributor

ehuss commented Apr 13, 2020

I suspect it was mostly an oversight that test --doc doesn't adjust the current dir. Normal rustc/rustdoc execution is very careful about using relative paths and cwd here, but the corresponding usage for doc tests isn't so careful.

@ehuss ehuss added the A-doctests Area: rustdoc --test label Apr 13, 2020
bors added a commit that referenced this issue Dec 7, 2020
Run rustdoc doctests relative to the workspace

By doing so, rustdoc will also emit workspace-relative filenames for
the doctests.

fixes #8097
@bors bors closed this as completed in 2cc2ae8 Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: rustdoc --test C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants