rustdoc: dep-info for standalone markdown inputs#154352
rustdoc: dep-info for standalone markdown inputs#154352notriddle wants to merge 3 commits intorust-lang:mainfrom
Conversation
| // construct a phony "crate" without actually running the parser | ||
| // allows us to use other compiler infrastructure like dep-info | ||
| let file = | ||
| compiler.sess.source_map().load_file(&md_input).map_err(|e| { |
There was a problem hiding this comment.
Using the SourceMap API has other observable side effects like source file normalization (i.e., removing a leading Unicode BOM U+FEFF and replacing CRLF with LF) but that's fine.
E.g., it means we now accept the string represented by "\u{FEFF}# T" whereas on stable&main we error out with invalid markdown file: no initial lines starting with `# ` or `%`.
There was a problem hiding this comment.
If .rs files do it, then it's hard to think of a reason we wouldn't want it for .md files, too.
| if has_dep_info { | ||
| // Register the loaded external files in the source map so they show up in depinfo. | ||
| // We can't load them via the source map because it gets created after we process the options. | ||
| for external_path in &loaded_paths { |
There was a problem hiding this comment.
Flags like --theme and --extend-css don't seem to be used for standalone markdown files IINM, so they don't really need to be included in the dep-info. Of course, impl'ing that isn't worth the complexity, this approach is fine as is imo.
| let mut md_opts = opt.clone(); | ||
| md_opts.output = cx.dst.clone(); | ||
| md_opts.external_html = cx.shared.layout.external_html.clone(); | ||
| let file = try_err!(cx.sess().source_map().load_file(&index_page), &index_page); |
There was a problem hiding this comment.
I have tested your patch locally and ran rustdoc test.md --index-page my-index-page.md --emit=dep-info (with the appropriate source files) but my-index-page.md wasn't listed in the resulting dep info (for comparison, --html-after-content did obv work as the tests also confirm); I might've overlooked something tho.
Note that the custom index page isn't properly tracked in "normal mode" either (where the source file is Rust), neither on main nor on your branch AFAICT.
There was a problem hiding this comment.
I see.
I notice that write_dep_info is run before the renderer is run. To fix this, I either need to add the file to the source map separately (which can be done the same way --html-before-content and related options are done), or move when the renderer runs.
The less risky option, at least in the short term, is adding the file separately.
Part of #146220 (comment)
r? @fmease