Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
51580d46
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51580d46
编写于
1月 26, 2018
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for themes
上级
63ee1cd8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
138 addition
and
25 deletion
+138
-25
src/bootstrap/builder.rs
src/bootstrap/builder.rs
+1
-1
src/bootstrap/check.rs
src/bootstrap/check.rs
+0
-1
src/bootstrap/test.rs
src/bootstrap/test.rs
+42
-0
src/librustdoc/lib.rs
src/librustdoc/lib.rs
+4
-4
src/librustdoc/theme.rs
src/librustdoc/theme.rs
+39
-19
src/tools/rustdoc-themes/test-themes.py
src/tools/rustdoc-themes/test-themes.py
+52
-0
未找到文件。
src/bootstrap/builder.rs
浏览文件 @
51580d46
...
...
@@ -258,7 +258,7 @@ fn get_step_descriptions(kind: Kind) -> Vec<StepDescription> {
test
::
HostCompiletest
,
test
::
Crate
,
test
::
CrateLibrustc
,
test
::
Rustdoc
,
test
::
Linkcheck
,
test
::
Cargotest
,
test
::
Cargo
,
test
::
Rls
,
test
::
Docs
,
test
::
ErrorIndex
,
test
::
Distcheck
,
test
::
Rustfmt
,
test
::
Miri
,
test
::
Clippy
,
test
::
RustdocJS
),
test
::
RustdocJS
,
test
::
RustdocTheme
),
Kind
::
Bench
=>
describe!
(
test
::
Crate
,
test
::
CrateLibrustc
),
Kind
::
Doc
=>
describe!
(
doc
::
UnstableBook
,
doc
::
UnstableBookGen
,
doc
::
TheBook
,
doc
::
Standalone
,
doc
::
Std
,
doc
::
Test
,
doc
::
Rustc
,
doc
::
ErrorIndex
,
doc
::
Nomicon
,
...
...
src/bootstrap/check.rs
浏览文件 @
51580d46
...
...
@@ -160,4 +160,3 @@ pub fn libtest_stamp(build: &Build, compiler: Compiler, target: Interned<String>
pub
fn
librustc_stamp
(
build
:
&
Build
,
compiler
:
Compiler
,
target
:
Interned
<
String
>
)
->
PathBuf
{
build
.cargo_out
(
compiler
,
Mode
::
Librustc
,
target
)
.join
(
".librustc-check.stamp"
)
}
src/bootstrap/test.rs
浏览文件 @
51580d46
...
...
@@ -424,6 +424,48 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
env
::
join_paths
(
iter
::
once
(
path
)
.chain
(
env
::
split_paths
(
&
old_path
)))
.expect
(
""
)
}
#[derive(Debug,
Copy,
Clone,
Hash,
PartialEq,
Eq)]
pub
struct
RustdocTheme
{
pub
compiler
:
Compiler
,
pub
host
:
Interned
<
String
>
,
}
impl
Step
for
RustdocTheme
{
type
Output
=
();
const
DEFAULT
:
bool
=
true
;
const
ONLY_HOSTS
:
bool
=
true
;
fn
should_run
(
run
:
ShouldRun
)
->
ShouldRun
{
run
.path
(
"src/tools/rustdoc-themes"
)
}
fn
make_run
(
run
:
RunConfig
)
{
let
compiler
=
run
.builder
.compiler
(
run
.builder.top_stage
,
run
.host
);
run
.builder
.ensure
(
RustdocTheme
{
compiler
:
compiler
,
host
:
run
.builder.build.build
,
});
}
fn
run
(
self
,
builder
:
&
Builder
)
{
let
rustdoc
=
builder
.rustdoc
(
self
.compiler.host
);
let
mut
cmd
=
Command
::
new
(
builder
.config.python
.clone
()
.expect
(
"python not defined"
));
cmd
.args
(
&
[
"src/tools/rustdoc-themes/test-themes.py"
,
rustdoc
.to_str
()
.unwrap
()]);
cmd
.env
(
"RUSTC_STAGE"
,
self
.compiler.stage
.to_string
())
.env
(
"RUSTC_SYSROOT"
,
builder
.sysroot
(
self
.compiler
))
.env
(
"RUSTDOC_LIBDIR"
,
builder
.sysroot_libdir
(
self
.compiler
,
self
.compiler.host
))
.env
(
"CFG_RELEASE_CHANNEL"
,
&
builder
.build.config.channel
)
.env
(
"RUSTDOC_REAL"
,
builder
.rustdoc
(
self
.host
))
.env
(
"RUSTDOC_CRATE_VERSION"
,
builder
.build
.rust_version
())
.env
(
"RUSTC_BOOTSTRAP"
,
"1"
);
if
let
Some
(
linker
)
=
builder
.build
.linker
(
self
.host
)
{
cmd
.env
(
"RUSTC_TARGET_LINKER"
,
linker
);
}
builder
.run
(
&
mut
cmd
);
}
}
#[derive(Debug,
Copy,
Clone,
Hash,
PartialEq,
Eq)]
pub
struct
RustdocJS
{
pub
host
:
Interned
<
String
>
,
...
...
src/librustdoc/lib.rs
浏览文件 @
51580d46
...
...
@@ -324,13 +324,13 @@ pub fn main_args(args: &[String]) -> isize {
let
to_check
=
matches
.opt_strs
(
"theme-checker"
);
if
!
to_check
.is_empty
()
{
let
path
es
=
theme
::
load_css_pathe
s
(
include_bytes!
(
"html/static/themes/main.css"
));
let
path
s
=
theme
::
load_css_path
s
(
include_bytes!
(
"html/static/themes/main.css"
));
let
mut
errors
=
0
;
println!
(
"rustdoc: [theme-checker] Starting tests!"
);
for
theme_file
in
to_check
.iter
()
{
print!
(
" - Checking
\"
{}
\"
..."
,
theme_file
);
let
(
success
,
differences
)
=
theme
::
test_theme_against
(
theme_file
,
&
path
e
s
);
let
(
success
,
differences
)
=
theme
::
test_theme_against
(
theme_file
,
&
paths
);
if
!
differences
.is_empty
()
||
!
success
{
eprintln!
(
" FAILED"
);
errors
+=
1
;
...
...
@@ -401,7 +401,7 @@ pub fn main_args(args: &[String]) -> isize {
let
mut
themes
=
Vec
::
new
();
if
matches
.opt_present
(
"themes"
)
{
let
path
es
=
theme
::
load_css_pathe
s
(
include_bytes!
(
"html/static/themes/main.css"
));
let
path
s
=
theme
::
load_css_path
s
(
include_bytes!
(
"html/static/themes/main.css"
));
for
(
theme_file
,
theme_s
)
in
matches
.opt_strs
(
"themes"
)
.iter
()
...
...
@@ -410,7 +410,7 @@ pub fn main_args(args: &[String]) -> isize {
eprintln!
(
"rustdoc: option --themes arguments must all be files"
);
return
1
;
}
let
(
success
,
ret
)
=
theme
::
test_theme_against
(
&
theme_file
,
&
path
e
s
);
let
(
success
,
ret
)
=
theme
::
test_theme_against
(
&
theme_file
,
&
paths
);
if
!
success
||
!
ret
.is_empty
()
{
eprintln!
(
"rustdoc: invalid theme:
\"
{}
\"
"
,
theme_s
);
eprintln!
(
" Check what's wrong with the
\"
theme-checker
\"
option"
);
...
...
src/librustdoc/theme.rs
浏览文件 @
51580d46
...
...
@@ -170,18 +170,24 @@ fn get_useful_next(events: &[Events], pos: &mut usize) -> Option<Events> {
fn
get_previous_positions
(
events
:
&
[
Events
],
mut
pos
:
usize
)
->
Vec
<
usize
>
{
let
mut
ret
=
Vec
::
with_capacity
(
3
);
ret
.push
(
events
[
pos
]
.get_pos
()
-
1
);
ret
.push
(
events
[
pos
]
.get_pos
());
if
pos
>
0
{
pos
-=
1
;
}
loop
{
ret
.push
(
events
[
pos
]
.get_pos
());
if
pos
<
1
||
!
events
[
pos
]
.is_comment
()
{
let
x
=
events
[
pos
]
.get_pos
();
if
*
ret
.last
()
.unwrap
()
!=
x
{
ret
.push
(
x
);
}
else
{
ret
.push
(
0
);
}
break
}
ret
.push
(
events
[
pos
]
.get_pos
());
pos
-=
1
;
}
if
events
[
pos
]
.is_comment
()
{
if
ret
.len
()
&
1
!=
0
&&
events
[
pos
]
.is_comment
()
{
ret
.push
(
0
);
}
ret
.iter
()
.rev
()
.cloned
()
.collect
()
...
...
@@ -189,14 +195,22 @@ fn get_previous_positions(events: &[Events], mut pos: usize) -> Vec<usize> {
fn
build_rule
(
v
:
&
[
u8
],
positions
:
&
[
usize
])
->
String
{
positions
.chunks
(
2
)
.map
(|
x
|
::
std
::
str
::
from_utf8
(
&
v
[
x
[
0
]
..
x
[
1
]])
.unwrap_or
(
""
)
.to_owned
()
)
.map
(|
x
|
::
std
::
str
::
from_utf8
(
&
v
[
x
[
0
]
..
x
[
1
]])
.unwrap_or
(
""
))
.collect
::
<
String
>
()
.trim
()
.replace
(
"
\n
"
,
" "
)
.replace
(
"/"
,
""
)
.replace
(
"
\t
"
,
" "
)
.replace
(
"{"
,
""
)
.replace
(
"}"
,
""
)
.split
(
" "
)
.filter
(|
s
|
s
.len
()
>
0
)
.collect
::
<
Vec
<&
str
>>
()
.join
(
" "
)
}
fn
inner
(
v
:
&
[
u8
],
events
:
&
[
Events
],
pos
:
&
mut
usize
)
->
HashSet
<
CssPath
>
{
let
mut
path
e
s
=
Vec
::
with_capacity
(
50
);
let
mut
paths
=
Vec
::
with_capacity
(
50
);
while
*
pos
<
events
.len
()
{
if
let
Some
(
Events
::
OutBlock
(
_
))
=
get_useful_next
(
events
,
pos
)
{
...
...
@@ -204,11 +218,11 @@ fn inner(v: &[u8], events: &[Events], pos: &mut usize) -> HashSet<CssPath> {
break
}
if
let
Some
(
Events
::
InBlock
(
_
))
=
get_useful_next
(
events
,
pos
)
{
path
e
s
.push
(
CssPath
::
new
(
build_rule
(
v
,
&
get_previous_positions
(
events
,
*
pos
))));
paths
.push
(
CssPath
::
new
(
build_rule
(
v
,
&
get_previous_positions
(
events
,
*
pos
))));
*
pos
+=
1
;
}
while
let
Some
(
Events
::
InBlock
(
_
))
=
get_useful_next
(
events
,
pos
)
{
if
let
Some
(
ref
mut
path
)
=
path
e
s
.last_mut
()
{
if
let
Some
(
ref
mut
path
)
=
paths
.last_mut
()
{
for
entry
in
inner
(
v
,
events
,
pos
)
.iter
()
{
path
.children
.insert
(
entry
.clone
());
}
...
...
@@ -218,10 +232,10 @@ fn inner(v: &[u8], events: &[Events], pos: &mut usize) -> HashSet<CssPath> {
*
pos
+=
1
;
}
}
path
e
s
.iter
()
.cloned
()
.collect
()
paths
.iter
()
.cloned
()
.collect
()
}
pub
fn
load_css_path
e
s
(
v
:
&
[
u8
])
->
CssPath
{
pub
fn
load_css_paths
(
v
:
&
[
u8
])
->
CssPath
{
let
events
=
load_css_events
(
v
);
let
mut
pos
=
0
;
...
...
@@ -264,9 +278,9 @@ pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath) -> (bool, Ve
let
mut
data
=
Vec
::
with_capacity
(
1000
);
try_something!
(
file
.read_to_end
(
&
mut
data
),
(
false
,
Vec
::
new
()));
let
path
es
=
load_css_pathe
s
(
&
data
);
let
path
s
=
load_css_path
s
(
&
data
);
let
mut
ret
=
Vec
::
new
();
get_differences
(
against
,
&
path
e
s
,
&
mut
ret
);
get_differences
(
against
,
&
paths
,
&
mut
ret
);
(
true
,
ret
)
}
...
...
@@ -317,8 +331,11 @@ fn test_comments_in_rules() {
rule j end {}
"#
;
assert
!
(
get_differences
(
&
load_css_pathes
(
against
.as_bytes
()),
&
load_css_pathes
(
text
.as_bytes
()))
.is_empty
());
let
mut
ret
=
Vec
::
new
();
get_differences
(
&
load_css_paths
(
against
.as_bytes
()),
&
load_css_paths
(
text
.as_bytes
()),
&
mut
ret
);
assert
!
(
ret
.is_empty
());
}
#[test]
...
...
@@ -330,8 +347,8 @@ fn test_text() {
c // sdf
d {}
"#
;
let
path
es
=
load_css_pathe
s
(
text
.as_bytes
());
assert
!
(
path
es
.children
.get
(
"a b c d"
)
.is_some
());
let
path
s
=
load_css_path
s
(
text
.as_bytes
());
assert
!
(
path
s
.children
.get
(
&
CssPath
::
new
(
"a b c d"
.to_owned
())
)
.is_some
());
}
#[test]
...
...
@@ -350,10 +367,13 @@ fn test_comparison() {
}
"#
;
let
against
=
load_css_path
e
s
(
y
.as_bytes
());
let
other
=
load_css_path
e
s
(
x
.as_bytes
());
let
against
=
load_css_paths
(
y
.as_bytes
());
let
other
=
load_css_paths
(
x
.as_bytes
());
assert
!
(
get_differences
(
&
against
,
&
other
)
.is_empty
());
assert_eq!
(
get_differences
(
&
other
,
&
against
),
vec!
[
" Missing
\"
c
\"
rule"
.to_owned
()])
let
mut
ret
=
Vec
::
new
();
get_differences
(
&
against
,
&
other
,
&
mut
ret
);
assert
!
(
ret
.is_empty
());
get_differences
(
&
other
,
&
against
,
&
mut
ret
);
assert_eq!
(
ret
,
vec!
[
" Missing
\"
c
\"
rule"
.to_owned
()]);
}
}
src/tools/rustdoc-themes/test-themes.py
0 → 100644
浏览文件 @
51580d46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2018 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
from
os
import
listdir
from
os.path
import
isfile
,
join
import
subprocess
import
sys
FILES_TO_IGNORE
=
[
'main.css'
]
THEME_DIR_PATH
=
"src/librustdoc/html/static/themes"
def
print_err
(
msg
):
sys
.
stderr
.
write
(
'{}
\n
'
.
format
(
msg
))
def
exec_command
(
command
):
child
=
subprocess
.
Popen
(
command
)
stdout
,
stderr
=
child
.
communicate
()
return
child
.
returncode
def
main
(
argv
):
if
len
(
argv
)
<
1
:
print_err
(
"Needs rustdoc binary path"
)
return
1
rustdoc_bin
=
argv
[
0
]
themes
=
[
join
(
THEME_DIR_PATH
,
f
)
for
f
in
listdir
(
THEME_DIR_PATH
)
if
isfile
(
join
(
THEME_DIR_PATH
,
f
))
and
f
not
in
FILES_TO_IGNORE
]
if
len
(
themes
)
<
1
:
print_err
(
'No theme found in "{}"...'
.
format
(
THEME_DIR_PATH
))
return
1
args
=
[
rustdoc_bin
,
'-Z'
,
'unstable-options'
,
'--theme-checker'
]
args
.
extend
(
themes
)
return
exec_command
(
args
)
if
__name__
!=
'__main__'
:
print_err
(
"Needs to be run as main"
)
sys
.
exit
(
1
)
else
:
sys
.
exit
(
main
(
sys
.
argv
[
1
:]))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录