@@ -139,6 +139,8 @@ pub fn opts() -> Vec<RustcOptGroup> {
139
139
"DIR" ) ) ,
140
140
stable( optmulti( "" , "cfg" , "pass a --cfg to rustc" , "" ) ) ,
141
141
stable( optmulti( "" , "extern" , "pass an --extern to rustc" , "NAME=PATH" ) ) ,
142
+ stable( optmulti( "" , "extern-version" , "pass an --extern-version to rustc" ,
143
+ "NAME=CRATE_NAME,VERSION" ) ) ,
142
144
stable( optmulti( "" , "plugin-path" , "directory to load plugins from" , "DIR" ) ) ,
143
145
stable( optmulti( "" , "passes" ,
144
146
"list of passes to also run, you might want \
@@ -259,6 +261,14 @@ pub fn main_args(args: &[String]) -> isize {
259
261
}
260
262
} ;
261
263
264
+ let extern_versions = match parse_extern_versions ( & matches) {
265
+ Ok ( ex) => ex,
266
+ Err ( err) => {
267
+ print_error ( err) ;
268
+ return 1 ;
269
+ }
270
+ } ;
271
+
262
272
let test_args = matches. opt_strs ( "test-args" ) ;
263
273
let test_args: Vec < String > = test_args. iter ( )
264
274
. flat_map ( |s| s. split_whitespace ( ) )
@@ -326,7 +336,7 @@ pub fn main_args(args: &[String]) -> isize {
326
336
info ! ( "going to format" ) ;
327
337
match output_format. as_ref ( ) . map ( |s| & * * s) {
328
338
Some ( "html" ) | None => {
329
- html:: render:: run ( krate, & external_html, playground_url,
339
+ html:: render:: run ( krate, extern_versions , & external_html, playground_url,
330
340
output. unwrap_or ( PathBuf :: from ( "doc" ) ) ,
331
341
passes. into_iter ( ) . collect ( ) ,
332
342
css_file_extension,
@@ -388,6 +398,23 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
388
398
Ok ( Externs :: new ( externs) )
389
399
}
390
400
401
+ /// Extracts `--extern CRATE=CRATE_NAME,VERSION` arguments from `matches` and
402
+ /// returns a map mapping crate names to their paths or else an
403
+ /// error message.
404
+ fn parse_extern_versions ( matches : & getopts:: Matches ) -> Result < Externs , String > {
405
+ let mut externs = BTreeMap :: new ( ) ;
406
+ for arg in & matches. opt_strs ( "extern-version" ) {
407
+ let mut parts = arg. splitn ( 2 , '=' ) ;
408
+ let name = parts. next ( ) . ok_or ( "--extern-version value must not be empty" . to_string ( ) ) ?;
409
+ let location = parts. next ( )
410
+ . ok_or ( "--extern-version value must be of the format `foo=bar`"
411
+ . to_string ( ) ) ?;
412
+ let name = name. to_string ( ) ;
413
+ externs. entry ( name) . or_insert_with ( BTreeSet :: new) . insert ( location. to_string ( ) ) ;
414
+ }
415
+ Ok ( Externs :: new ( externs) )
416
+ }
417
+
391
418
/// Interprets the input file as a rust source file, passing it through the
392
419
/// compiler all the way through the analysis passes. The rustdoc output is then
393
420
/// generated from the cleaned AST of the crate.
0 commit comments