Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c01e4ce7
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,发现更多精彩内容 >>
提交
c01e4ce7
编写于
9月 11, 2018
作者:
I
Igor Matuszewski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Emit used rustc invocation in the save-analysis file
上级
88769068
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
101 addition
and
14 deletion
+101
-14
src/Cargo.toml
src/Cargo.toml
+1
-0
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/dump_visitor.rs
+61
-3
src/librustc_save_analysis/json_dumper.rs
src/librustc_save_analysis/json_dumper.rs
+8
-2
src/librustc_save_analysis/lib.rs
src/librustc_save_analysis/lib.rs
+23
-4
src/librustc_save_analysis/span_utils.rs
src/librustc_save_analysis/span_utils.rs
+8
-5
未找到文件。
src/Cargo.toml
浏览文件 @
c01e4ce7
...
...
@@ -57,6 +57,7 @@ cargo = { path = "tools/cargo" }
# that we're shipping as well (to ensure that the rustfmt in RLS and the
# `rustfmt` executable are the same exact version).
rustfmt-nightly
=
{
path
=
"tools/rustfmt"
}
rls-data
=
{
git
=
"https://github.com/Xanewok/rls-data"
,
branch
=
"compilation-options"
}
# See comments in `tools/rustc-workspace-hack/README.md` for what's going on
# here
...
...
src/librustc_save_analysis/dump_visitor.rs
浏览文件 @
c01e4ce7
...
...
@@ -28,7 +28,8 @@
use
rustc
::
ty
::{
self
,
TyCtxt
};
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
std
::
path
::
Path
;
use
std
::
path
::{
Path
,
PathBuf
};
use
std
::
env
;
use
syntax
::
ast
::{
self
,
Attribute
,
NodeId
,
PatKind
,
CRATE_NODE_ID
};
use
syntax
::
parse
::
token
;
...
...
@@ -49,8 +50,10 @@
use
span_utils
::
SpanUtils
;
use
sig
;
use
rls_data
::{
CratePreludeData
,
Def
,
DefKind
,
GlobalCrateId
,
Import
,
ImportKind
,
Ref
,
RefKind
,
Relation
,
RelationKind
,
SpanData
};
use
rls_data
::{
CompilationOptions
,
CratePreludeData
,
Def
,
DefKind
,
GlobalCrateId
,
Import
,
ImportKind
,
Ref
,
RefKind
,
Relation
,
RelationKind
,
SpanData
,
};
macro_rules!
down_cast_data
{
(
$id:ident
,
$kind:ident
,
$sp:expr
)
=>
{
...
...
@@ -169,6 +172,61 @@ 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
=
{
let
remap_arg_indices
=
{
let
mut
indices
=
FxHashSet
();
for
(
i
,
e
)
in
env
::
args
()
.enumerate
()
{
if
e
.starts_with
(
"--remap-path-prefix="
)
{
indices
.insert
(
i
);
}
else
if
e
==
"--remap-path-prefix"
{
indices
.insert
(
i
);
indices
.insert
(
i
+
1
);
}
}
indices
};
let
args_without_remap_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
|
{
let
mut
arg
=
elem
.splitn
(
2
,
'='
);
match
(
arg
.next
(),
arg
.next
())
{
// Apart from `--remap...`, in `a=b` args usually only
// `b` is a path (e.g. `--extern some_crate=/path/to..`)
(
Some
(
a
),
Some
(
b
))
=>
format!
(
"{}={}"
,
a
,
remap_arg
(
b
)),
(
Some
(
a
),
_
)
=>
remap_arg
(
a
),
_
=>
unreachable!
(),
}
})
.collect
::
<
Vec
<
_
>>
();
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
(),
};
self
.dumper
.compilation_opts
(
data
);
}
// Return all non-empty prefixes of a path.
// For each prefix, we return the span for the last segment in the prefix and
// a str representation of the entire prefix.
...
...
src/librustc_save_analysis/json_dumper.rs
浏览文件 @
c01e4ce7
...
...
@@ -12,9 +12,11 @@
use
rustc_serialize
::
json
::
as_json
;
use
rls_data
::{
self
,
Analysis
,
CratePreludeData
,
Def
,
DefKind
,
Import
,
MacroRef
,
Ref
,
RefKind
,
Relation
,
Impl
};
use
rls_data
::
config
::
Config
;
use
rls_data
::{
self
,
Analysis
,
CompilationOptions
,
CratePreludeData
,
Def
,
DefKind
,
Impl
,
Import
,
MacroRef
,
Ref
,
RefKind
,
Relation
,
};
use
rls_span
::{
Column
,
Row
};
#[derive(Debug)]
...
...
@@ -89,6 +91,10 @@ pub fn crate_prelude(&mut self, data: CratePreludeData) {
self
.result.prelude
=
Some
(
data
)
}
pub
fn
compilation_opts
(
&
mut
self
,
data
:
CompilationOptions
)
{
self
.result.compilation
=
Some
(
data
);
}
pub
fn
macro_use
(
&
mut
self
,
data
:
MacroRef
)
{
if
self
.config.pub_only
||
self
.config.reachable_only
{
return
;
...
...
src/librustc_save_analysis/lib.rs
浏览文件 @
c01e4ce7
...
...
@@ -70,10 +70,11 @@
use
dump_visitor
::
DumpVisitor
;
use
span_utils
::
SpanUtils
;
use
rls_data
::{
Def
,
DefKind
,
ExternalCrateData
,
GlobalCrateId
,
MacroRef
,
Ref
,
RefKind
,
Relation
,
RelationKind
,
SpanData
,
Impl
,
ImplKind
};
use
rls_data
::
config
::
Config
;
use
rls_data
::{
CrateSource
,
Def
,
DefKind
,
ExternalCrateData
,
GlobalCrateId
,
Impl
,
ImplKind
,
MacroRef
,
Ref
,
RefKind
,
Relation
,
RelationKind
,
SpanData
,
};
pub
struct
SaveContext
<
'l
,
'tcx
:
'l
>
{
tcx
:
TyCtxt
<
'l
,
'tcx
,
'tcx
>
,
...
...
@@ -122,16 +123,32 @@ pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
continue
;
}
};
let
src
=
self
.tcx
.used_crate_source
(
n
);
let
lo_loc
=
self
.span_utils.sess
.source_map
()
.lookup_char_pos
(
span
.lo
());
let
map_prefix
=
|
path
:
&
PathBuf
|
->
PathBuf
{
self
.tcx.sess
.source_map
()
.path_mapping
()
.map_prefix
(
path
.to_owned
())
.0
};
result
.push
(
ExternalCrateData
{
// FIXME: change file_name field to PathBuf in rls-data
// https://github.com/nrc/rls-data/issues/7
file_name
:
self
.span_utils
.make_
path_string
(
&
lo_loc
.file.nam
e
),
file_name
:
self
.span_utils
.make_
filename_string
(
&
lo_loc
.fil
e
),
num
:
n
.as_u32
(),
id
:
GlobalCrateId
{
name
:
self
.tcx
.crate_name
(
n
)
.to_string
(),
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
()
),
}
});
}
...
...
@@ -1086,6 +1103,7 @@ fn save<'l, 'tcx>(
let
mut
visitor
=
DumpVisitor
::
new
(
save_ctxt
,
&
mut
dumper
);
visitor
.dump_crate_info
(
cratename
,
krate
);
visitor
.dump_compilation_options
();
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
}
...
...
@@ -1111,6 +1129,7 @@ fn save<'l, 'tcx>(
let
mut
visitor
=
DumpVisitor
::
new
(
save_ctxt
,
&
mut
dumper
);
visitor
.dump_crate_info
(
cratename
,
krate
);
visitor
.dump_compilation_options
();
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
}
...
...
src/librustc_save_analysis/span_utils.rs
浏览文件 @
c01e4ce7
...
...
@@ -35,14 +35,17 @@ pub fn new(sess: &'a Session) -> SpanUtils<'a> {
}
}
pub
fn
make_
path_string
(
&
self
,
path
:
&
FileNam
e
)
->
String
{
match
*
path
{
FileName
::
Real
(
ref
path
)
if
!
path
.is_absolute
()
=>
pub
fn
make_
filename_string
(
&
self
,
file
:
&
SourceFil
e
)
->
String
{
match
&
file
.name
{
FileName
::
Real
(
path
)
if
!
path
.is_absolute
()
&&
!
file
.name_was_remapped
=>
{
self
.sess.working_dir
.0
.join
(
&
path
)
.display
()
.to_string
(),
_
=>
path
.to_string
(),
.to_string
()
},
// If the file name is already remapped, we assume the user
// configured it the way they wanted to, so use that directly
filename
=>
filename
.to_string
()
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录