Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d45f8770
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,发现更多精彩内容 >>
提交
d45f8770
编写于
9月 22, 2018
作者:
I
Igor Matuszewski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Emit only necessary compilation options in save-analysis
This is `command`, `directory` and `output` file.
上级
cddd00a1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
34 deletion
+47
-34
src/Cargo.lock
src/Cargo.lock
+1
-0
src/librustc_save_analysis/Cargo.toml
src/librustc_save_analysis/Cargo.toml
+1
-0
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/dump_visitor.rs
+19
-22
src/librustc_save_analysis/lib.rs
src/librustc_save_analysis/lib.rs
+26
-12
未找到文件。
src/Cargo.lock
浏览文件 @
d45f8770
...
...
@@ -2373,6 +2373,7 @@ dependencies = [
"rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_codegen_utils 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_target 0.0.0",
"rustc_typeck 0.0.0",
...
...
src/librustc_save_analysis/Cargo.toml
浏览文件 @
d45f8770
...
...
@@ -12,6 +12,7 @@ crate-type = ["dylib"]
log
=
"0.4"
rustc
=
{
path
=
"../librustc"
}
rustc_data_structures
=
{
path
=
"../librustc_data_structures"
}
rustc_codegen_utils
=
{
path
=
"../librustc_codegen_utils"
}
rustc_target
=
{
path
=
"../librustc_target"
}
rustc_typeck
=
{
path
=
"../librustc_typeck"
}
syntax
=
{
path
=
"../libsyntax"
}
...
...
src/librustc_save_analysis/dump_visitor.rs
浏览文件 @
d45f8770
...
...
@@ -28,8 +28,9 @@
use
rustc
::
ty
::{
self
,
TyCtxt
};
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
std
::
path
::
{
Path
,
PathBuf
}
;
use
std
::
path
::
Path
;
use
std
::
env
;
use
std
::
fs
;
use
syntax
::
ast
::{
self
,
Attribute
,
NodeId
,
PatKind
,
CRATE_NODE_ID
};
use
syntax
::
parse
::
token
;
...
...
@@ -172,11 +173,20 @@ pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
self
.dumper
.crate_prelude
(
data
);
}
pub
fn
dump_compilation_options
(
&
mut
self
)
{
// Apply possible `remap-path-prefix` remapping to the raw invocation
let
invocation
=
{
pub
fn
dump_compilation_options
(
&
mut
self
,
crate_name
:
&
str
)
{
// Apply possible `remap-path-prefix` remapping to the raw command
let
command
=
{
let
mapping
=
self
.tcx.sess
.source_map
()
.path_mapping
();
let
remap_arg
=
|
x
:
&
str
|
->
String
{
match
fs
::
canonicalize
(
x
)
{
Ok
(
path
)
=>
mapping
.map_prefix
(
path
)
.0
.to_str
()
.unwrap
()
.to_owned
(),
Err
(
_
)
=>
x
.to_owned
(),
// Probably not a path, ignore
}
};
let
remap_arg_indices
=
{
let
mut
indices
=
FxHashSet
();
// rustc args are guaranteed to be valid UTF-8 (checked early)
for
(
i
,
e
)
in
env
::
args
()
.enumerate
()
{
if
e
.starts_with
(
"--remap-path-prefix="
)
{
indices
.insert
(
i
);
...
...
@@ -188,19 +198,10 @@ pub fn dump_compilation_options(&mut self) {
indices
};
let
args
_without_remap_args
=
env
::
args
()
let
args
=
env
::
args
()
.enumerate
()
.filter
(|(
i
,
_
)|
!
remap_arg_indices
.contains
(
i
))
.map
(|(
_
,
e
)|
e
);
let
mapping
=
self
.tcx.sess
.source_map
()
.path_mapping
();
let
remap_arg
=
|
x
:
&
str
|
->
String
{
mapping
.map_prefix
(
PathBuf
::
from
(
x
))
.0
.to_str
()
.unwrap
()
.to_owned
()
};
// Naively attempt to remap every argument
let
args
=
args_without_remap_args
.map
(|
elem
|
{
.map
(|(
_
,
elem
)|
{
let
mut
arg
=
elem
.splitn
(
2
,
'='
);
match
(
arg
.next
(),
arg
.next
())
{
// Apart from `--remap...`, in `a=b` args usually only
...
...
@@ -214,14 +215,10 @@ pub fn dump_compilation_options(&mut self) {
args
.as_slice
()
.join
(
" "
)
};
let
opts
=
&
self
.tcx.sess.opts
;
let
data
=
CompilationOptions
{
invocation
,
crate_name
:
opts
.crate_name
.clone
(),
test
:
opts
.test
,
sysroot
:
opts
.maybe_sysroot
.clone
(),
target_triple
:
opts
.target_triple
.to_string
(),
directory
:
self
.tcx.sess.working_dir
.0
.clone
(),
command
,
output
:
self
.save_ctxt
.compilation_output
(
crate_name
),
};
self
.dumper
.compilation_opts
(
data
);
...
...
src/librustc_save_analysis/lib.rs
浏览文件 @
d45f8770
...
...
@@ -23,6 +23,7 @@
#[macro_use]
extern
crate
log
;
extern
crate
rustc_data_structures
;
extern
crate
rustc_codegen_utils
;
extern
crate
rustc_serialize
;
extern
crate
rustc_target
;
extern
crate
rustc_typeck
;
...
...
@@ -45,9 +46,10 @@
use
rustc
::
hir
::
Node
;
use
rustc
::
hir
::
def_id
::{
DefId
,
LOCAL_CRATE
};
use
rustc
::
middle
::
cstore
::
ExternCrate
;
use
rustc
::
session
::
config
::
CrateType
;
use
rustc
::
session
::
config
::
{
CrateType
,
OutputType
}
;
use
rustc
::
ty
::{
self
,
TyCtxt
};
use
rustc_typeck
::
hir_ty_to_ty
;
use
rustc_codegen_utils
::
link
::{
filename_for_metadata
,
out_filename
};
use
std
::
cell
::
Cell
;
use
std
::
default
::
Default
;
...
...
@@ -111,6 +113,24 @@ fn span_from_span(&self, span: Span) -> SpanData {
}
}
// Returns path to the compilation output (e.g. libfoo-12345678.rmeta)
pub
fn
compilation_output
(
&
self
,
crate_name
:
&
str
)
->
PathBuf
{
let
sess
=
&
self
.tcx.sess
;
// Save-analysis is emitted per whole session, not per each crate type
let
crate_type
=
sess
.crate_types
.borrow
()[
0
];
let
outputs
=
&*
self
.tcx
.output_filenames
(
LOCAL_CRATE
);
if
outputs
.outputs
.contains_key
(
&
OutputType
::
Metadata
)
{
filename_for_metadata
(
sess
,
crate_name
,
outputs
)
}
else
if
outputs
.outputs
.should_codegen
()
{
out_filename
(
sess
,
crate_type
,
outputs
,
crate_name
)
}
else
{
// Otherwise it's only a DepInfo, in which case we return early and
// not even reach the analysis stage.
unreachable!
()
}
}
// List external crates used by the current crate.
pub
fn
get_external_crates
(
&
self
)
->
Vec
<
ExternalCrateData
>
{
let
mut
result
=
Vec
::
with_capacity
(
self
.tcx
.crates
()
.len
());
...
...
@@ -139,15 +159,9 @@ pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
disambiguator
:
self
.tcx
.crate_disambiguator
(
n
)
.to_fingerprint
()
.as_value
(),
},
source
:
CrateSource
{
dylib
:
src
.dylib
.as_ref
()
.map
(|(
ref
path
,
_
)|
map_prefix
(
path
)
.display
()
.to_string
()
),
rlib
:
src
.rlib
.as_ref
()
.map
(|(
ref
path
,
_
)|
map_prefix
(
path
)
.display
()
.to_string
()
),
rmeta
:
src
.rmeta
.as_ref
()
.map
(|(
ref
path
,
_
)|
map_prefix
(
path
)
.display
()
.to_string
()
),
dylib
:
src
.dylib
.as_ref
()
.map
(|(
path
,
_
)|
map_prefix
(
path
)),
rlib
:
src
.rlib
.as_ref
()
.map
(|(
path
,
_
)|
map_prefix
(
path
)),
rmeta
:
src
.rmeta
.as_ref
()
.map
(|(
path
,
_
)|
map_prefix
(
path
)),
}
});
}
...
...
@@ -1103,7 +1117,7 @@ fn save<'l, 'tcx>(
let
mut
visitor
=
DumpVisitor
::
new
(
save_ctxt
,
&
mut
dumper
);
visitor
.dump_crate_info
(
cratename
,
krate
);
visitor
.dump_compilation_options
();
visitor
.dump_compilation_options
(
cratename
);
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
}
...
...
@@ -1129,7 +1143,7 @@ fn save<'l, 'tcx>(
let
mut
visitor
=
DumpVisitor
::
new
(
save_ctxt
,
&
mut
dumper
);
visitor
.dump_crate_info
(
cratename
,
krate
);
visitor
.dump_compilation_options
();
visitor
.dump_compilation_options
(
cratename
);
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录