Put temporary directory into one common function
This commit is contained in:
parent
33735d5913
commit
86fe40021f
@ -20,7 +20,6 @@
|
|||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
|
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
|
||||||
use rustc_target::spec::{Target, TargetTriple};
|
use rustc_target::spec::{Target, TargetTriple};
|
||||||
use tempfile::Builder as TempFileBuilder;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -32,7 +31,7 @@
|
|||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::{Builder as TempFileBuilder, TempDir};
|
||||||
|
|
||||||
use crate::clean::{types::AttributesExt, Attributes};
|
use crate::clean::{types::AttributesExt, Attributes};
|
||||||
use crate::config::Options as RustdocOptions;
|
use crate::config::Options as RustdocOptions;
|
||||||
@ -92,6 +91,10 @@ pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) ->
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_doctest_dir() -> io::Result<TempDir> {
|
||||||
|
TempFileBuilder::new().prefix("rustdoctest").tempdir()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn run(
|
pub(crate) fn run(
|
||||||
dcx: &rustc_errors::DiagCtxt,
|
dcx: &rustc_errors::DiagCtxt,
|
||||||
options: RustdocOptions,
|
options: RustdocOptions,
|
||||||
@ -165,7 +168,7 @@ pub(crate) fn run(
|
|||||||
let externs = options.externs.clone();
|
let externs = options.externs.clone();
|
||||||
let json_unused_externs = options.json_unused_externs;
|
let json_unused_externs = options.json_unused_externs;
|
||||||
|
|
||||||
let temp_dir = match tempdir()
|
let temp_dir = match get_doctest_dir()
|
||||||
.map_err(|error| format!("failed to create temporary directory: {error:?}"))
|
.map_err(|error| format!("failed to create temporary directory: {error:?}"))
|
||||||
{
|
{
|
||||||
Ok(temp_dir) => temp_dir,
|
Ok(temp_dir) => temp_dir,
|
||||||
@ -962,12 +965,7 @@ fn new(options: &RustdocOptions, arg_file: &Path, test_id: String) -> Self {
|
|||||||
|
|
||||||
DirState::Perm(path)
|
DirState::Perm(path)
|
||||||
} else {
|
} else {
|
||||||
DirState::Temp(
|
DirState::Temp(get_doctest_dir().expect("rustdoc needs a tempdir"))
|
||||||
TempFileBuilder::new()
|
|
||||||
.prefix("rustdoctest")
|
|
||||||
.tempdir()
|
|
||||||
.expect("rustdoc needs a tempdir"),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user