Rollup merge of #125022 - GuillaumeGomez:migrate-rustdoc-scrape-examples-ordering, r=jieyouxu

Migrate rustdoc scrape examples ordering

Part of https://github.com/rust-lang/rust/issues/121876.

This one adds a lot of utility methods/functions. To prevent having too much changes at once, I didn't make the existing rmake tests use these yet but I'll send a follow-up so they all use it.

r? `@jieyouxu`
This commit is contained in:
Guillaume Gomez 2024-05-12 13:41:57 +02:00 committed by GitHub
commit 1393a87e4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 102 additions and 7 deletions

View file

@ -54,6 +54,15 @@ pub fn static_lib(name: &str) -> PathBuf {
tmp_dir().join(static_lib_name(name))
}
pub fn python_command() -> Command {
let python_path = std::env::var("PYTHON").expect("PYTHON environment variable does not exist");
Command::new(python_path)
}
pub fn source_path() -> PathBuf {
std::env::var("S").expect("S variable does not exist").into()
}
/// Construct the static library name based on the platform.
pub fn static_lib_name(name: &str) -> String {
// See tools.mk (irrelevant lines omitted):

View file

@ -1,5 +1,5 @@
use std::env;
use std::ffi::OsString;
use std::ffi::{OsStr, OsString};
use std::io::Write;
use std::path::Path;
use std::process::{Command, Output, Stdio};
@ -176,6 +176,13 @@ impl Rustc {
self
}
/// Specify the crate name.
pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
self.cmd.arg("--crate-name");
self.cmd.arg(name.as_ref());
self
}
/// Get the [`Output`][::std::process::Output] of the finished process.
#[track_caller]
pub fn command_output(&mut self) -> ::std::process::Output {

View file

@ -1,4 +1,5 @@
use std::env;
use std::ffi::OsStr;
use std::io::Write;
use std::path::Path;
use std::process::{Command, Output, Stdio};
@ -45,6 +46,21 @@ impl Rustdoc {
Self { cmd, stdin: None }
}
/// Specify where an external library is located.
pub fn extern_<P: AsRef<Path>>(&mut self, crate_name: &str, path: P) -> &mut Self {
assert!(
!crate_name.contains(|c: char| c.is_whitespace() || c == '\\' || c == '/'),
"crate name cannot contain whitespace or path separators"
);
let path = path.as_ref().to_string_lossy();
self.cmd.arg("--extern");
self.cmd.arg(format!("{crate_name}={path}"));
self
}
/// Specify path to the input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
@ -107,6 +123,20 @@ impl Rustdoc {
self
}
/// Specify the crate type.
pub fn crate_type(&mut self, crate_type: &str) -> &mut Self {
self.cmd.arg("--crate-type");
self.cmd.arg(crate_type);
self
}
/// Specify the crate name.
pub fn crate_name<S: AsRef<OsStr>>(&mut self, name: S) -> &mut Self {
self.cmd.arg("--crate-name");
self.cmd.arg(name.as_ref());
self
}
#[track_caller]
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
let caller_location = std::panic::Location::caller();

View file

@ -248,7 +248,6 @@ run-make/rustdoc-io-error/Makefile
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
run-make/rustdoc-scrape-examples-macros/Makefile
run-make/rustdoc-scrape-examples-multiple/Makefile
run-make/rustdoc-scrape-examples-ordering/Makefile
run-make/rustdoc-scrape-examples-remap/Makefile
run-make/rustdoc-scrape-examples-test/Makefile
run-make/rustdoc-scrape-examples-whitespace/Makefile