Skip to content

Commit d0960a6

Browse files
z0w0graydon
authored andcommitted
---
yaml --- r: 44509 b: refs/heads/master c: 71d34a8 h: refs/heads/master i: 44507: db9b828 v: v3
1 parent fa1be06 commit d0960a6

File tree

5 files changed

+174
-2
lines changed

5 files changed

+174
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 621c791dedaeb0b421e259feea6acef0df51ea27
2+
refs/heads/master: 71d34a8872491f37011aa14c866a95165fc45f99
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/src/librustpkg/api.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use core::*;
2+
3+
pub struct Crate {
4+
file: ~str,
5+
flags: ~[~str],
6+
cfg: ~[~str]
7+
}
8+
9+
pub impl Crate {
10+
fn flag(flag: ~str) -> Crate {
11+
Crate {
12+
flags: vec::append(self.flags, flag),
13+
.. copy self
14+
}
15+
}
16+
}
17+
18+
pub fn build(_targets: ~[Crate]) {
19+
// TODO: magic
20+
}

trunk/src/librustpkg/rustpkg.rc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,62 @@
1616
url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")];
1717

1818
#[crate_type = "lib"];
19-
2019
#[no_core];
2120

2221
extern mod core(vers = "0.6");
2322
extern mod std(vers = "0.6");
2423
extern mod rustc(vers = "0.6");
2524
extern mod syntax(vers = "0.6");
2625

26+
use core::*;
27+
use std::getopts;
28+
use getopts::{optflag, optopt, opt_present};
2729
use rustc::metadata::{filesearch};
2830

31+
mod api;
32+
mod usage;
33+
mod util;
34+
35+
use util::*;
36+
2937
pub fn main() {
38+
let args = os::args();
39+
let opts = ~[optflag(~"h"), optflag(~"help")];
40+
let matches = &match getopts::getopts(args, opts) {
41+
result::Ok(m) => m,
42+
result::Err(f) => {
43+
fail fmt!("%s", getopts::fail_str(f));
44+
}
45+
};
46+
let help = opt_present(matches, ~"h") || opt_present(matches, ~"help");
47+
let mut args = copy matches.free;
48+
49+
args.shift();
3050

51+
if (args.len() < 1) {
52+
return usage::general();
53+
}
54+
55+
let cmd = copy args[0];
56+
57+
if !is_cmd(cmd) {
58+
return usage::general();
59+
} else if help {
60+
match cmd {
61+
~"build" => usage::build(),
62+
~"clean" => usage::clean(),
63+
~"install" => usage::install(),
64+
~"prefer" => usage::prefer(),
65+
~"test" => usage::test(),
66+
~"uninstall" => usage::uninstall(),
67+
~"unprefer" => usage::unprefer(),
68+
_ => usage::general()
69+
}
70+
}
71+
72+
Ctx { cmd: cmd, args: args }
3173
}
74+
75+
pub use Crate = api::Crate;
76+
pub use build = api::build;
77+
pub use util = api::util;

trunk/src/librustpkg/usage.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
use core::io;
2+
3+
pub fn general() {
4+
io::println(~"Usage: rustpkg [options] <cmd> [args..]
5+
6+
Where <cmd> is one of:
7+
build, clean, install, prefer, test, uninstall, unprefer
8+
9+
Options:
10+
11+
-h, --help Display this message
12+
<cmd> -h, <cmd> --help Display help for <cmd>");
13+
}
14+
15+
pub fn build() {
16+
io::println(~"rustpkg [options..] build
17+
18+
Build all targets described in the package script in the current
19+
directory.
20+
21+
Options:
22+
-c, --cfg Pass a cfg flag to the package script");
23+
}
24+
25+
pub fn clean() {
26+
io::println(~"rustpkg clean
27+
28+
Remove all build files in the work cache for the package in the current
29+
directory.");
30+
}
31+
32+
pub fn install() {
33+
io::println(~"rustpkg [options..] install [url] [target]
34+
35+
Install a package from a URL by Git or cURL (FTP, HTTP, etc.).
36+
If target is provided, Git will checkout the branch or tag before
37+
continuing. If the URL is a TAR file (with or without compression),
38+
extract it before installing. If a URL isn't provided, the package will
39+
be built and installed from the current directory (which is
40+
functionally the same as `rustpkg build` and installing the result).
41+
42+
Examples:
43+
rustpkg install
44+
rustpkg install git://github.com/mozilla/servo.git
45+
rustpkg install git://github.com/mozilla/servo.git v0.1.2
46+
rustpkg install http://rust-lang.org/hello-world-0.3.4.tar.gz
47+
48+
Options:
49+
-c, --cfg Pass a cfg flag to the package script
50+
-p, --prefer Prefer the package after installing
51+
(see `rustpkg prefer -h`)");
52+
}
53+
54+
pub fn uninstall() {
55+
io::println(~"rustpkg uninstall <name>[@version]
56+
57+
Remove a package by name and/or version. If version is omitted then all
58+
versions of the package will be removed. If the package[s] is/are depended
59+
on by another package then they cannot be removed. If the package is preferred
60+
(see `rustpkg prefer -h`), it will attempt to prefer the next latest
61+
version of the package if another version is installed, otherwise it'll remove
62+
the symlink.");
63+
}
64+
65+
pub fn prefer() {
66+
io::println(~"rustpkg [options..] prefer <name>[@version]
67+
68+
By default all binaries are given a unique name so that multiple versions can
69+
coexist. The prefer command will symlink the uniquely named binary to
70+
the binary directory under its bare name. The user will need to confirm
71+
if the symlink will overwrite another. If version is not supplied, the latest
72+
version of the package will be preferred.
73+
74+
Example:
75+
export PATH=$PATH:/home/user/.rustpkg/bin
76+
rustpkg prefer machine@1.2.4
77+
machine -v
78+
==> v1.2.4
79+
rustpkg prefer machine@0.4.6
80+
machine -v
81+
==> v0.4.6");
82+
}
83+
84+
pub fn unprefer() {
85+
io::println(~"rustpkg [options..] unprefer <name>
86+
87+
Remove all symlinks from the store to the binary directory for a package
88+
name. See `rustpkg prefer -h` for more information.");
89+
}
90+
91+
pub fn test() {
92+
io::println(~"rustpkg [options..] test
93+
94+
Build all targets described in the package script in the current directory
95+
with the test flag. The test bootstraps will be run afterwards and the output
96+
and exit code will be redirected.
97+
98+
Options:
99+
-c, --cfg Pass a cfg flag to the package script");
100+
}

trunk/src/librustpkg/util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub fn is_cmd(cmd: ~str) -> bool {
2+
let cmds = &[~"build", ~"clean", ~"install", ~"prefer", ~"test",
3+
~"uninstall", ~"unprefer"];
4+
5+
vec::contains(cmds, &cmd)
6+
}

0 commit comments

Comments
 (0)