Skip to content

Commit e1367ef

Browse files
Update unstable-crate test
1 parent 274543b commit e1367ef

File tree

7 files changed

+1118
-537
lines changed

7 files changed

+1118
-537
lines changed

src/Cargo.lock

Lines changed: 1032 additions & 492 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustdoc/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ env_logger = { version = "0.4", default-features = false }
1313
log = "0.3"
1414
pulldown-cmark = { version = "0.0.14", default-features = false }
1515

16-
[target.'cfg(not(stage0))'.dependencies]
17-
html-diff = "0.0.2"
16+
[target.'cfg(not(any(stage0, stage1)))'.dependencies]
17+
html-diff = "0.0.3"
1818

1919
[build-dependencies]
2020
build_helper = { path = "../build_helper" }

src/librustdoc/html/render.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use html::item_type::ItemType;
7575
use html::markdown::{self, Markdown, MarkdownHtml, MarkdownSummaryLine, RenderType};
7676
use html::{highlight, layout};
7777

78-
#[cfg(not(stage0))]
78+
#[cfg(not(any(stage0, stage1)))]
7979
use html_diff;
8080

8181
/// A pair of name and its optional document.
@@ -1648,7 +1648,7 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re
16481648
Ok(())
16491649
}
16501650

1651-
#[cfg(not(stage0))]
1651+
#[cfg(not(any(stage0, stage1)))]
16521652
fn get_html_diff(w: &mut fmt::Formatter, md_text: &str, render_type: RenderType,
16531653
prefix: &str) -> fmt::Result {
16541654
if render_type == RenderType::Pulldown {
@@ -1671,9 +1671,10 @@ fn get_html_diff(w: &mut fmt::Formatter, md_text: &str, render_type: RenderType,
16711671
}
16721672
}
16731673

1674-
#[cfg(stage0)]
1675-
fn get_html_diff(w: &mut fmt::Formatter, md_text: &str, render_type: RenderType) -> fmt::Result {
1676-
write!(w, "<div class='docblock'>{}</div>", Markdown(md_text, render_type))
1674+
#[cfg(any(stage0, stage1))]
1675+
fn get_html_diff(w: &mut fmt::Formatter, md_text: &str, render_type: RenderType,
1676+
prefix: &str) -> fmt::Result {
1677+
write!(w, "<div class='docblock'>{}{}</div>", prefix, Markdown(md_text, render_type))
16771678
}
16781679

16791680
fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLink,
@@ -1685,7 +1686,7 @@ fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLin
16851686
} else {
16861687
format!("{}", &plain_summary_line(Some(s)))
16871688
};
1688-
get_html_diff(&markdown, render_type, prefix)?;
1689+
get_html_diff(w, &markdown, render_type, prefix)?;
16891690
} else if !prefix.is_empty() {
16901691
write!(w, "<div class='docblock'>{}</div>", prefix)?;
16911692
}
@@ -1709,7 +1710,7 @@ fn render_assoc_const_value(item: &clean::Item) -> String {
17091710
fn document_full(w: &mut fmt::Formatter, item: &clean::Item,
17101711
render_type: RenderType, prefix: &str) -> fmt::Result {
17111712
if let Some(s) = item.doc_value() {
1712-
get_html_diff(format!("{}{}", md_render_assoc_item(item), s), render_type, prefix)?;
1713+
get_html_diff(w, s, render_type, prefix)?;
17131714
} else if !prefix.is_empty() {
17141715
write!(w, "<div class='docblock'>{}</div>", prefix)?;
17151716
}

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
extern crate arena;
2929
extern crate getopts;
3030
extern crate env_logger;
31-
#[cfg(not(stage0))]
31+
#[cfg(not(any(stage0, stage1)))]
3232
extern crate html_diff;
3333
extern crate libc;
3434
extern crate rustc;
Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
1-
-include ../tools.mk
1+
PYTHON=python
22

3-
# This is a whitelist of files which are stable crates or simply are not crates,
4-
# we don't check for the instability of these crates as they're all stable!
5-
STABLE_CRATES := \
6-
std \
7-
core \
8-
proc_macro \
9-
rsbegin.o \
10-
rsend.o \
11-
dllcrt2.o \
12-
crt2.o \
13-
clang_rt.%_dynamic.dylib
14-
15-
# Generate a list of all crates in the sysroot. To do this we list all files in
16-
# rustc's sysroot, look at the filename, strip everything after the `-`, and
17-
# strip the leading `lib` (if present)
18-
SYSROOT := $(shell $(RUSTC) --print sysroot)
19-
LIBS := $(wildcard $(SYSROOT)/lib/rustlib/$(TARGET)/lib/*)
20-
LIBS := $(foreach lib,$(LIBS),$(notdir $(lib)))
21-
LIBS := $(foreach lib,$(LIBS),$(word 1,$(subst -, ,$(lib))))
22-
LIBS := $(foreach lib,$(LIBS),$(patsubst lib%,%,$(lib)))
23-
LIBS := $(filter-out $(STABLE_CRATES),$(LIBS))
24-
25-
all: $(foreach lib,$(LIBS),check-crate-$(lib)-is-unstable)
26-
27-
check-crate-%-is-unstable:
28-
@echo verifying $* is an unstable crate
29-
@echo 'extern crate $*;' | \
30-
$(RUSTC) - --crate-type rlib 2>&1 | cat > $(TMPDIR)/$*; \
31-
true
32-
@grep -q 'use of unstable library feature' $(TMPDIR)/$* || \
33-
(echo crate $* is not unstable && \
34-
cat $(TMPDIR)/$* && \
35-
false)
3+
all:
4+
python test.py
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
# file at the top-level directory of this distribution and at
3+
# http://rust-lang.org/COPYRIGHT.
4+
#
5+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
# option. This file may not be copied, modified, or distributed
9+
# except according to those terms.
10+
11+
import sys
12+
import os
13+
from os import listdir
14+
from os.path import isfile, join
15+
from subprocess import PIPE, Popen
16+
17+
18+
# This is a whitelist of files which are stable crates or simply are not crates,
19+
# we don't check for the instability of these crates as they're all stable!
20+
STABLE_CRATES = ['std', 'core', 'proc_macro', 'rsbegin.o', 'rsend.o', 'dllcrt2.o', 'crt2.o',
21+
'clang_rt']
22+
23+
24+
def convert_to_string(s):
25+
if s.__class__.__name__ == 'bytes':
26+
return s.decode('utf-8')
27+
return s
28+
29+
30+
def exec_command(command, to_input=None):
31+
child = None
32+
if to_input is None:
33+
child = Popen(command, stdout=PIPE, stderr=PIPE)
34+
else:
35+
child = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE)
36+
stdout, stderr = child.communicate(input=to_input)
37+
return (convert_to_string(stdout), convert_to_string(stderr))
38+
39+
40+
def check_lib(lib):
41+
if lib['name'] in STABLE_CRATES:
42+
return True
43+
print('verifying if {} is an unstable crate'.format(lib['name']))
44+
stdout, stderr = exec_command([os.environ['RUSTC'], '-', '--crate-type', 'rlib',
45+
'--extern', '{}={}'.format(lib['name'], lib['path'])],
46+
to_input='extern crate {};'.format(lib['name']))
47+
if not 'use of unstable library feature' in '{}{}'.format(stdout, stderr):
48+
print('crate {} "{}" is not unstable'.format(lib['name'], lib['path']))
49+
print('{}{}'.format(stdout, stderr))
50+
print('')
51+
return False
52+
return True
53+
54+
# Generate a list of all crates in the sysroot. To do this we list all files in
55+
# rustc's sysroot, look at the filename, strip everything after the `-`, and
56+
# strip the leading `lib` (if present)
57+
def get_all_libs(dir_path):
58+
return [{ 'path': join(dir_path, f), 'name': f[3:].split('-')[0] }
59+
for f in listdir(dir_path)
60+
if isfile(join(dir_path, f)) and f.endswith('.rlib') and f not in STABLE_CRATES]
61+
62+
63+
sysroot = exec_command([os.environ['RUSTC'], '--print', 'sysroot'])[0].replace('\n', '')
64+
libs = get_all_libs(join(sysroot, 'lib/rustlib/{}/lib'.format(os.environ['TARGET'])))
65+
66+
ret = 0
67+
for lib in libs:
68+
if not check_lib(lib):
69+
# We continue so users can see all the not unstable crates.
70+
ret = 1
71+
sys.exit(ret)

src/test/rustdoc/issue-12834.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// @has issue_12834/fn.foo.html
1616
// @has - //pre 'a + b '
1717

18-
/// ```text
18+
/// ```
1919
/// a + b ∈ Self ∀ a, b ∈ Self
2020
/// ```
2121
pub fn foo() {}

0 commit comments

Comments
 (0)