Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
38f0b90e
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
38f0b90e
编写于
6月 21, 2019
作者:
M
Mark Rousskov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move file-reading into walker loop
上级
c113a376
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
36 addition
and
67 deletion
+36
-67
src/tools/tidy/src/bins.rs
src/tools/tidy/src/bins.rs
+2
-2
src/tools/tidy/src/errors.rs
src/tools/tidy/src/errors.rs
+1
-7
src/tools/tidy/src/features.rs
src/tools/tidy/src/features.rs
+3
-13
src/tools/tidy/src/lib.rs
src/tools/tidy/src/lib.rs
+13
-6
src/tools/tidy/src/libcoretest.rs
src/tools/tidy/src/libcoretest.rs
+8
-16
src/tools/tidy/src/pal.rs
src/tools/tidy/src/pal.rs
+3
-9
src/tools/tidy/src/style.rs
src/tools/tidy/src/style.rs
+2
-8
src/tools/tidy/src/ui_tests.rs
src/tools/tidy/src/ui_tests.rs
+4
-6
未找到文件。
src/tools/tidy/src/bins.rs
浏览文件 @
38f0b90e
...
...
@@ -25,9 +25,9 @@ pub fn check(path: &Path, bad: &mut bool) {
}
}
super
::
walk
(
path
,
super
::
walk
_no_read
(
path
,
&
mut
|
path
|
super
::
filter_dirs
(
path
)
||
path
.ends_with
(
"src/etc"
),
&
mut
|
entry
,
_
contents
|
{
&
mut
|
entry
|
{
let
file
=
entry
.path
();
let
filename
=
file
.file_name
()
.unwrap
()
.to_string_lossy
();
let
extensions
=
[
".py"
,
".sh"
];
...
...
src/tools/tidy/src/errors.rs
浏览文件 @
38f0b90e
...
...
@@ -4,25 +4,19 @@
//! statistics about the error codes.
use
std
::
collections
::
HashMap
;
use
std
::
fs
::
File
;
use
std
::
io
::
prelude
::
*
;
use
std
::
path
::
Path
;
pub
fn
check
(
path
:
&
Path
,
bad
:
&
mut
bool
)
{
let
mut
contents
=
String
::
new
();
let
mut
map
:
HashMap
<
_
,
Vec
<
_
>>
=
HashMap
::
new
();
super
::
walk
(
path
,
&
mut
|
path
|
super
::
filter_dirs
(
path
)
||
path
.ends_with
(
"src/test"
),
&
mut
|
entry
,
_
contents
|
{
&
mut
|
entry
,
contents
|
{
let
file
=
entry
.path
();
let
filename
=
file
.file_name
()
.unwrap
()
.to_string_lossy
();
if
filename
!=
"error_codes.rs"
{
return
}
contents
.truncate
(
0
);
t!
(
t!
(
File
::
open
(
file
))
.read_to_string
(
&
mut
contents
));
// In the `register_long_diagnostics!` macro, entries look like this:
//
// ```
...
...
src/tools/tidy/src/features.rs
浏览文件 @
38f0b90e
...
...
@@ -11,8 +11,7 @@
use
std
::
collections
::
HashMap
;
use
std
::
fmt
;
use
std
::
fs
::{
self
,
File
};
use
std
::
io
::
prelude
::
*
;
use
std
::
fs
;
use
std
::
path
::
Path
;
use
regex
::
Regex
;
...
...
@@ -58,13 +57,11 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
let
lib_features
=
get_and_check_lib_features
(
path
,
bad
,
&
features
);
assert
!
(
!
lib_features
.is_empty
());
let
mut
contents
=
String
::
new
();
super
::
walk_many
(
&
[
&
path
.join
(
"test/ui"
),
&
path
.join
(
"test/ui-fulldeps"
),
&
path
.join
(
"test/compile-fail"
)],
&
mut
|
path
|
super
::
filter_dirs
(
path
),
&
mut
|
entry
,
_
contents
|
{
&
mut
|
entry
,
contents
|
{
let
file
=
entry
.path
();
let
filename
=
file
.file_name
()
.unwrap
()
.to_string_lossy
();
if
!
filename
.ends_with
(
".rs"
)
||
filename
==
"features.rs"
||
...
...
@@ -75,9 +72,6 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
let
filen_underscore
=
filename
.replace
(
'-'
,
"_"
)
.replace
(
".rs"
,
""
);
let
filename_is_gate_test
=
test_filen_gate
(
&
filen_underscore
,
&
mut
features
);
contents
.truncate
(
0
);
t!
(
t!
(
File
::
open
(
&
file
),
&
file
)
.read_to_string
(
&
mut
contents
));
for
(
i
,
line
)
in
contents
.lines
()
.enumerate
()
{
let
mut
err
=
|
msg
:
&
str
|
{
tidy_error!
(
bad
,
"{}:{}: {}"
,
file
.display
(),
i
+
1
,
msg
);
...
...
@@ -369,10 +363,9 @@ fn get_and_check_lib_features(base_src_path: &Path,
fn
map_lib_features
(
base_src_path
:
&
Path
,
mf
:
&
mut
dyn
FnMut
(
Result
<
(
&
str
,
Feature
),
&
str
>
,
&
Path
,
usize
))
{
let
mut
contents
=
String
::
new
();
super
::
walk
(
base_src_path
,
&
mut
|
path
|
super
::
filter_dirs
(
path
)
||
path
.ends_with
(
"src/test"
),
&
mut
|
entry
,
_
contents
|
{
&
mut
|
entry
,
contents
|
{
let
file
=
entry
.path
();
let
filename
=
file
.file_name
()
.unwrap
()
.to_string_lossy
();
if
!
filename
.ends_with
(
".rs"
)
||
filename
==
"features.rs"
||
...
...
@@ -380,9 +373,6 @@ fn map_lib_features(base_src_path: &Path,
return
;
}
contents
.truncate
(
0
);
t!
(
t!
(
File
::
open
(
&
file
),
&
file
)
.read_to_string
(
&
mut
contents
));
let
mut
becoming_feature
:
Option
<
(
String
,
Feature
)
>
=
None
;
for
(
i
,
line
)
in
contents
.lines
()
.enumerate
()
{
macro_rules!
err
{
...
...
src/tools/tidy/src/lib.rs
浏览文件 @
38f0b90e
...
...
@@ -67,6 +67,7 @@ fn filter_dirs(path: &Path) -> bool {
skip
.iter
()
.any
(|
p
|
path
.ends_with
(
p
))
}
fn
walk_many
(
paths
:
&
[
&
Path
],
skip
:
&
mut
dyn
FnMut
(
&
Path
)
->
bool
,
f
:
&
mut
dyn
FnMut
(
&
DirEntry
,
&
str
)
)
{
...
...
@@ -76,19 +77,25 @@ fn walk_many(
}
fn
walk
(
path
:
&
Path
,
skip
:
&
mut
dyn
FnMut
(
&
Path
)
->
bool
,
f
:
&
mut
dyn
FnMut
(
&
DirEntry
,
&
str
))
{
let
mut
contents
=
String
::
new
();
walk_no_read
(
path
,
skip
,
&
mut
|
entry
|
{
contents
.clear
();
if
t!
(
File
::
open
(
entry
.path
()),
entry
.path
())
.read_to_string
(
&
mut
contents
)
.is_err
()
{
contents
.clear
();
}
f
(
&
entry
,
&
contents
);
});
}
fn
walk_no_read
(
path
:
&
Path
,
skip
:
&
mut
dyn
FnMut
(
&
Path
)
->
bool
,
f
:
&
mut
dyn
FnMut
(
&
DirEntry
))
{
let
walker
=
WalkDir
::
new
(
path
)
.into_iter
()
.filter_entry
(|
e
|
!
skip
(
e
.path
()));
let
mut
contents
=
String
::
new
();
for
entry
in
walker
{
if
let
Ok
(
entry
)
=
entry
{
if
entry
.file_type
()
.is_dir
()
{
continue
;
}
contents
.clear
();
if
t!
(
File
::
open
(
entry
.path
()),
entry
.path
())
.read_to_string
(
&
mut
contents
)
.is_err
()
{
contents
.clear
();
}
f
(
&
entry
,
&
contents
);
f
(
&
entry
);
}
}
}
src/tools/tidy/src/libcoretest.rs
浏览文件 @
38f0b90e
...
...
@@ -4,30 +4,22 @@
//! item. All tests must be written externally in `libcore/tests`.
use
std
::
path
::
Path
;
use
std
::
fs
::
read_to_string
;
pub
fn
check
(
path
:
&
Path
,
bad
:
&
mut
bool
)
{
let
libcore_path
=
path
.join
(
"libcore"
);
super
::
walk
(
&
libcore_path
,
&
mut
|
subpath
|
t!
(
subpath
.strip_prefix
(
&
libcore_path
))
.starts_with
(
"tests"
),
&
mut
|
entry
,
_
contents
|
{
&
mut
|
entry
,
contents
|
{
let
subpath
=
entry
.path
();
if
let
Some
(
"rs"
)
=
subpath
.extension
()
.and_then
(|
e
|
e
.to_str
())
{
match
read_to_string
(
subpath
)
{
Ok
(
contents
)
=>
{
if
contents
.contains
(
"#[test]"
)
{
tidy_error!
(
bad
,
"{} contains #[test]; libcore tests must be placed inside
\
`src/libcore/tests/`"
,
subpath
.display
()
);
}
}
Err
(
err
)
=>
{
panic!
(
"failed to read file {:?}: {}"
,
subpath
,
err
);
}
if
contents
.contains
(
"#[test]"
)
{
tidy_error!
(
bad
,
"{} contains #[test]; libcore tests must be placed inside
\
`src/libcore/tests/`"
,
subpath
.display
()
);
}
}
},
...
...
src/tools/tidy/src/pal.rs
浏览文件 @
38f0b90e
...
...
@@ -31,8 +31,6 @@
//! platform-specific cfgs are allowed. Not sure yet how to deal with
//! this in the long term.
use
std
::
fs
::
File
;
use
std
::
io
::
Read
;
use
std
::
path
::
Path
;
use
std
::
iter
::
Iterator
;
...
...
@@ -87,11 +85,10 @@
];
pub
fn
check
(
path
:
&
Path
,
bad
:
&
mut
bool
)
{
let
mut
contents
=
String
::
new
();
// Sanity check that the complex parsing here works.
let
mut
saw_target_arch
=
false
;
let
mut
saw_cfg_bang
=
false
;
super
::
walk
(
path
,
&
mut
super
::
filter_dirs
,
&
mut
|
entry
,
_
contents
|
{
super
::
walk
(
path
,
&
mut
super
::
filter_dirs
,
&
mut
|
entry
,
contents
|
{
let
file
=
entry
.path
();
let
filestr
=
file
.to_string_lossy
()
.replace
(
"
\\
"
,
"/"
);
if
!
filestr
.ends_with
(
".rs"
)
{
return
}
...
...
@@ -99,18 +96,15 @@ pub fn check(path: &Path, bad: &mut bool) {
let
is_exception_path
=
EXCEPTION_PATHS
.iter
()
.any
(|
s
|
filestr
.contains
(
&**
s
));
if
is_exception_path
{
return
}
check_cfgs
(
&
mut
contents
,
&
file
,
bad
,
&
mut
saw_target_arch
,
&
mut
saw_cfg_bang
);
check_cfgs
(
contents
,
&
file
,
bad
,
&
mut
saw_target_arch
,
&
mut
saw_cfg_bang
);
});
assert
!
(
saw_target_arch
);
assert
!
(
saw_cfg_bang
);
}
fn
check_cfgs
(
contents
:
&
mut
String
,
file
:
&
Path
,
fn
check_cfgs
(
contents
:
&
str
,
file
:
&
Path
,
bad
:
&
mut
bool
,
saw_target_arch
:
&
mut
bool
,
saw_cfg_bang
:
&
mut
bool
)
{
contents
.truncate
(
0
);
t!
(
t!
(
File
::
open
(
file
),
file
)
.read_to_string
(
contents
));
// For now it's ok to have platform-specific code after 'mod tests'.
let
mod_tests_idx
=
find_test_mod
(
contents
);
let
contents
=
&
contents
[
..
mod_tests_idx
];
...
...
src/tools/tidy/src/style.rs
浏览文件 @
38f0b90e
...
...
@@ -13,8 +13,6 @@
//! A number of these checks can be opted-out of with various directives of the form:
//! `// ignore-tidy-CHECK-NAME`.
use
std
::
fs
::
File
;
use
std
::
io
::
prelude
::
*
;
use
std
::
path
::
Path
;
const
COLS
:
usize
=
100
;
...
...
@@ -109,7 +107,7 @@ enum Directive {
Ignore
(
bool
),
}
fn
contains_ignore_directive
(
contents
:
&
String
,
check
:
&
str
)
->
Directive
{
fn
contains_ignore_directive
(
contents
:
&
str
,
check
:
&
str
)
->
Directive
{
if
contents
.contains
(
&
format!
(
"// ignore-tidy-{}"
,
check
))
||
contents
.contains
(
&
format!
(
"# ignore-tidy-{}"
,
check
))
{
Directive
::
Ignore
(
false
)
...
...
@@ -129,8 +127,7 @@ fn contains_ignore_directive(contents: &String, check: &str) -> Directive {
}
pub
fn
check
(
path
:
&
Path
,
bad
:
&
mut
bool
)
{
let
mut
contents
=
String
::
new
();
super
::
walk
(
path
,
&
mut
super
::
filter_dirs
,
&
mut
|
entry
,
_
contents
|
{
super
::
walk
(
path
,
&
mut
super
::
filter_dirs
,
&
mut
|
entry
,
contents
|
{
let
file
=
entry
.path
();
let
filename
=
file
.file_name
()
.unwrap
()
.to_string_lossy
();
let
extensions
=
[
".rs"
,
".py"
,
".js"
,
".sh"
,
".c"
,
".cpp"
,
".h"
];
...
...
@@ -139,9 +136,6 @@ pub fn check(path: &Path, bad: &mut bool) {
return
}
contents
.truncate
(
0
);
t!
(
t!
(
File
::
open
(
file
),
file
)
.read_to_string
(
&
mut
contents
));
if
contents
.is_empty
()
{
tidy_error!
(
bad
,
"{}: empty file"
,
file
.display
());
}
...
...
src/tools/tidy/src/ui_tests.rs
浏览文件 @
38f0b90e
...
...
@@ -4,10 +4,8 @@
use
std
::
path
::
Path
;
pub
fn
check
(
path
:
&
Path
,
bad
:
&
mut
bool
)
{
super
::
walk_many
(
&
[
&
path
.join
(
"test/ui"
),
&
path
.join
(
"test/ui-fulldeps"
)],
&
mut
|
_
|
false
,
&
mut
|
entry
,
_
contents
|
{
for
path
in
&
[
&
path
.join
(
"test/ui"
),
&
path
.join
(
"test/ui-fulldeps"
)]
{
super
::
walk_no_read
(
path
,
&
mut
|
_
|
false
,
&
mut
|
entry
|
{
let
file_path
=
entry
.path
();
if
let
Some
(
ext
)
=
file_path
.extension
()
{
if
ext
==
"stderr"
||
ext
==
"stdout"
{
...
...
@@ -46,6 +44,6 @@ pub fn check(path: &Path, bad: &mut bool) {
}
}
}
}
,
);
}
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录