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

rustdoc --runtool uses ambiguous relative paths with --test-run-directory #112210

Closed
ehuss opened this issue Jun 2, 2023 · 0 comments · Fixed by #112751
Closed

rustdoc --runtool uses ambiguous relative paths with --test-run-directory #112210

ehuss opened this issue Jun 2, 2023 · 0 comments · Fixed by #112751
Assignees
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Jun 2, 2023

The current code for --runtool can interact in platform-specific ways with --test-run-directory because it uses current_dir in combination with potentially relative paths which has platform-specific behavior.

This also causes issues with Cargo, since in some cases it makes the path relative to the package in a workspace instead of the workspace itself. This means that in a workspace, it can be difficult or impossible to use a relative path for the --runtool since it would change for every package.

Reproduction:

  1. mkdir foo
  2. cd foo
  3. mkdir tool
  4. Create a runtool:
    cat <<'EOF' > tool/echo.rs
    fn main() { eprintln!("{:?}", std::env::args().collect::<Vec<_>>()); }
    EOF
    
  5. rustc --out-dir tool tool/echo.rs
  6. mkdir subdir
  7. Create a test file:
    cat <<'EOF' > subdir/example.rs
    /// ```
    /// example::foo();
    /// ```
    pub fn foo() {}
    EOF
    
  8. rustc --crate-type=rlib subdir/example.rs
  9. Verify test works: rustdoc --edition=2021 -L . --test subdir/example.rs
  10. Verify with just runtool: rustdoc --edition=2021 -L . --test subdir/example.rs --runtool=tool/echo -Z unstable-options --nocapture
  11. Try with both runtool and test-run-directory: rustdoc --edition=2021 -L . --test subdir/example.rs --runtool=tool/echo --test-run-directory=subdir -Z unstable-options --nocapture

I expected this to happen: The last step should always work.

Instead, this happened: The last step works on Windows, but fails on Unix-like platforms.

I general, Command::current_dir can be problematic with relative paths. One approach I recommend (and the one Cargo uses) is to check if the executable has a / or \, and if it does, do current_working_directory.join(exe_path) as the argument to Command::new.

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (9d871b061 2023-05-21)
binary: rustc
commit-hash: 9d871b0617a4b3d6610b7cee0ab5310dcb542c62
commit-date: 2023-05-21
host: aarch64-apple-darwin
release: 1.71.0-nightly
LLVM version: 16.0.4

cc #56925
cc #64245

@ehuss ehuss added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-doctests Area: Documentation tests, run by rustdoc labels Jun 2, 2023
@ehuss ehuss self-assigned this Jun 17, 2023
@bors bors closed this as completed in da54108 Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc 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.

1 participant