@@ -120,7 +120,8 @@ pub fn run(mut options: Options) -> isize {
120
120
Some ( source_map) ,
121
121
None ,
122
122
options. linker ,
123
- options. edition
123
+ options. edition ,
124
+ options. persist_doctests ,
124
125
) ;
125
126
126
127
{
@@ -184,7 +185,8 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
184
185
cg : CodegenOptions , externs : Externs ,
185
186
should_panic : bool , no_run : bool , as_test_harness : bool ,
186
187
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 > ) {
188
190
// The test harness wants its own `main` and top-level functions, so
189
191
// never wrap the test in `fn main() { ... }`.
190
192
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,
249
251
let old = io:: set_panic ( Some ( box Sink ( data. clone ( ) ) ) ) ;
250
252
let _bomb = Bomb ( data. clone ( ) , old. unwrap_or ( box io:: stdout ( ) ) ) ;
251
253
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
+
252
268
let ( libdir, outdir, compile_result) = driver:: spawn_thread_pool ( sessopts, |sessopts| {
253
269
let source_map = Lrc :: new ( SourceMap :: new ( sessopts. file_path_mapping ( ) ) ) ;
254
270
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,
267
283
rustc_lint:: register_builtins ( & mut sess. lint_store . borrow_mut ( ) , Some ( & sess) ) ;
268
284
269
285
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
+ }
271
306
) ;
272
307
let libdir = sess. target_filesearch ( PathKind :: All ) . get_lib_path ( ) ;
273
308
let mut control = driver:: CompileController :: basic ( ) ;
@@ -629,13 +664,15 @@ pub struct Collector {
629
664
filename : Option < PathBuf > ,
630
665
linker : Option < PathBuf > ,
631
666
edition : Edition ,
667
+ persist_doctests : Option < PathBuf > ,
632
668
}
633
669
634
670
impl Collector {
635
671
pub fn new ( cratename : String , cfgs : Vec < String > , libs : Vec < SearchPath > , cg : CodegenOptions ,
636
672
externs : Externs , use_headers : bool , opts : TestOptions ,
637
673
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 {
639
676
Collector {
640
677
tests : Vec :: new ( ) ,
641
678
names : Vec :: new ( ) ,
@@ -652,6 +689,7 @@ impl Collector {
652
689
filename,
653
690
linker,
654
691
edition,
692
+ persist_doctests,
655
693
}
656
694
}
657
695
@@ -695,6 +733,8 @@ impl Tester for Collector {
695
733
let maybe_sysroot = self . maybe_sysroot . clone ( ) ;
696
734
let linker = self . linker . clone ( ) ;
697
735
let edition = config. edition . unwrap_or ( self . edition ) ;
736
+ let persist_doctests = self . persist_doctests . clone ( ) ;
737
+
698
738
debug ! ( "Creating test {}: {}" , name, test) ;
699
739
self . tests . push ( testing:: TestDescAndFn {
700
740
desc : testing:: TestDesc {
@@ -727,7 +767,8 @@ impl Tester for Collector {
727
767
& opts,
728
768
maybe_sysroot,
729
769
linker,
730
- edition)
770
+ edition,
771
+ persist_doctests)
731
772
} ) )
732
773
} {
733
774
Ok ( ( ) ) => ( ) ,
0 commit comments