]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/config.rs
Auto merge of #73645 - poliorcetics:ref-keyword, r=jyn514
[rust.git] / src / librustdoc / config.rs
1 use std::collections::BTreeMap;
2 use std::convert::TryFrom;
3 use std::ffi::OsStr;
4 use std::fmt;
5 use std::path::PathBuf;
6
7 use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
8 use rustc_session::config::{
9     build_codegen_options, build_debugging_options, get_cmd_lint_options, host_triple,
10     nightly_options,
11 };
12 use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
13 use rustc_session::getopts;
14 use rustc_session::lint::Level;
15 use rustc_session::search_paths::SearchPath;
16 use rustc_span::edition::{Edition, DEFAULT_EDITION};
17 use rustc_target::spec::TargetTriple;
18
19 use crate::core::new_handler;
20 use crate::externalfiles::ExternalHtml;
21 use crate::html;
22 use crate::html::markdown::IdMap;
23 use crate::html::render::StylePath;
24 use crate::html::static_files;
25 use crate::opts;
26 use crate::passes::{self, Condition, DefaultPassOption};
27 use crate::theme;
28
29 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
30 pub enum OutputFormat {
31     Json,
32     Html,
33 }
34
35 impl OutputFormat {
36     pub fn is_json(&self) -> bool {
37         match self {
38             OutputFormat::Json => true,
39             _ => false,
40         }
41     }
42 }
43
44 impl TryFrom<&str> for OutputFormat {
45     type Error = String;
46
47     fn try_from(value: &str) -> Result<Self, Self::Error> {
48         match value {
49             "json" => Ok(OutputFormat::Json),
50             "html" => Ok(OutputFormat::Html),
51             _ => Err(format!("unknown output format `{}`", value)),
52         }
53     }
54 }
55
56 /// Configuration options for rustdoc.
57 #[derive(Clone)]
58 pub struct Options {
59     // Basic options / Options passed directly to rustc
60     /// The crate root or Markdown file to load.
61     pub input: PathBuf,
62     /// The name of the crate being documented.
63     pub crate_name: Option<String>,
64     /// Whether or not this is a proc-macro crate
65     pub proc_macro_crate: bool,
66     /// How to format errors and warnings.
67     pub error_format: ErrorOutputType,
68     /// Library search paths to hand to the compiler.
69     pub libs: Vec<SearchPath>,
70     /// Library search paths strings to hand to the compiler.
71     pub lib_strs: Vec<String>,
72     /// The list of external crates to link against.
73     pub externs: Externs,
74     /// The list of external crates strings to link against.
75     pub extern_strs: Vec<String>,
76     /// List of `cfg` flags to hand to the compiler. Always includes `rustdoc`.
77     pub cfgs: Vec<String>,
78     /// Codegen options to hand to the compiler.
79     pub codegen_options: CodegenOptions,
80     /// Codegen options strings to hand to the compiler.
81     pub codegen_options_strs: Vec<String>,
82     /// Debugging (`-Z`) options to pass to the compiler.
83     pub debugging_options: DebuggingOptions,
84     /// Debugging (`-Z`) options strings to pass to the compiler.
85     pub debugging_options_strs: Vec<String>,
86     /// The target used to compile the crate against.
87     pub target: TargetTriple,
88     /// Edition used when reading the crate. Defaults to "2015". Also used by default when
89     /// compiling doctests from the crate.
90     pub edition: Edition,
91     /// The path to the sysroot. Used during the compilation process.
92     pub maybe_sysroot: Option<PathBuf>,
93     /// Lint information passed over the command-line.
94     pub lint_opts: Vec<(String, Level)>,
95     /// Whether to ask rustc to describe the lints it knows. Practically speaking, this will not be
96     /// used, since we abort if we have no input file, but it's included for completeness.
97     pub describe_lints: bool,
98     /// What level to cap lints at.
99     pub lint_cap: Option<Level>,
100
101     // Options specific to running doctests
102     /// Whether we should run doctests instead of generating docs.
103     pub should_test: bool,
104     /// List of arguments to pass to the test harness, if running tests.
105     pub test_args: Vec<String>,
106     /// Optional path to persist the doctest executables to, defaults to a
107     /// temporary directory if not set.
108     pub persist_doctests: Option<PathBuf>,
109     /// Runtool to run doctests with
110     pub runtool: Option<String>,
111     /// Arguments to pass to the runtool
112     pub runtool_args: Vec<String>,
113     /// Whether to allow ignoring doctests on a per-target basis
114     /// For example, using ignore-foo to ignore running the doctest on any target that
115     /// contains "foo" as a substring
116     pub enable_per_target_ignores: bool,
117
118     /// The path to a rustc-like binary to build tests with. If not set, we
119     /// default to loading from $sysroot/bin/rustc.
120     pub test_builder: Option<PathBuf>,
121
122     // Options that affect the documentation process
123     /// The selected default set of passes to use.
124     ///
125     /// Be aware: This option can come both from the CLI and from crate attributes!
126     pub default_passes: DefaultPassOption,
127     /// Any passes manually selected by the user.
128     ///
129     /// Be aware: This option can come both from the CLI and from crate attributes!
130     pub manual_passes: Vec<String>,
131     /// Whether to display warnings during doc generation or while gathering doctests. By default,
132     /// all non-rustdoc-specific lints are allowed when generating docs.
133     pub display_warnings: bool,
134     /// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items
135     /// with and without documentation.
136     pub show_coverage: bool,
137
138     // Options that alter generated documentation pages
139     /// Crate version to note on the sidebar of generated docs.
140     pub crate_version: Option<String>,
141     /// Collected options specific to outputting final pages.
142     pub render_options: RenderOptions,
143     /// Output format rendering (used only for "show-coverage" option for the moment)
144     pub output_format: Option<OutputFormat>,
145 }
146
147 impl fmt::Debug for Options {
148     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149         struct FmtExterns<'a>(&'a Externs);
150
151         impl<'a> fmt::Debug for FmtExterns<'a> {
152             fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153                 f.debug_map().entries(self.0.iter()).finish()
154             }
155         }
156
157         f.debug_struct("Options")
158             .field("input", &self.input)
159             .field("crate_name", &self.crate_name)
160             .field("proc_macro_crate", &self.proc_macro_crate)
161             .field("error_format", &self.error_format)
162             .field("libs", &self.libs)
163             .field("externs", &FmtExterns(&self.externs))
164             .field("cfgs", &self.cfgs)
165             .field("codegen_options", &"...")
166             .field("debugging_options", &"...")
167             .field("target", &self.target)
168             .field("edition", &self.edition)
169             .field("maybe_sysroot", &self.maybe_sysroot)
170             .field("lint_opts", &self.lint_opts)
171             .field("describe_lints", &self.describe_lints)
172             .field("lint_cap", &self.lint_cap)
173             .field("should_test", &self.should_test)
174             .field("test_args", &self.test_args)
175             .field("persist_doctests", &self.persist_doctests)
176             .field("default_passes", &self.default_passes)
177             .field("manual_passes", &self.manual_passes)
178             .field("display_warnings", &self.display_warnings)
179             .field("show_coverage", &self.show_coverage)
180             .field("crate_version", &self.crate_version)
181             .field("render_options", &self.render_options)
182             .field("runtool", &self.runtool)
183             .field("runtool_args", &self.runtool_args)
184             .field("enable-per-target-ignores", &self.enable_per_target_ignores)
185             .finish()
186     }
187 }
188
189 /// Configuration options for the HTML page-creation process.
190 #[derive(Clone, Debug)]
191 pub struct RenderOptions {
192     /// Output directory to generate docs into. Defaults to `doc`.
193     pub output: PathBuf,
194     /// External files to insert into generated pages.
195     pub external_html: ExternalHtml,
196     /// A pre-populated `IdMap` with the default headings and any headings added by Markdown files
197     /// processed by `external_html`.
198     pub id_map: IdMap,
199     /// If present, playground URL to use in the "Run" button added to code samples.
200     ///
201     /// Be aware: This option can come both from the CLI and from crate attributes!
202     pub playground_url: Option<String>,
203     /// Whether to sort modules alphabetically on a module page instead of using declaration order.
204     /// `true` by default.
205     //
206     // FIXME(misdreavus): the flag name is `--sort-modules-by-appearance` but the meaning is
207     // inverted once read.
208     pub sort_modules_alphabetically: bool,
209     /// List of themes to extend the docs with. Original argument name is included to assist in
210     /// displaying errors if it fails a theme check.
211     pub themes: Vec<StylePath>,
212     /// If present, CSS file that contains rules to add to the default CSS.
213     pub extension_css: Option<PathBuf>,
214     /// A map of crate names to the URL to use instead of querying the crate's `html_root_url`.
215     pub extern_html_root_urls: BTreeMap<String, String>,
216     /// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
217     pub resource_suffix: String,
218     /// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by
219     /// default.
220     //
221     // FIXME(misdreavus): the flag name is `--disable-minification` but the meaning is inverted
222     // once read.
223     pub enable_minification: bool,
224     /// Whether to create an index page in the root of the output directory. If this is true but
225     /// `enable_index_page` is None, generate a static listing of crates instead.
226     pub enable_index_page: bool,
227     /// A file to use as the index page at the root of the output directory. Overrides
228     /// `enable_index_page` to be true if set.
229     pub index_page: Option<PathBuf>,
230     /// An optional path to use as the location of static files. If not set, uses combinations of
231     /// `../` to reach the documentation root.
232     pub static_root_path: Option<String>,
233
234     // Options specific to reading standalone Markdown files
235     /// Whether to generate a table of contents on the output file when reading a standalone
236     /// Markdown file.
237     pub markdown_no_toc: bool,
238     /// Additional CSS files to link in pages generated from standalone Markdown files.
239     pub markdown_css: Vec<String>,
240     /// If present, playground URL to use in the "Run" button added to code samples generated from
241     /// standalone Markdown files. If not present, `playground_url` is used.
242     pub markdown_playground_url: Option<String>,
243     /// If false, the `select` element to have search filtering by crates on rendered docs
244     /// won't be generated.
245     pub generate_search_filter: bool,
246     /// Document items that have lower than `pub` visibility.
247     pub document_private: bool,
248     /// Document items that have `doc(hidden)`.
249     pub document_hidden: bool,
250 }
251
252 impl Options {
253     /// Parses the given command-line for options. If an error message or other early-return has
254     /// been printed, returns `Err` with the exit code.
255     pub fn from_matches(matches: &getopts::Matches) -> Result<Options, i32> {
256         // Check for unstable options.
257         nightly_options::check_nightly_options(&matches, &opts());
258
259         if matches.opt_present("h") || matches.opt_present("help") {
260             crate::usage("rustdoc");
261             return Err(0);
262         } else if matches.opt_present("version") {
263             rustc_driver::version("rustdoc", &matches);
264             return Err(0);
265         }
266
267         if matches.opt_strs("passes") == ["list"] {
268             println!("Available passes for running rustdoc:");
269             for pass in passes::PASSES {
270                 println!("{:>20} - {}", pass.name, pass.description);
271             }
272             println!("\nDefault passes for rustdoc:");
273             for p in passes::DEFAULT_PASSES {
274                 print!("{:>20}", p.pass.name);
275                 println_condition(p.condition);
276             }
277
278             if nightly_options::is_nightly_build() {
279                 println!("\nPasses run with `--show-coverage`:");
280                 for p in passes::COVERAGE_PASSES {
281                     print!("{:>20}", p.pass.name);
282                     println_condition(p.condition);
283                 }
284             }
285
286             fn println_condition(condition: Condition) {
287                 use Condition::*;
288                 match condition {
289                     Always => println!(),
290                     WhenDocumentPrivate => println!("  (when --document-private-items)"),
291                     WhenNotDocumentPrivate => println!("  (when not --document-private-items)"),
292                     WhenNotDocumentHidden => println!("  (when not --document-hidden-items)"),
293                 }
294             }
295
296             return Err(0);
297         }
298
299         let color = config::parse_color(&matches);
300         let (json_rendered, _artifacts) = config::parse_json(&matches);
301         let error_format = config::parse_error_format(&matches, color, json_rendered);
302
303         let codegen_options = build_codegen_options(matches, error_format);
304         let debugging_options = build_debugging_options(matches, error_format);
305
306         let diag = new_handler(error_format, None, &debugging_options);
307
308         // check for deprecated options
309         check_deprecated_options(&matches, &diag);
310
311         let to_check = matches.opt_strs("check-theme");
312         if !to_check.is_empty() {
313             let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes());
314             let mut errors = 0;
315
316             println!("rustdoc: [check-theme] Starting tests! (Ignoring all other arguments)");
317             for theme_file in to_check.iter() {
318                 print!(" - Checking \"{}\"...", theme_file);
319                 let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag);
320                 if !differences.is_empty() || !success {
321                     println!(" FAILED");
322                     errors += 1;
323                     if !differences.is_empty() {
324                         println!("{}", differences.join("\n"));
325                     }
326                 } else {
327                     println!(" OK");
328                 }
329             }
330             if errors != 0 {
331                 return Err(1);
332             }
333             return Err(0);
334         }
335
336         if matches.free.is_empty() {
337             diag.struct_err("missing file operand").emit();
338             return Err(1);
339         }
340         if matches.free.len() > 1 {
341             diag.struct_err("too many file operands").emit();
342             return Err(1);
343         }
344         let input = PathBuf::from(&matches.free[0]);
345
346         let libs = matches
347             .opt_strs("L")
348             .iter()
349             .map(|s| SearchPath::from_cli_opt(s, error_format))
350             .collect();
351         let externs = parse_externs(&matches, &debugging_options, error_format);
352         let extern_html_root_urls = match parse_extern_html_roots(&matches) {
353             Ok(ex) => ex,
354             Err(err) => {
355                 diag.struct_err(err).emit();
356                 return Err(1);
357             }
358         };
359
360         let test_args = matches.opt_strs("test-args");
361         let test_args: Vec<String> =
362             test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
363
364         let should_test = matches.opt_present("test");
365
366         let output =
367             matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
368         let cfgs = matches.opt_strs("cfg");
369
370         let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));
371
372         if let Some(ref p) = extension_css {
373             if !p.is_file() {
374                 diag.struct_err("option --extend-css argument must be a file").emit();
375                 return Err(1);
376             }
377         }
378
379         let mut themes = Vec::new();
380         if matches.opt_present("theme") {
381             let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes());
382
383             for (theme_file, theme_s) in
384                 matches.opt_strs("theme").iter().map(|s| (PathBuf::from(&s), s.to_owned()))
385             {
386                 if !theme_file.is_file() {
387                     diag.struct_err(&format!("invalid argument: \"{}\"", theme_s))
388                         .help("arguments to --theme must be files")
389                         .emit();
390                     return Err(1);
391                 }
392                 if theme_file.extension() != Some(OsStr::new("css")) {
393                     diag.struct_err(&format!("invalid argument: \"{}\"", theme_s)).emit();
394                     return Err(1);
395                 }
396                 let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
397                 if !success {
398                     diag.struct_err(&format!("error loading theme file: \"{}\"", theme_s)).emit();
399                     return Err(1);
400                 } else if !ret.is_empty() {
401                     diag.struct_warn(&format!(
402                         "theme file \"{}\" is missing CSS rules from the \
403                                                default theme",
404                         theme_s
405                     ))
406                     .warn("the theme may appear incorrect when loaded")
407                     .help(&format!(
408                         "to see what rules are missing, call `rustdoc \
409                                         --check-theme \"{}\"`",
410                         theme_s
411                     ))
412                     .emit();
413                 }
414                 themes.push(StylePath { path: theme_file, disabled: true });
415             }
416         }
417
418         let edition = if let Some(e) = matches.opt_str("edition") {
419             match e.parse() {
420                 Ok(e) => e,
421                 Err(_) => {
422                     diag.struct_err("could not parse edition").emit();
423                     return Err(1);
424                 }
425             }
426         } else {
427             DEFAULT_EDITION
428         };
429
430         let mut id_map = html::markdown::IdMap::new();
431         id_map.populate(html::render::initial_ids());
432         let external_html = match ExternalHtml::load(
433             &matches.opt_strs("html-in-header"),
434             &matches.opt_strs("html-before-content"),
435             &matches.opt_strs("html-after-content"),
436             &matches.opt_strs("markdown-before-content"),
437             &matches.opt_strs("markdown-after-content"),
438             &diag,
439             &mut id_map,
440             edition,
441             &None,
442         ) {
443             Some(eh) => eh,
444             None => return Err(3),
445         };
446
447         match matches.opt_str("r").as_deref() {
448             Some("rust") | None => {}
449             Some(s) => {
450                 diag.struct_err(&format!("unknown input format: {}", s)).emit();
451                 return Err(1);
452             }
453         }
454
455         let index_page = matches.opt_str("index-page").map(|s| PathBuf::from(&s));
456         if let Some(ref index_page) = index_page {
457             if !index_page.is_file() {
458                 diag.struct_err("option `--index-page` argument must be a file").emit();
459                 return Err(1);
460             }
461         }
462
463         let target =
464             matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| {
465                 if target.ends_with(".json") {
466                     TargetTriple::TargetPath(PathBuf::from(target))
467                 } else {
468                     TargetTriple::TargetTriple(target)
469                 }
470             });
471
472         let show_coverage = matches.opt_present("show-coverage");
473
474         let default_passes = if matches.opt_present("no-defaults") {
475             passes::DefaultPassOption::None
476         } else if show_coverage {
477             passes::DefaultPassOption::Coverage
478         } else {
479             passes::DefaultPassOption::Default
480         };
481         let manual_passes = matches.opt_strs("passes");
482
483         let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
484             Ok(types) => types,
485             Err(e) => {
486                 diag.struct_err(&format!("unknown crate type: {}", e)).emit();
487                 return Err(1);
488             }
489         };
490
491         let output_format = match matches.opt_str("output-format") {
492             Some(s) => match OutputFormat::try_from(s.as_str()) {
493                 Ok(o) => {
494                     if o.is_json() && !show_coverage {
495                         diag.struct_err("json output format isn't supported for doc generation")
496                             .emit();
497                         return Err(1);
498                     } else if !o.is_json() && show_coverage {
499                         diag.struct_err(
500                             "html output format isn't supported for the --show-coverage option",
501                         )
502                         .emit();
503                         return Err(1);
504                     }
505                     Some(o)
506                 }
507                 Err(e) => {
508                     diag.struct_err(&e).emit();
509                     return Err(1);
510                 }
511             },
512             None => None,
513         };
514         let crate_name = matches.opt_str("crate-name");
515         let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
516         let playground_url = matches.opt_str("playground-url");
517         let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
518         let display_warnings = matches.opt_present("display-warnings");
519         let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
520         let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default();
521         let enable_minification = !matches.opt_present("disable-minification");
522         let markdown_no_toc = matches.opt_present("markdown-no-toc");
523         let markdown_css = matches.opt_strs("markdown-css");
524         let markdown_playground_url = matches.opt_str("markdown-playground-url");
525         let crate_version = matches.opt_str("crate-version");
526         let enable_index_page = matches.opt_present("enable-index-page") || index_page.is_some();
527         let static_root_path = matches.opt_str("static-root-path");
528         let generate_search_filter = !matches.opt_present("disable-per-crate-search");
529         let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from);
530         let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
531         let codegen_options_strs = matches.opt_strs("C");
532         let debugging_options_strs = matches.opt_strs("Z");
533         let lib_strs = matches.opt_strs("L");
534         let extern_strs = matches.opt_strs("extern");
535         let runtool = matches.opt_str("runtool");
536         let runtool_args = matches.opt_strs("runtool-arg");
537         let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
538         let document_private = matches.opt_present("document-private-items");
539         let document_hidden = matches.opt_present("document-hidden-items");
540
541         let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
542
543         Ok(Options {
544             input,
545             crate_name,
546             proc_macro_crate,
547             error_format,
548             libs,
549             lib_strs,
550             externs,
551             extern_strs,
552             cfgs,
553             codegen_options,
554             codegen_options_strs,
555             debugging_options,
556             debugging_options_strs,
557             target,
558             edition,
559             maybe_sysroot,
560             lint_opts,
561             describe_lints,
562             lint_cap,
563             should_test,
564             test_args,
565             default_passes,
566             manual_passes,
567             display_warnings,
568             show_coverage,
569             crate_version,
570             persist_doctests,
571             runtool,
572             runtool_args,
573             enable_per_target_ignores,
574             test_builder,
575             render_options: RenderOptions {
576                 output,
577                 external_html,
578                 id_map,
579                 playground_url,
580                 sort_modules_alphabetically,
581                 themes,
582                 extension_css,
583                 extern_html_root_urls,
584                 resource_suffix,
585                 enable_minification,
586                 enable_index_page,
587                 index_page,
588                 static_root_path,
589                 markdown_no_toc,
590                 markdown_css,
591                 markdown_playground_url,
592                 generate_search_filter,
593                 document_private,
594                 document_hidden,
595             },
596             output_format,
597         })
598     }
599
600     /// Returns `true` if the file given as `self.input` is a Markdown file.
601     pub fn markdown_input(&self) -> bool {
602         self.input.extension().map_or(false, |e| e == "md" || e == "markdown")
603     }
604 }
605
606 /// Prints deprecation warnings for deprecated options
607 fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Handler) {
608     let deprecated_flags = ["input-format", "output-format", "no-defaults", "passes"];
609
610     for flag in deprecated_flags.iter() {
611         if matches.opt_present(flag) {
612             if *flag == "output-format" && matches.opt_present("show-coverage") {
613                 continue;
614             }
615             let mut err =
616                 diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag));
617             err.warn(
618                 "see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
619                  for more information",
620             );
621
622             if *flag == "no-defaults" {
623                 err.help("you may want to use --document-private-items");
624             }
625
626             err.emit();
627         }
628     }
629
630     let removed_flags = ["plugins", "plugin-path"];
631
632     for &flag in removed_flags.iter() {
633         if matches.opt_present(flag) {
634             diag.struct_warn(&format!("the '{}' flag no longer functions", flag))
635                 .warn("see CVE-2018-1000622")
636                 .emit();
637         }
638     }
639 }
640
641 /// Extracts `--extern-html-root-url` arguments from `matches` and returns a map of crate names to
642 /// the given URLs. If an `--extern-html-root-url` argument was ill-formed, returns an error
643 /// describing the issue.
644 fn parse_extern_html_roots(
645     matches: &getopts::Matches,
646 ) -> Result<BTreeMap<String, String>, &'static str> {
647     let mut externs = BTreeMap::new();
648     for arg in &matches.opt_strs("extern-html-root-url") {
649         let mut parts = arg.splitn(2, '=');
650         let name = parts.next().ok_or("--extern-html-root-url must not be empty")?;
651         let url = parts.next().ok_or("--extern-html-root-url must be of the form name=url")?;
652         externs.insert(name.to_string(), url.to_string());
653     }
654
655     Ok(externs)
656 }