@@ -139,6 +139,8 @@ pub fn opts() -> Vec<RustcOptGroup> {
139139 "DIR" ) ) ,
140140 stable( optmulti( "" , "cfg" , "pass a --cfg to rustc" , "" ) ) ,
141141 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" ) ) ,
142144 stable( optmulti( "" , "plugin-path" , "directory to load plugins from" , "DIR" ) ) ,
143145 stable( optmulti( "" , "passes" ,
144146 "list of passes to also run, you might want \
@@ -259,6 +261,14 @@ pub fn main_args(args: &[String]) -> isize {
259261 }
260262 } ;
261263
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+
262272 let test_args = matches. opt_strs ( "test-args" ) ;
263273 let test_args: Vec < String > = test_args. iter ( )
264274 . flat_map ( |s| s. split_whitespace ( ) )
@@ -326,7 +336,7 @@ pub fn main_args(args: &[String]) -> isize {
326336 info ! ( "going to format" ) ;
327337 match output_format. as_ref ( ) . map ( |s| & * * s) {
328338 Some ( "html" ) | None => {
329- html:: render:: run ( krate, & external_html, playground_url,
339+ html:: render:: run ( krate, extern_versions , & external_html, playground_url,
330340 output. unwrap_or ( PathBuf :: from ( "doc" ) ) ,
331341 passes. into_iter ( ) . collect ( ) ,
332342 css_file_extension,
@@ -388,6 +398,23 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
388398 Ok ( Externs :: new ( externs) )
389399}
390400
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+
391418/// Interprets the input file as a rust source file, passing it through the
392419/// compiler all the way through the analysis passes. The rustdoc output is then
393420/// generated from the cleaned AST of the crate.
0 commit comments