Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5aa5220f
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,发现更多精彩内容 >>
提交
5aa5220f
编写于
4月 08, 2012
作者:
H
Haitao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Encode crate dependencies' hash and version data
上级
5300662b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
26 deletion
+57
-26
src/rustc/metadata/common.rs
src/rustc/metadata/common.rs
+4
-0
src/rustc/metadata/cstore.rs
src/rustc/metadata/cstore.rs
+1
-3
src/rustc/metadata/decoder.rs
src/rustc/metadata/decoder.rs
+21
-4
src/rustc/metadata/encoder.rs
src/rustc/metadata/encoder.rs
+31
-19
未找到文件。
src/rustc/metadata/common.rs
浏览文件 @
5aa5220f
...
...
@@ -64,6 +64,10 @@
const
tag_parent_item
:
uint
=
0x29u
;
const
tag_crate_dep_name
:
uint
=
0x2au
;
const
tag_crate_dep_hash
:
uint
=
0x2bu
;
const
tag_crate_dep_vers
:
uint
=
0x2cu
;
const
tag_mod_impl
:
uint
=
0x30u
;
const
tag_item_method
:
uint
=
0x31u
;
...
...
src/rustc/metadata/cstore.rs
浏览文件 @
5aa5220f
...
...
@@ -88,9 +88,7 @@ fn get_crate_hash(cstore: cstore, cnum: ast::crate_num) -> str {
fn
get_crate_vers
(
cstore
:
cstore
,
cnum
:
ast
::
crate_num
)
->
str
{
let
cdata
=
get_crate_data
(
cstore
,
cnum
);
let
attrs
=
decoder
::
get_crate_attributes
(
cdata
.data
);
ret
option
::
get
(
attr
::
meta_item_value_from_list
(
attr
::
find_linkage_metas
(
attrs
),
"vers"
));
ret
decoder
::
get_crate_vers
(
cdata
.data
);
}
fn
set_crate_data
(
cstore
:
cstore
,
cnum
:
ast
::
crate_num
,
...
...
src/rustc/metadata/decoder.rs
浏览文件 @
5aa5220f
...
...
@@ -33,6 +33,7 @@
export
crate_dep
;
export
get_crate_deps
;
export
get_crate_hash
;
export
get_crate_vers
;
export
get_impls_for_mod
;
export
get_iface_methods
;
export
get_crate_module_paths
;
...
...
@@ -579,16 +580,22 @@ fn get_crate_attributes(data: @[u8]) -> [ast::attribute] {
ret
get_attributes
(
ebml
::
doc
(
data
));
}
type
crate_dep
=
{
cnum
:
ast
::
crate_num
,
ident
:
str
};
type
crate_dep
=
{
cnum
:
ast
::
crate_num
,
name
:
ast
::
ident
,
vers
:
str
,
hash
:
str
};
fn
get_crate_deps
(
data
:
@
[
u8
])
->
[
crate_dep
]
{
let
mut
deps
:
[
crate_dep
]
=
[];
let
cratedoc
=
ebml
::
doc
(
data
);
let
depsdoc
=
ebml
::
get_doc
(
cratedoc
,
tag_crate_deps
);
let
mut
crate_num
=
1
;
fn
docstr
(
doc
:
ebml
::
doc
,
tag_
:
uint
)
->
str
{
str
::
from_bytes
(
ebml
::
doc_data
(
ebml
::
get_doc
(
doc
,
tag_
)))
}
ebml
::
tagged_docs
(
depsdoc
,
tag_crate_dep
)
{|
depdoc
|
let
depname
=
str
::
from_bytes
(
ebml
::
doc_data
(
depdoc
));
deps
+=
[{
cnum
:
crate_num
,
ident
:
depname
}];
deps
+=
[{
cnum
:
crate_num
,
name
:
docstr
(
depdoc
,
tag_crate_dep_name
),
vers
:
docstr
(
depdoc
,
tag_crate_dep_vers
),
hash
:
docstr
(
depdoc
,
tag_crate_dep_hash
)}];
crate_num
+=
1
;
};
ret
deps
;
...
...
@@ -598,7 +605,8 @@ fn list_crate_deps(data: @[u8], out: io::writer) {
out
.write_str
(
"=External Dependencies=
\n
"
);
for
get_crate_deps
(
data
)
.each
{|
dep
|
out
.write_str
(
#
fmt
[
"%d %s
\n
"
,
dep
.cnum
,
dep
.ident
]);
out
.write_str
(
#
fmt
[
"%d %s-%s-%s
\n
"
,
dep
.cnum
,
dep
.name
,
dep
.hash
,
dep
.vers
]);
}
out
.write_str
(
"
\n
"
);
...
...
@@ -610,6 +618,15 @@ fn get_crate_hash(data: @[u8]) -> str {
ret
str
::
from_bytes
(
ebml
::
doc_data
(
hashdoc
));
}
fn
get_crate_vers
(
data
:
@
[
u8
])
->
str
{
let
attrs
=
decoder
::
get_crate_attributes
(
data
);
ret
alt
attr
::
meta_item_value_from_list
(
attr
::
find_linkage_metas
(
attrs
),
"vers"
)
{
some
(
ver
)
{
ver
}
none
{
"0.0"
}
};
}
fn
list_crate_items
(
bytes
:
@
[
u8
],
md
:
ebml
::
doc
,
out
:
io
::
writer
)
{
out
.write_str
(
"=Items=
\n
"
);
let
items
=
ebml
::
get_doc
(
md
,
tag_items
);
...
...
src/rustc/metadata/encoder.rs
浏览文件 @
5aa5220f
...
...
@@ -907,47 +907,59 @@ fn synthesize_link_attr(ecx: @encode_ctxt, items: [@meta_item]) ->
fn
encode_crate_deps
(
ebml_w
:
ebml
::
writer
,
cstore
:
cstore
::
cstore
)
{
fn
get_ordered_
names
(
cstore
:
cstore
::
cstore
)
->
[
str
]
{
fn
get_ordered_
deps
(
cstore
:
cstore
::
cstore
)
->
[
decoder
::
crate_dep
]
{
type
hashkv
=
@
{
key
:
crate_num
,
val
:
cstore
::
crate_metadata
};
type
num
name
=
{
crate
:
crate_num
,
ident
:
str
}
;
type
num
dep
=
decoder
::
crate_dep
;
// Pull the cnums and name
s
out of cstore
let
mut
pairs
:
[
mut
numname
]
=
[
mut
];
// Pull the cnums and name
,vers,hash
out of cstore
let
mut
deps
:
[
mut
numdep
]
=
[
mut
];
cstore
::
iter_crate_data
(
cstore
)
{|
key
,
val
|
pairs
+=
[
mut
{
crate
:
key
,
ident
:
val
.name
}];
let
dep
=
{
cnum
:
key
,
name
:
val
.name
,
vers
:
decoder
::
get_crate_vers
(
val
.data
),
hash
:
decoder
::
get_crate_hash
(
val
.data
)};
deps
+=
[
mut
dep
];
};
// Sort by cnum
fn
lteq
(
kv1
:
num
name
,
kv2
:
numname
)
->
bool
{
kv1
.crate
<=
kv2
.crate
}
std
::
sort
::
quick_sort
(
lteq
,
pair
s
);
fn
lteq
(
kv1
:
num
dep
,
kv2
:
numdep
)
->
bool
{
kv1
.cnum
<=
kv2
.cnum
}
std
::
sort
::
quick_sort
(
lteq
,
dep
s
);
// Sanity-check the crate numbers
let
mut
expected_cnum
=
1
;
for
pair
s
.each
{|
n
|
assert
(
n
.c
rate
==
expected_cnum
);
for
dep
s
.each
{|
n
|
assert
(
n
.c
num
==
expected_cnum
);
expected_cnum
+=
1
;
}
// Return just the names
fn
name
(
kv
:
numname
)
->
str
{
kv
.ident
}
// mut -> immutable hack for vec::map
let
immpairs
=
vec
::
slice
(
pairs
,
0u
,
vec
::
len
(
pairs
));
ret
vec
::
map
(
immpairs
,
name
);
ret
vec
::
slice
(
deps
,
0u
,
vec
::
len
(
deps
));
}
// We're just going to write a list of crate
names, with the assumption
// that they are numbered 1 to n.
// We're just going to write a list of crate
'name-hash-version's, with
// th
e assumption th
at they are numbered 1 to n.
// FIXME: This is not nearly enough to support correct versioning
// but is enough to get transitive crate dependencies working.
ebml_w
.start_tag
(
tag_crate_deps
);
for
get_ordered_names
(
cstore
)
.each
{|
cname
|
ebml_w
.start_tag
(
tag_crate_dep
);
ebml_w
.writer
.write
(
str
::
bytes
(
cname
));
ebml_w
.end_tag
();
for
get_ordered_deps
(
cstore
)
.each
{|
dep
|
encode_crate_dep
(
ebml_w
,
dep
);
}
ebml_w
.end_tag
();
}
fn
encode_crate_dep
(
ebml_w
:
ebml
::
writer
,
dep
:
decoder
::
crate_dep
)
{
ebml_w
.start_tag
(
tag_crate_dep
);
ebml_w
.start_tag
(
tag_crate_dep_name
);
ebml_w
.writer
.write
(
str
::
bytes
(
dep
.name
));
ebml_w
.end_tag
();
ebml_w
.start_tag
(
tag_crate_dep_vers
);
ebml_w
.writer
.write
(
str
::
bytes
(
dep
.vers
));
ebml_w
.end_tag
();
ebml_w
.start_tag
(
tag_crate_dep_hash
);
ebml_w
.writer
.write
(
str
::
bytes
(
dep
.hash
));
ebml_w
.end_tag
();
ebml_w
.end_tag
();
}
fn
encode_hash
(
ebml_w
:
ebml
::
writer
,
hash
:
str
)
{
ebml_w
.start_tag
(
tag_crate_hash
);
ebml_w
.writer
.write
(
str
::
bytes
(
hash
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录