@@ -18,9 +18,10 @@ extern crate build_helper;
18
18
use std:: collections:: HashSet ;
19
19
use std:: env;
20
20
use std:: fmt;
21
- use std:: fs;
21
+ use std:: fs:: { self , File } ;
22
22
use std:: path:: { PathBuf , Path } ;
23
23
use std:: process:: Command ;
24
+ use std:: io:: Read ;
24
25
25
26
use build_helper:: output;
26
27
@@ -328,24 +329,15 @@ pub fn docs(build: &Build, compiler: &Compiler) {
328
329
329
330
while let Some ( p) = stack. pop ( ) {
330
331
if p. is_dir ( ) {
331
- stack. extend ( t ! ( p. read_dir( ) ) . map ( |p| t ! ( p) . path ( ) ) ) ;
332
+ stack. extend ( t ! ( p. read_dir( ) ) . map ( |p| t ! ( p) . path ( ) ) . filter ( |p| {
333
+ p. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "md" ) &&
334
+ // The nostarch directory in the book is for no starch, and so isn't guaranteed to
335
+ // build. We don't care if it doesn't build, so skip it.
336
+ p. to_str ( ) . map_or ( true , |p| !p. contains ( "nostarch" ) )
337
+ } ) ) ;
332
338
continue
333
339
}
334
340
335
- if p. extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "md" ) {
336
- continue
337
- }
338
-
339
- // The nostarch directory in the book is for no starch, and so isn't guaranteed to build.
340
- // we don't care if it doesn't build, so skip it.
341
- use std:: ffi:: OsStr ;
342
- let path: & OsStr = p. as_ref ( ) ;
343
- if let Some ( path) = path. to_str ( ) {
344
- if path. contains ( "nostarch" ) {
345
- continue ;
346
- }
347
- }
348
-
349
341
println ! ( "doc tests for: {}" , p. display( ) ) ;
350
342
markdown_test ( build, compiler, & p) ;
351
343
}
@@ -376,6 +368,13 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
376
368
}
377
369
378
370
fn markdown_test ( build : & Build , compiler : & Compiler , markdown : & Path ) {
371
+ let mut file = t ! ( File :: open( markdown) ) ;
372
+ let mut contents = String :: new ( ) ;
373
+ t ! ( file. read_to_string( & mut contents) ) ;
374
+ if !contents. contains ( "```" ) {
375
+ return ;
376
+ }
377
+
379
378
let mut cmd = Command :: new ( build. rustdoc ( compiler) ) ;
380
379
build. add_rustc_lib_path ( compiler, & mut cmd) ;
381
380
build. add_rust_test_threads ( & mut cmd) ;
0 commit comments