Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
726fc877
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,发现更多精彩内容 >>
提交
726fc877
编写于
2月 18, 2013
作者:
M
Marvin Löbel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added rust convenience tool similar to go's go tool
上级
a6945f2a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
302 addition
and
3 deletion
+302
-3
Makefile.in
Makefile.in
+7
-1
mk/clean.mk
mk/clean.mk
+3
-0
mk/dist.mk
mk/dist.mk
+1
-0
mk/install.mk
mk/install.mk
+8
-0
mk/pp.mk
mk/pp.mk
+2
-1
mk/tests.mk
mk/tests.mk
+7
-1
mk/tools.mk
mk/tools.mk
+36
-0
src/driver/driver.rs
src/driver/driver.rs
+3
-0
src/librust/rust.rc
src/librust/rust.rc
+235
-0
未找到文件。
Makefile.in
浏览文件 @
726fc877
...
...
@@ -134,6 +134,7 @@ CFG_LIBFUZZER :=$(call CFG_LIB_NAME,fuzzer)
CFG_LIBRUSTPKG
:=
$(
call
CFG_LIB_NAME,rustpkg
)
CFG_LIBRUSTDOC
:=
$(
call
CFG_LIB_NAME,rustdoc
)
CFG_LIBRUSTI
:=
$(
call
CFG_LIB_NAME,rusti
)
CFG_LIBRUST
:=
$(
call
CFG_LIB_NAME,rust
)
STDLIB_GLOB
:=
$(
call
CFG_LIB_GLOB,std
)
CORELIB_GLOB
:=
$(
call
CFG_LIB_GLOB,core
)
...
...
@@ -143,6 +144,7 @@ LIBFUZZER_GLOB :=$(call CFG_LIB_GLOB,fuzzer)
LIBRUSTPKG_GLOB
:=
$(
call
CFG_LIB_GLOB,rustpkg
)
LIBRUSTDOC_GLOB
:=
$(
call
CFG_LIB_GLOB,rustdoc
)
LIBRUSTI_GLOB
:=
$(
call
CFG_LIB_GLOB,rusti
)
LIBRUST_GLOB
:=
$(
call
CFG_LIB_GLOB,rust
)
STDLIB_DSYM_GLOB
:=
$(
call
CFG_LIB_DSYM_GLOB,std
)
CORELIB_DSYM_GLOB
:=
$(
call
CFG_LIB_DSYM_GLOB,core
)
LIBRUSTC_DSYM_GLOB
:=
$(
call
CFG_LIB_DSYM_GLOB,rustc
)
...
...
@@ -151,6 +153,7 @@ LIBFUZZER_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,fuzzer)
LIBRUSTPKG_DSYM_GLOB
:=
$(
call
CFG_LIB_DSYM_GLOB,rustpkg
)
LIBRUSTDOC_DSYM_GLOB
:=
$(
call
CFG_LIB_DSYM_GLOB,rustdoc
)
LIBRUSTI_DSYM_GLOB
:=
$(
call
CFG_LIB_DSYM_GLOB,rusti
)
LIBRUST_DSYM_GLOB
:=
$(
call
CFG_LIB_DSYM_GLOB,rust
)
# version-string calculation
CFG_GIT_DIR
:=
$(CFG_SRC_DIR)
.git
...
...
@@ -374,10 +377,12 @@ CSREQ$(1)_T_$(2)_H_$(3) = \
$$
(
HBIN
$(1)
_H_
$(3)
)
/rustpkg
$
$(X)
\
$$
(
HBIN
$(1)
_H_
$(3)
)
/rustdoc
$
$(X)
\
$$
(
HBIN
$(1)
_H_
$(3)
)
/rusti
$
$(X)
\
$$
(
HBIN
$(1)
_H_
$(3)
)
/rust
$
$(X)
\
$$
(
HLIB
$(1)
_H_
$(3)
)
/
$
$(CFG_L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 +27,7 @@ PKG_FILES := \
driver
\
librustpkg
\
librusti
\
librust
\
librustc
\
compiletest
\
etc
\
...
...
mk/install.mk
浏览文件 @
726fc877
...
...
@@ -60,6 +60,8 @@ install-target-$(1)-host-$(2): $$(CSREQ$$(ISTAGE)_T_$(1)_H_$(2))
$$
(
TL
$(1)$(2)
)
,
$$
(
PTL
$(1)$(2)
)
,
$
$(LIBRUSTDOC_GLOB)
)
$
$(Q)
$
$(
call
INSTALL_LIB,
\
$$
(
TL
$(1)$(2)
)
,
$$
(
PTL
$(1)$(2)
)
,
$
$(LIBRUSTI_GLOB)
)
$
$(Q)
$
$(
call
INSTALL_LIB,
\
$$
(
TL
$(1)$(2)
)
,
$$
(
PTL
$(1)$(2)
)
,
$
$(LIBRUST_GLOB)
)
$
$(Q)
$
$(
call
INSTALL,
$$
(
TL
$(1)$(2)
)
,
$$
(
PTL
$(1)$(2)
)
,libmorestack.a
)
endef
...
...
@@ -90,15 +92,18 @@ install-host: $(CSREQ$(ISTAGE)_T_$(CFG_HOST_TRIPLE)_H_$(CFG_HOST_TRIPLE))
$(Q)
$(
call
INSTALL,
$(HB2)
,
$(PHB)
,rustpkg
$(X)
)
$(Q)
$(
call
INSTALL,
$(HB2)
,
$(PHB)
,rustdoc
$(X)
)
$(Q)
$(
call
INSTALL,
$(HB2)
,
$(PHB)
,rusti
$(X)
)
$(Q)
$(
call
INSTALL,
$(HB2)
,
$(PHB)
,rust
$(X)
)
$(Q)
$(
call
INSTALL,
$(HL)
,
$(PHL)
,
$(CFG_LIBRUSTC)
)
$(Q)
$(
call
INSTALL,
$(HL)
,
$(PHL)
,
$(CFG_LIBRUSTPKG)
)
$(Q)
$(
call
INSTALL,
$(HL)
,
$(PHL)
,
$(CFG_LIBRUSTDOC)
)
$(Q)
$(
call
INSTALL,
$(HL)
,
$(PHL)
,
$(CFG_LIBRUSTI)
)
$(Q)
$(
call
INSTALL,
$(HL)
,
$(PHL)
,
$(CFG_LIBRUST)
)
$(Q)
$(
call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)
)
\
$(
call
HOST_LIB_FROM_HL_GLOB,
$(LIBRUSTDOC_GLOB)
)
\
$(
call
HOST_LIB_FROM_HL_GLOB,
$(LIBRUSTI_GLOB)
)
\
$(
call
HOST_LIB_FROM_HL_GLOB,
$(LIBRUST_GLOB)
)
\
;
\
do
rm
-f
$$
i
;
\
done
...
...
mk/pp.mk
浏览文件 @
726fc877
...
...
@@ -19,7 +19,8 @@ else
$(S)
src/test/
*
/
*
/
*
.rs
)
\
$(
wildcard
$(S)
src/fuzzer/
*
.rs
)
\
$(
wildcard
$(S)
src/rustpkg/
*
.rs
)
\
$(
wildcard
$(S)
src/rusti/
*
.rs
)
$(
wildcard
$(S)
src/rusti/
*
.rs
)
\
$(
wildcard
$(S)
src/rust/
*
.rs
)
PP_INPUTS_FILTERED
=
$(
shell
echo
$(PP_INPUTS)
| xargs
grep
-L
\
"no-reformat
\|
xfail-pretty
\|
xfail-test"
)
...
...
mk/tests.mk
浏览文件 @
726fc877
...
...
@@ -14,7 +14,7 @@
######################################################################
# The names of crates that must be tested
TEST_CRATES
=
core std syntax rustc rustdoc rusti rustpkg
TEST_CRATES
=
core std syntax rustc rustdoc rusti rust
rust
pkg
# Markdown files under doc/ that should have their code extracted and run
DOC_TEST_NAMES
=
tutorial tutorial-ffi tutorial-macros tutorial-borrowed-ptr tutorial-tasks rust
...
...
@@ -241,6 +241,12 @@ $(3)/test/rustitest.stage$(1)-$(2)$$(X): \
@
$
$(
call
E, compile_and_link:
$$
@
)
$$
(
STAGE
$(1)
_T_
$(2)
_H_
$(3)
)
-o
$$
@
$$
<
--test
$(3)/test/rusttest.stage$(1)-$(2)$$(X)
:
\
$$(RUST_LIB) $$(RUST_INPUTS)
\
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
@
$
$(
call
E, compile_and_link:
$$
@
)
$$
(
STAGE
$(1)
_T_
$(2)
_H_
$(3)
)
-o
$$
@
$$
<
--test
$(3)/test/rustdoctest.stage$(1)-$(2)$$(X)
:
\
$$(RUSTDOC_LIB) $$(RUSTDOC_INPUTS)
\
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
...
...
mk/tools.mk
浏览文件 @
726fc877
...
...
@@ -30,6 +30,10 @@ RUSTDOC_INPUTS := $(wildcard $(S)src/librustdoc/*.rs)
RUSTI_LIB
:=
$(S)
src/librusti/rusti.rc
RUSTI_INPUTS
:=
$(
wildcard
$(S)
src/librusti/
*
.rs
)
# Rust, the convenience tool
RUST_LIB
:=
$(S)
src/librust/rust.rc
RUST_INPUTS
:=
$(
wildcard
$(S)
src/librust/
*
.rs
)
# FIXME: These are only built for the host arch. Eventually we'll
# have tools that need to built for other targets.
define
TOOLS_STAGE_N_TARGET
...
...
@@ -102,6 +106,21 @@ $$(TBIN$(1)_T_$(4)_H_$(3))/rusti$$(X): \
@
$
$(
call
E, compile_and_link:
$$
@
)
$$
(
STAGE
$(1)
_T_
$(4)
_H_
$(3)
)
--cfg
rusti
-o
$$
@
$$
<
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUST)
:
\
$$(RUST_LIB) $$(RUST_INPUTS)
\
$$(TSREQ$(1)_T_$(4)_H_$(3))
\
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_CORELIB)
\
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB)
\
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUSTC)
@
$
$(
call
E, compile_and_link:
$$
@
)
$$
(
STAGE
$(1)
_T_
$(4)
_H_
$(3)
)
-o
$$
@
$$
<
&&
touch
$$
@
$$(TBIN$(1)_T_$(4)_H_$(3))/rust$$(X)
:
\
$$(DRIVER_CRATE)
\
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUST)
@
$
$(
call
E, compile_and_link:
$$
@
)
$$
(
STAGE
$(1)
_T_
$(4)
_H_
$(3)
)
--cfg
rust
-o
$$
@
$$
<
endef
define
TOOLS_STAGE_N_HOST
...
...
@@ -185,6 +204,23 @@ $$(HBIN$(2)_H_$(4))/rusti$$(X): \
@
$
$(
call
E,
cp
:
$$
@
)
$
$(Q)
cp
$$
<
$$
@
$$(HLIB$(2)_H_$(4))/$$(CFG_LIBRUST)
:
\
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_LIBRUST)
\
$$(HLIB$(2)_H_$(4))/$$(CFG_LIBRUSTC)
\
$$(HSREQ$(2)_H_$(4))
@
$
$(
call
E,
cp
:
$$
@
)
$
$(Q)
cp
$$
<
$$
@
$
$(Q)
cp
-R
$$
(
TLIB
$(1)
_T_
$(4)
_H_
$(3)
)
/
$(LIBRUST_GLOB)
\
$
$(
wildcard
$$
(
TLIB
$(1)
_T_
$(4)
_H_
$(3)
)
/
$(LIBRUST_DSYM_GLOB)
)
\
$$
(
HLIB
$(2)
_H_
$(4)
)
$$(HBIN$(2)_H_$(4))/rust$$(X)
:
\
$$(TBIN$(1)_T_$(4)_H_$(3))/rust$$(X)
\
$$(HLIB$(2)_H_$(4))/$$(CFG_LIBRUST)
\
$$(HSREQ$(2)_H_$(4))
@
$
$(
call
E,
cp
:
$$
@
)
$
$(Q)
cp
$$
<
$$
@
endef
$(foreach
host,$(CFG_TARGET_TRIPLES),
\
...
...
src/driver/driver.rs
浏览文件 @
726fc877
...
...
@@ -23,6 +23,9 @@
#[cfg(rusti)]
extern
mod
this
(
name
=
"rusti"
,
vers
=
"0.6"
);
#[cfg(rust)]
extern
mod
this
(
name
=
"rust"
,
vers
=
"0.6"
);
#[cfg(rustc)]
extern
mod
this
(
name
=
"rustc"
,
vers
=
"0.6"
);
...
...
src/librust/rust.rc
0 → 100644
浏览文件 @
726fc877
// Copyright 2013 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.
// rust - central access to other rust tools
// XXX: Make commands run and test emit proper file endings on winds
// XXX: Make run only accept source that emits an executable
#[link(name = "rust",
vers = "0.6",
uuid = "4a24da33-5cc8-4037-9352-2cbe9bd9d27c",
url = "https://github.com/mozilla/rust/tree/master/src/rust")];
#[crate_type = "lib"];
extern mod core(vers = "0.6");
use core::run;
enum ValidUsage {
Valid, Invalid
}
impl ValidUsage {
fn is_valid(&self) -> bool { match *self {
Valid => true,
Invalid => false
}}
}
enum Action {
Exec(&str),
Call(&fn(args: &[~str]) -> ValidUsage)
}
enum UsageSource {
UsgExec(&str),
UsgStr(&str)
}
struct Command {
cmd: &str,
action: Action,
usage_line: &str,
usage_full: UsageSource
}
const commands: &[Command] = &[
Command{
cmd: "build",
action: Exec("rustc"),
usage_line: "compile rust source files",
usage_full: UsgExec("rustc --help")
},
Command{
cmd: "run",
action: Call(cmd_run),
usage_line: "build a executable, and run it",
usage_full: UsgStr(
"The run command is an shortcut for the command line \n\
\"rustc <filename> -o <filestem>~ && ./<filestem>~\".\
\n\nUsage:\trust run <filename>"
)
},
Command{
cmd: "test",
action: Call(cmd_test),
usage_line: "build a test executable, and run it",
usage_full: UsgStr(
"The test command is an shortcut for the command line \n\
\"rustc --test <filename> -o <filestem>test~ && \
./<filestem>test~\"\n\nUsage:\trust test <filename>"
)
},
Command{
cmd: "doc",
action: Exec("rustdoc"),
usage_line: "generate documentation from doc comments",
usage_full: UsgExec("rustdoc --help")
},
Command{
cmd: "pkg",
action: Exec("rustpkg"),
usage_line: "download, build, install rust packages",
usage_full: UsgExec("rustpkg --help")
},
Command{
cmd: "sketch",
action: Exec("rusti"),
usage_line: "run a rust interpreter",
usage_full: UsgStr("\nUsage:\trusti")
},
Command{
cmd: "help",
action: Call(cmd_help),
usage_line: "show detailed usage of a command",
usage_full: UsgStr(
"The help command displays the usage text of another command.\n\
The text is either build in, or provided by the corresponding \
program.\n\nUsage:\trust help <command>"
)
}
];
fn find_cmd(command_string: &str) -> Option<Command> {
do commands.find |command| {
command.cmd == command_string
}
}
fn cmd_help(args: &[~str]) -> ValidUsage {
fn print_usage(command_string: ~str) -> ValidUsage {
match find_cmd(command_string) {
Some(command) => {
match command.action {
Exec(s) => io::println(fmt!(
"The %s command is an alias for the %s program.",
command.cmd, s)),
_ => ()
}
match command.usage_full {
UsgStr(msg) => io::println(fmt!("%s\n", msg)),
UsgExec(commandline) => {
let words = str::words(commandline);
let (prog, args) = (words.head(), words.tail());
run::run_program(prog, args);
}
}
Valid
},
None => Invalid
}
}
match args {
[command_string] => print_usage(command_string),
_ => Invalid
}
}
fn cmd_test(args: &[~str]) -> ValidUsage {
match args {
[filename] => {
let test_exec = Path(filename).filestem().unwrap() + "test~";
if run::run_program("rustc", [
~"--test",
filename.to_owned(),
~"-o",
test_exec.to_owned()
]) == 0 {
run::run_program(~"./" + test_exec, []);
}
Valid
}
_ => Invalid
}
}
fn cmd_run(args: &[~str]) -> ValidUsage {
match args {
[filename] => {
let exec = Path(filename).filestem().unwrap() + "~";
if run::run_program("rustc", [
filename.to_owned(),
~"-o",
exec.to_owned()
]) == 0 {
run::run_program(~"./"+exec, []);
}
Valid
}
_ => Invalid
}
}
fn do_command(command: &Command, args: &[~str]) -> ValidUsage {
match command.action {
Call(f) => f(args),
Exec(commandline) => {
let words = str::words(commandline);
let (prog, prog_args) = (words.head(), words.tail());
let exitstatus = run::run_program(prog, prog_args + args);
os::set_exit_status(exitstatus);
Valid
}
}
}
fn usage() {
const indent: uint = 8;
io::print(
"The rust tool is a convenience for managing rust source code.\n\
It acts as a shortcut for programs of the rust tool chain.\n\
\n\
Usage:\trust <command> [arguments]\n\
\n\
The commands are:\n\
\n"
);
for commands.each |command| {
let padding = str::repeat(" ", indent - command.cmd.len());
io::println(fmt!(" %s%s%s",
command.cmd, padding, command.usage_line));
}
io::print(
"\n\
Use \"rust help <command>\" for more information about a command.\n\
\n"
);
}
fn main() {
let args = os::args().tail();
if !args.is_empty() {
for commands.each |command| {
if command.cmd == args.head() {
let result = do_command(command, args.tail());
if result.is_valid() { return; }
}
}
}
usage();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录