-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[rustdoc] Generate redirect map file #81223
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3a92f77
Add --generate-redirect-map option to replace HTML redirection file w…
GuillaumeGomez 2b59e76
Add tests for --generate-redirect-map option
GuillaumeGomez 1a7126b
Add full test for rustdoc map file
GuillaumeGomez 41fc58b
Fix nits
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-include ../tools.mk | ||
|
||
all: | ||
$(RUSTDOC) -Z unstable-options --generate-redirect-map foo.rs -o "$(TMPDIR)/out" | ||
"$(PYTHON)" validate_json.py "$(TMPDIR)/out" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"foo/macro.foo!.html": "foo/macro.foo.html", | ||
"foo/private/struct.Quz.html": "foo/struct.Quz.html", | ||
"foo/hidden/struct.Bar.html": "foo/struct.Bar.html" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pub use private::Quz; | ||
pub use hidden::Bar; | ||
|
||
mod private { | ||
pub struct Quz; | ||
} | ||
|
||
#[doc(hidden)] | ||
pub mod hidden { | ||
pub struct Bar; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! foo { | ||
() => {} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/run-make-fulldeps/rustdoc-map-file/validate_json.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import json | ||
|
||
|
||
def find_redirect_map_file(folder, errors): | ||
for root, dirs, files in os.walk(folder): | ||
for name in files: | ||
if not name.endswith("redirect-map.json"): | ||
continue | ||
with open(os.path.join(root, name)) as f: | ||
data = json.load(f) | ||
with open("expected.json") as f: | ||
expected = json.load(f) | ||
for key in expected: | ||
if expected[key] != data.get(key): | ||
errors.append("Expected `{}` for key `{}`, found: `{}`".format( | ||
expected[key], key, data.get(key))) | ||
else: | ||
del data[key] | ||
for key in data: | ||
errors.append("Extra data not expected: key: `{}`, data: `{}`".format( | ||
key, data[key])) | ||
return True | ||
return False | ||
|
||
|
||
if len(sys.argv) != 2: | ||
print("Expected doc directory to check!") | ||
sys.exit(1) | ||
|
||
errors = [] | ||
if not find_redirect_map_file(sys.argv[1], errors): | ||
print("Didn't find the map file in `{}`...".format(sys.argv[1])) | ||
sys.exit(1) | ||
for err in errors: | ||
print("=> {}".format(err)) | ||
if len(errors) != 0: | ||
sys.exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// compile-flags: -Z unstable-options --generate-redirect-map | ||
|
||
#![crate_name = "foo"] | ||
|
||
// @!has foo/redirect-map.json | ||
pub struct Foo; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// compile-flags: -Z unstable-options --generate-redirect-map | ||
|
||
#![crate_name = "foo"] | ||
|
||
// @!has foo/private/struct.Quz.html | ||
// @!has foo/hidden/struct.Bar.html | ||
// @has foo/redirect-map.json | ||
GuillaumeGomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub use private::Quz; | ||
pub use hidden::Bar; | ||
|
||
mod private { | ||
pub struct Quz; | ||
} | ||
|
||
#[doc(hidden)] | ||
pub mod hidden { | ||
pub struct Bar; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! foo { | ||
() => {} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.