@@ -120,7 +120,8 @@ pub fn run(mut options: Options) -> isize {
120120 Some ( source_map) ,
121121 None ,
122122 options. linker ,
123- options. edition
123+ options. edition ,
124+ options. persist_doctests ,
124125 ) ;
125126
126127 {
@@ -184,7 +185,8 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
184185 cg : CodegenOptions , externs : Externs ,
185186 should_panic : bool , no_run : bool , as_test_harness : bool ,
186187 compile_fail : bool , mut error_codes : Vec < String > , opts : & TestOptions ,
187- maybe_sysroot : Option < PathBuf > , linker : Option < PathBuf > , edition : Edition ) {
188+ maybe_sysroot : Option < PathBuf > , linker : Option < PathBuf > , edition : Edition ,
189+ persist_doctests : Option < PathBuf > ) {
188190 // The test harness wants its own `main` and top-level functions, so
189191 // never wrap the test in `fn main() { ... }`.
190192 let ( test, line_offset) = make_test ( test, Some ( cratename) , as_test_harness, opts) ;
@@ -249,6 +251,20 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
249251 let old = io:: set_panic ( Some ( box Sink ( data. clone ( ) ) ) ) ;
250252 let _bomb = Bomb ( data. clone ( ) , old. unwrap_or ( box io:: stdout ( ) ) ) ;
251253
254+ enum DirState {
255+ Temp ( tempfile:: TempDir ) ,
256+ Perm ( PathBuf ) ,
257+ }
258+
259+ impl DirState {
260+ fn path ( & self ) -> & std:: path:: Path {
261+ match self {
262+ DirState :: Temp ( t) => t. path ( ) ,
263+ DirState :: Perm ( p) => p. as_path ( ) ,
264+ }
265+ }
266+ }
267+
252268 let ( libdir, outdir, compile_result) = driver:: spawn_thread_pool ( sessopts, |sessopts| {
253269 let source_map = Lrc :: new ( SourceMap :: new ( sessopts. file_path_mapping ( ) ) ) ;
254270 let emitter = errors:: emitter:: EmitterWriter :: new ( box Sink ( data. clone ( ) ) ,
@@ -267,7 +283,26 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
267283 rustc_lint:: register_builtins ( & mut sess. lint_store . borrow_mut ( ) , Some ( & sess) ) ;
268284
269285 let outdir = Mutex :: new (
270- TempFileBuilder :: new ( ) . prefix ( "rustdoctest" ) . tempdir ( ) . expect ( "rustdoc needs a tempdir" )
286+ if let Some ( mut path) = persist_doctests {
287+ path. push ( format ! ( "{}_{}" ,
288+ filename
289+ . to_string( )
290+ . rsplit( '/' )
291+ . next( )
292+ . unwrap( )
293+ . replace( "." , "_" ) ,
294+ line)
295+ ) ;
296+ std:: fs:: create_dir_all ( & path)
297+ . expect ( "Couldn't create directory for doctest executables" ) ;
298+
299+ DirState :: Perm ( path)
300+ } else {
301+ DirState :: Temp ( TempFileBuilder :: new ( )
302+ . prefix ( "rustdoctest" )
303+ . tempdir ( )
304+ . expect ( "rustdoc needs a tempdir" ) )
305+ }
271306 ) ;
272307 let libdir = sess. target_filesearch ( PathKind :: All ) . get_lib_path ( ) ;
273308 let mut control = driver:: CompileController :: basic ( ) ;
@@ -629,13 +664,15 @@ pub struct Collector {
629664 filename : Option < PathBuf > ,
630665 linker : Option < PathBuf > ,
631666 edition : Edition ,
667+ persist_doctests : Option < PathBuf > ,
632668}
633669
634670impl Collector {
635671 pub fn new ( cratename : String , cfgs : Vec < String > , libs : Vec < SearchPath > , cg : CodegenOptions ,
636672 externs : Externs , use_headers : bool , opts : TestOptions ,
637673 maybe_sysroot : Option < PathBuf > , source_map : Option < Lrc < SourceMap > > ,
638- filename : Option < PathBuf > , linker : Option < PathBuf > , edition : Edition ) -> Collector {
674+ filename : Option < PathBuf > , linker : Option < PathBuf > , edition : Edition ,
675+ persist_doctests : Option < PathBuf > ) -> Collector {
639676 Collector {
640677 tests : Vec :: new ( ) ,
641678 names : Vec :: new ( ) ,
@@ -652,6 +689,7 @@ impl Collector {
652689 filename,
653690 linker,
654691 edition,
692+ persist_doctests,
655693 }
656694 }
657695
@@ -695,6 +733,8 @@ impl Tester for Collector {
695733 let maybe_sysroot = self . maybe_sysroot . clone ( ) ;
696734 let linker = self . linker . clone ( ) ;
697735 let edition = config. edition . unwrap_or ( self . edition ) ;
736+ let persist_doctests = self . persist_doctests . clone ( ) ;
737+
698738 debug ! ( "Creating test {}: {}" , name, test) ;
699739 self . tests . push ( testing:: TestDescAndFn {
700740 desc : testing:: TestDesc {
@@ -727,7 +767,8 @@ impl Tester for Collector {
727767 & opts,
728768 maybe_sysroot,
729769 linker,
730- edition)
770+ edition,
771+ persist_doctests)
731772 } ) )
732773 } {
733774 Ok ( ( ) ) => ( ) ,
0 commit comments