@@ -150,6 +150,8 @@ fn find_test_blocks(docs: &str) -> Vec<String> {
150
150
/// Any crate attributes are preserved at the top level.
151
151
fn preprocess ( test : & str , crate_name : & str ) -> String {
152
152
if let Ok ( mut ast) = syn:: parse_crate ( test) {
153
+
154
+ // TODO if the extern crate has `#[macro_use]` we need to strip it out
153
155
let has_extern_crate = ast. items . iter ( ) . any ( |item| match item. node {
154
156
ItemKind :: ExternCrate ( ..) => true ,
155
157
_ => false ,
@@ -241,7 +243,7 @@ fn preprocess(test: &str, crate_name: &str) -> String {
241
243
}
242
244
}
243
245
244
- pub fn save_tests ( config : & Config , tests : & Vec < ( & String , Vec < String > ) > , save_path : & Path ) -> Result < ( ) > {
246
+ pub fn save_tests ( tests : & Vec < ( & String , Vec < String > ) > , save_path : & Path , crate_name : & str ) -> Result < ( ) > {
245
247
DirBuilder :: new ( ) . recursive ( true ) . create ( save_path) ?;
246
248
247
249
let mut mods = vec ! [ ] ;
@@ -267,14 +269,7 @@ pub fn save_tests(config: &Config, tests: &Vec<(&String, Vec<String>)>, save_pat
267
269
// TODO use syn here as well?
268
270
let mut main = String :: new ( ) ;
269
271
270
- //let externs = find_externs_for_crate(config)?;
271
- //for e in externs {
272
- // let name = e.name.replace("\"", "");
273
- // let name = name.replace("-", "_");
274
- // main.push_str(&format!("extern crate {};\n", name));
275
- //}
276
-
277
- main. push_str ( "#[macro_use] extern crate hyper;" ) ;
272
+ main. push_str ( & format ! ( "extern crate {};" , crate_name) ) ;
278
273
for m in mods {
279
274
main. push_str ( & format ! ( "mod {};\n " , m) ) ;
280
275
}
@@ -288,50 +283,13 @@ pub fn save_tests(config: &Config, tests: &Vec<(&String, Vec<String>)>, save_pat
288
283
pub fn compile_tests ( config : & Config , save_path : & Path ) -> Result < PathBuf > {
289
284
static TEST_NAME : & str = "rustdoc-test" ;
290
285
291
- // First, determine the location of the dependency artifacts so we can pass them to rustc.
292
- let output = Command :: new ( "cargo" )
293
- . arg ( "build" )
294
- . arg ( "--manifest-path" )
295
- . arg ( & config. manifest_path )
296
- . args ( & [ "--message-format" , "json" ] )
297
- . output ( ) ?;
298
- if !output. status . success ( ) {
299
- return Err ( format_err ! (
300
- "cargo did not exit successfully: {}" ,
301
- output. status
302
- ) ) ;
303
- }
304
-
305
- let output = String :: from_utf8 ( output. stdout ) . expect ( "cargo did not output valid utf-8" ) ;
286
+ let crate_externs = find_externs_for_crate ( config) ?;
306
287
307
288
let mut externs = vec ! [ ] ;
308
-
309
- for message in output. lines ( ) {
310
- let message = serde_json:: from_str :: < Value > ( message) ?;
311
- let is_compiler_artifact = message
312
- . as_object ( )
313
- . unwrap ( )
314
- . get ( "reason" )
315
- . and_then ( Value :: as_str)
316
- . map ( |reason| reason == "compiler-artifact" )
317
- . unwrap_or_default ( ) ;
318
-
319
- if is_compiler_artifact {
320
- let name = message
321
- . pointer ( "/target/name" )
322
- . and_then ( Value :: as_str)
323
- . unwrap ( ) ;
324
- let name = name. replace ( "-" , "_" ) ;
325
- let rlib = message
326
- . pointer ( "/filenames/0" )
327
- . and_then ( Value :: as_str)
328
- . unwrap ( ) ;
329
-
330
- externs. push ( format ! ( "{}={}" , name, rlib) ) ;
331
- }
289
+ for c in crate_externs. iter ( ) {
290
+ externs. push ( format ! ( "{}={}" , & c. name, & c. location. to_string_lossy( ) ) ) ;
332
291
}
333
292
334
- let crate_externs = find_externs_for_crate ( config) ?;
335
293
let search_path = crate_externs. first ( ) . map ( |e| {
336
294
e. location . parent ( ) . unwrap ( ) . to_path_buf ( )
337
295
} ) . unwrap ( ) ;
0 commit comments