Skip to content

Commit f03efb4

Browse files
committed
---
yaml --- r: 14395 b: refs/heads/try c: 3c95fa2 h: refs/heads/master i: 14393: b8a08ec 14391: e2f92c4 v: v3
1 parent 36d8baf commit f03efb4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+845
-1606
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 46018107474675ece9b7ef482d2ff1be1086d085
5+
refs/heads/try: 3c95fa22daf157d8e2d07b20e66f9888de60681a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/doc/tutorial.md

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,10 +2375,10 @@ module `task`. Let's begin with the simplest one, `task::spawn()`:
23752375

23762376
~~~~
23772377
let some_value = 22;
2378-
task::spawn {||
2378+
let child_task = task::spawn {||
23792379
std::io::println("This executes in the child task.");
23802380
std::io::println(#fmt("%d", some_value));
2381-
}
2381+
};
23822382
~~~~
23832383

23842384
The argument to `task::spawn()` is a [unique
@@ -2456,66 +2456,70 @@ let result = comm::recv(port);
24562456
## Creating a task with a bi-directional communication path
24572457

24582458
A very common thing to do is to spawn a child task where the parent
2459-
and child both need to exchange messages with each
2460-
other. The function `task::spawn_listener()` supports this pattern. We'll look
2461-
briefly at how it is used.
2459+
and child both need to exchange messages with each other. The function
2460+
`task::spawn_connected()` supports this pattern. We'll look briefly at
2461+
how it is used.
24622462

2463-
To see how `spawn_listener()` works, we will create a child task
2463+
To see how `spawn_connected()` works, we will create a child task
24642464
which receives `uint` messages, converts them to a string, and sends
24652465
the string in response. The child terminates when `0` is received.
24662466
Here is the function which implements the child task:
24672467

24682468
~~~~
2469-
fn stringifier(from_parent: comm::port<uint>,
2470-
to_parent: comm::chan<str>) {
2469+
fn stringifier(from_par: comm::port<uint>,
2470+
to_par: comm::chan<str>) {
24712471
let value: uint;
24722472
do {
2473-
value = comm::recv(from_parent);
2474-
comm::send(to_parent, uint::to_str(value, 10u));
2473+
value = comm::recv(from_par);
2474+
comm::send(to_par, uint::to_str(value, 10u));
24752475
} while value != 0u;
24762476
}
24772477
24782478
~~~~
2479-
24802479
You can see that the function takes two parameters. The first is a
24812480
port used to receive messages from the parent, and the second is a
24822481
channel used to send messages to the parent. The body itself simply
24832482
loops, reading from the `from_par` port and then sending its response
24842483
to the `to_par` channel. The actual response itself is simply the
24852484
strified version of the received value, `uint::to_str(value)`.
2486-
2487-
Here is the code for the parent task:
24882485

2486+
Here is the code for the parent task:
24892487
~~~~
2490-
# fn stringifier(from_parent: comm::port<uint>,
2491-
# to_parent: comm::chan<str>) {
2492-
# comm::send(to_parent, "22");
2493-
# comm::send(to_parent, "23");
2494-
# comm::send(to_parent, "0");
2488+
# fn stringifier(from_par: comm::port<uint>,
2489+
# to_par: comm::chan<str>) {
2490+
# comm::send(to_par, "22");
2491+
# comm::send(to_par, "23");
2492+
# comm::send(to_par, "0");
24952493
# }
24962494
fn main() {
2497-
let from_child = comm::port();
2498-
let to_parent = comm::chan(from_child);
2499-
let to_child = task::spawn_listener {|from_parent|
2500-
stringifier(from_parent, to_parent);
2501-
};
2502-
comm::send(to_child, 22u);
2503-
assert comm::recv(from_child) == "22";
2504-
comm::send(to_child, 23u);
2505-
assert comm::recv(from_child) == "23";
2506-
comm::send(to_child, 0u);
2507-
assert comm::recv(from_child) == "0";
2508-
}
2509-
~~~~
2510-
2511-
The parent first sets up a port to receive data from and a channel
2512-
that the child can use to send data to that port. The call to
2513-
`spawn_listener()` will spawn the child task, providing it with a port
2514-
on which to receive data from its parent, and returning to the parent
2515-
the associated channel. Finally, the closure passed to
2516-
`spawn_listener()` that forms the body of the child task captures the
2517-
`to_parent` channel in its environment, so both parent and child
2518-
can send and receive data to and from the other.
2495+
let t = task::spawn_connected(stringifier);
2496+
comm::send(t.to_child, 22u);
2497+
assert comm::recv(t.from_child) == "22";
2498+
comm::send(t.to_child, 23u);
2499+
assert comm::recv(t.from_child) == "23";
2500+
comm::send(t.to_child, 0u);
2501+
assert comm::recv(t.from_child) == "0";
2502+
}
2503+
~~~~
2504+
2505+
The call to `spawn_connected()` on the first line will instantiate the
2506+
various ports and channels and startup the child task. The returned
2507+
value, `t`, is a record of type `task::connected_task<uint,str>`. In
2508+
addition to the task id of the child, this record defines two fields,
2509+
`from_child` and `to_child`, which contain the port and channel
2510+
respectively for communicating with the child. Those fields are used
2511+
here to send and receive three messages from the child task.
2512+
2513+
## Joining a task
2514+
2515+
The function `spawn_joinable()` is used to spawn a task that can later
2516+
be joined. This is implemented by having the child task send a message
2517+
when it has completed (either successfully or by failing). Therefore,
2518+
`spawn_joinable()` returns a structure containing both the task ID and
2519+
the port where this message will be sent---this structure type is
2520+
called `task::joinable_task`. The structure can be passed to
2521+
`task::join()`, which simply blocks on the port, waiting to receive
2522+
the message from the child task.
25192523

25202524
## The supervisor relationship
25212525

branches/try/mk/tests.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ endif
104104
# Extracting tests for docs
105105
######################################################################
106106

107-
EXTRACT_TESTS := $(CFG_PYTHON) $(S)src/etc/extract-tests.py
107+
EXTRACT_TESTS := "$(CFG_PYTHON)" $(S)src/etc/extract-tests.py
108108

109109
define DEF_DOC_TEST_HOST
110110

branches/try/src/cargo/cargo.rs

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std;
66
import rustc::syntax::{ast, codemap};
77
import rustc::syntax::parse::parser;
88
import rustc::util::filesearch::{get_cargo_root, get_cargo_root_nearest,
9-
get_cargo_sysroot, libdir};
9+
get_cargo_sysroot};
1010
import rustc::driver::diagnostic;
1111

1212
import std::fs;
@@ -346,35 +346,39 @@ fn build_cargo_options(argv: [str]) -> options {
346346
};
347347

348348
let test = opt_present(match, "test");
349-
let G = opt_present(match, "G");
350-
let g = opt_present(match, "g");
351-
let m = opt_present(match, "mode");
352-
let is_install = vec::len(match.free) > 1u && match.free[1] == "install";
353-
354-
if G && g { fail "-G and -g both provided"; }
355-
if g && m { fail "--mode and -g both provided"; }
356-
if G && m { fail "--mode and -G both provided"; }
357-
358-
let mode = if is_install {
359-
if G { system_mode }
360-
else if g { user_mode }
361-
else if m {
362-
alt getopts::opt_str(match, "mode") {
363-
"system" { system_mode }
364-
"user" { user_mode }
365-
"local" { local_mode }
366-
_ { fail "argument to `mode` must be one of `system`" +
367-
", `user`, or `local`";
368-
}
349+
let mode = if opt_present(match, "G") {
350+
if opt_present(match, "mode") { fail "--mode and -G both provided"; }
351+
if opt_present(match, "g") { fail "-G and -g both provided"; }
352+
system_mode
353+
} else if opt_present(match, "g") {
354+
if opt_present(match, "mode") { fail "--mode and -g both provided"; }
355+
if opt_present(match, "G") { fail "-G and -g both provided"; }
356+
user_mode
357+
} else if opt_present(match, "mode") {
358+
alt getopts::opt_str(match, "mode") {
359+
"system" { system_mode }
360+
"user" { user_mode }
361+
"local" { local_mode }
362+
_ { fail "argument to `mode` must be one of `system`" +
363+
", `user`, or `normal`";
369364
}
370-
} else { local_mode }
371-
} else { system_mode };
365+
}
366+
} else {
367+
local_mode
368+
};
369+
370+
if mode == system_mode {
371+
// FIXME: Per discussion on #1760, we need to think about how
372+
// system mode works. It should install files to the normal
373+
// sysroot paths, but it also needsd an area to place various
374+
// cargo configuration and work files.
375+
fail "system mode does not exist yet";
376+
}
372377

373378
{test: test, mode: mode, free: match.free}
374379
}
375380

376381
fn configure(opts: options) -> cargo {
377-
let syscargo = result::get(get_cargo_sysroot());
378382
let get_cargo_dir = alt opts.mode {
379383
system_mode { get_cargo_sysroot }
380384
user_mode { get_cargo_root }
@@ -387,15 +391,15 @@ fn configure(opts: options) -> cargo {
387391
};
388392

389393
let sources = map::new_str_hash::<source>();
390-
try_parse_sources(fs::connect(syscargo, "sources.json"), sources);
391-
try_parse_sources(fs::connect(syscargo, "local-sources.json"), sources);
394+
try_parse_sources(fs::connect(p, "sources.json"), sources);
395+
try_parse_sources(fs::connect(p, "local-sources.json"), sources);
392396
let c = {
393397
pgp: pgp::supported(),
394398
root: p,
395399
bindir: fs::connect(p, "bin"),
396400
libdir: fs::connect(p, "lib"),
397401
workdir: fs::connect(p, "work"),
398-
sourcedir: fs::connect(syscargo, "sources"),
402+
sourcedir: fs::connect(p, "sources"),
399403
sources: sources,
400404
opts: opts
401405
};
@@ -467,31 +471,10 @@ fn install_one_crate(c: cargo, _path: str, cf: str, _p: pkg) {
467471
#debug(" bin: %s", ct);
468472
// FIXME: need libstd fs::copy or something
469473
run::run_program("cp", [ct, c.bindir]);
470-
if c.opts.mode == system_mode {
471-
install_one_crate_to_sysroot(ct, "bin");
472-
}
473474
} else {
474475
#debug(" lib: %s", ct);
475476
run::run_program("cp", [ct, c.libdir]);
476-
if c.opts.mode == system_mode {
477-
install_one_crate_to_sysroot(ct, libdir());
478-
}
479-
}
480-
}
481-
}
482-
483-
fn install_one_crate_to_sysroot(ct: str, target: str) {
484-
alt os::get_exe_path() {
485-
some(_path) {
486-
let path = [_path, "..", target];
487-
check vec::is_not_empty(path);
488-
let target_dir = fs::normalize(fs::connect_many(path));
489-
let p = run::program_output("cp", [ct, target_dir]);
490-
if p.status != 0 {
491-
warn(#fmt["Copying %s to %s is failed", ct, target_dir]);
492-
}
493477
}
494-
none { }
495478
}
496479
}
497480

@@ -848,25 +831,23 @@ fn cmd_usage() {
848831
"
849832
850833
init Set up .cargo
851-
install [options] [source/]package-name Install by name
852-
install [options] uuid:[source/]package-uuid Install by uuid
834+
install [--test] [source/]package-name Install by name
835+
install [--test] uuid:[source/]package-uuid Install by uuid
853836
list [source] List packages
854837
search <name | '*'> [tags...] Search packages
855838
sync Sync all sources
856839
usage This
857840
858841
Options:
859842
860-
cargo install
861-
862843
--mode=[system,user,local] change mode as (system/user/local)
863844
-g equivalent to --mode=user
864845
-G equivalent to --mode=system
865846
866847
NOTE:
867-
\"cargo install\" installs bin/libs to local-level .cargo by default.
868-
To install them into user-level .cargo, use option -g/--mode=user.
869-
To install them into bin/lib on sysroot, use option -G/--mode=system.
848+
This command creates/uses local-level .cargo by default.
849+
To create/use user-level .cargo, use option -g/--mode=user.
850+
To create/use system-level .cargo, use option -G/--mode=system.
870851
");
871852
}
872853

branches/try/src/comp/driver/rustc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ fn monitor(f: fn~(diagnostic::emitter)) {
143143

144144
alt task::try {||
145145

146+
task::unsupervise();
147+
146148
// The 'diagnostics emitter'. Every error, warning, etc. should
147149
// go through this function.
148150
let demitter = fn@(cmsp: option<(codemap::codemap, codemap::span)>,

0 commit comments

Comments
 (0)