@@ -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,17 @@ 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 ! ( "{}_{}" , filename. to_string( ) . rsplit( '/' ) . next( ) . unwrap( ) . replace( "." , "_" ) , line) ) ;
288
+ std:: fs:: create_dir_all ( & path) . expect ( "Couldn't create directory for doctest executables" ) ;
289
+
290
+ DirState :: Perm ( path)
291
+ } else {
292
+ DirState :: Temp ( TempFileBuilder :: new ( )
293
+ . prefix ( "rustdoctest" )
294
+ . tempdir ( )
295
+ . expect ( "rustdoc needs a tempdir" ) )
296
+ }
271
297
) ;
272
298
let libdir = sess. target_filesearch ( PathKind :: All ) . get_lib_path ( ) ;
273
299
let mut control = driver:: CompileController :: basic ( ) ;
@@ -629,13 +655,15 @@ pub struct Collector {
629
655
filename : Option < PathBuf > ,
630
656
linker : Option < PathBuf > ,
631
657
edition : Edition ,
658
+ persist_doctests : Option < PathBuf > ,
632
659
}
633
660
634
661
impl Collector {
635
662
pub fn new ( cratename : String , cfgs : Vec < String > , libs : Vec < SearchPath > , cg : CodegenOptions ,
636
663
externs : Externs , use_headers : bool , opts : TestOptions ,
637
664
maybe_sysroot : Option < PathBuf > , source_map : Option < Lrc < SourceMap > > ,
638
- filename : Option < PathBuf > , linker : Option < PathBuf > , edition : Edition ) -> Collector {
665
+ filename : Option < PathBuf > , linker : Option < PathBuf > , edition : Edition ,
666
+ persist_doctests : Option < PathBuf > ) -> Collector {
639
667
Collector {
640
668
tests : Vec :: new ( ) ,
641
669
names : Vec :: new ( ) ,
@@ -652,6 +680,7 @@ impl Collector {
652
680
filename,
653
681
linker,
654
682
edition,
683
+ persist_doctests,
655
684
}
656
685
}
657
686
@@ -695,6 +724,8 @@ impl Tester for Collector {
695
724
let maybe_sysroot = self . maybe_sysroot . clone ( ) ;
696
725
let linker = self . linker . clone ( ) ;
697
726
let edition = config. edition . unwrap_or ( self . edition ) ;
727
+ let persist_doctests = self . persist_doctests . clone ( ) ;
728
+
698
729
debug ! ( "Creating test {}: {}" , name, test) ;
699
730
self . tests . push ( testing:: TestDescAndFn {
700
731
desc : testing:: TestDesc {
@@ -727,7 +758,8 @@ impl Tester for Collector {
727
758
& opts,
728
759
maybe_sysroot,
729
760
linker,
730
- edition)
761
+ edition,
762
+ persist_doctests)
731
763
} ) )
732
764
} {
733
765
Ok ( ( ) ) => ( ) ,
0 commit comments