-
Notifications
You must be signed in to change notification settings - Fork 13.8k
rustdoc: Add flag to use external source code pages #69167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
0909f7b
0a079f0
52dbe7c
7cc197c
b5c573b
cbf13bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -453,7 +453,7 @@ override `ignore`. | |
|
||
### `--runtool`, `--runtool-arg`: program to run tests with; args to pass to it | ||
|
||
Using thses options looks like this: | ||
Using these options looks like this: | ||
|
||
```bash | ||
$ rustdoc src/lib.rs -Z unstable-options --runtool runner --runtool-arg --do-thing --runtool-arg --do-other-thing | ||
|
@@ -467,3 +467,20 @@ $ rustdoc src/lib.rs -Z unstable-options --runtool valgrind | |
``` | ||
|
||
Another use case would be to run a test inside an emulator, or through a Virtual Machine. | ||
|
||
### `--source-code-external-url`: using external source code | ||
|
||
In case you don't want to generate the source code files and instead use existing ones (available | ||
through an HTTP URL!), you can use this option: | ||
|
||
```bash | ||
$ rustdoc src/lib.rs -Z unstable-options --source-code-external-url 'https://somewhere.com' | ||
|
||
``` | ||
|
||
Note that generated source URLs will look like this: | ||
|
||
```text | ||
https://somewhere.com/[crate name] | ||
``` | ||
|
||
It is equivalent to the local `src/[crate name]` folder. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,7 @@ crate struct SharedContext { | |
/// The default edition used to parse doctests. | ||
pub edition: Edition, | ||
pub codes: ErrorCodes, | ||
pub source_code_external_url: Option<String>, | ||
playground: Option<markdown::Playground>, | ||
} | ||
|
||
|
@@ -409,6 +410,7 @@ pub fn run( | |
static_root_path, | ||
generate_search_filter, | ||
generate_redirect_pages, | ||
source_code_external_url, | ||
.. | ||
} = options; | ||
|
||
|
@@ -467,6 +469,7 @@ pub fn run( | |
collapsed: krate.collapsed, | ||
src_root, | ||
include_sources, | ||
source_code_external_url, | ||
local_sources: Default::default(), | ||
issue_tracker_base_url, | ||
layout, | ||
|
@@ -1550,6 +1553,21 @@ impl Context { | |
} | ||
} | ||
|
||
fn compute_path(path: String) -> String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to use |
||
if path.split('/').find(|x| *x == "..").is_none() { | ||
return path; | ||
} | ||
let mut new_path = Vec::new(); | ||
for part in path.split('/') { | ||
if part == ".." && !new_path.is_empty() { | ||
new_path.pop(); | ||
} else { | ||
new_path.push(part); | ||
} | ||
} | ||
new_path.join("/") | ||
} | ||
|
||
impl Context { | ||
/// Generates a url appropriate for an `href` attribute back to the source of | ||
/// this item. | ||
|
@@ -1602,13 +1620,26 @@ impl Context { | |
} else { | ||
format!("{}-{}", item.source.loline, item.source.hiline) | ||
}; | ||
Some(format!( | ||
"{root}src/{krate}/{path}#{lines}", | ||
root = Escape(&root), | ||
krate = krate, | ||
path = path, | ||
lines = lines | ||
)) | ||
if let Some(ref source_code_external_url) = self.shared.source_code_external_url { | ||
Some(format!( | ||
"{path}#{lines}", | ||
path = compute_path(format!( | ||
"{root}{krate}/{path}", | ||
jyn514 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
root = source_code_external_url, | ||
krate = krate, | ||
path = path, | ||
),), | ||
lines = lines | ||
)) | ||
} else { | ||
Some(format!( | ||
"{root}src/{krate}/{path}#{lines}", | ||
root = Escape(&root), | ||
krate = krate, | ||
path = path, | ||
lines = lines | ||
)) | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// compile-flags:--Z unstable-options --source-code-external-url /hello | ||
|
||
pub struct Foo; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: option `--source-code-external-url` argument cannot be an absolute local path | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// ignore-tidy-linelength | ||
// compile-flags: -Z unstable-options --source-code-external-url https://a.a | ||
|
||
#![crate_name = "foo"] | ||
|
||
// @has foo/struct.Foo.html | ||
// @has - '//h1[@class="fqn"]//a[@href="https://a.a/foo/source_code_external_url.rs.html#8"]' '[src]' | ||
pub struct Foo; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// ignore-tidy-linelength | ||
// compile-flags: -Z unstable-options --source-code-external-url https://a.a/ | ||
|
||
#![crate_name = "foo"] | ||
|
||
// @has foo/struct.Foo.html | ||
// @has - '//h1[@class="fqn"]//a[@href="https://a.a/foo/source_code_external_url2.rs.html#8"]' '[src]' | ||
pub struct Foo; |
Uh oh!
There was an error while loading. Please reload this page.