]> git.lizzy.rs Git - rust.git/commitdiff
rustpkg: More preliminary work
authorZack Corr <zack@z0w0.me>
Tue, 15 Jan 2013 13:57:03 +0000 (23:57 +1000)
committerGraydon Hoare <graydon@mozilla.com>
Sat, 16 Feb 2013 02:04:10 +0000 (18:04 -0800)
src/librustpkg/api.rs [new file with mode: 0644]
src/librustpkg/rustpkg.rc
src/librustpkg/usage.rs [new file with mode: 0644]
src/librustpkg/util.rs [new file with mode: 0644]

diff --git a/src/librustpkg/api.rs b/src/librustpkg/api.rs
new file mode 100644 (file)
index 0000000..10868c2
--- /dev/null
@@ -0,0 +1,20 @@
+use core::*;
+
+pub struct Crate {
+    file: ~str,
+    flags: ~[~str],
+    cfg: ~[~str]
+}
+
+pub impl Crate {
+    fn flag(flag: ~str) -> Crate {
+        Crate {
+            flags: vec::append(self.flags, flag),
+            .. copy self
+        }
+    }
+}
+
+pub fn build(_targets: ~[Crate]) {
+    // TODO: magic
+}
index e5f443abba43e8ebe63763a9193fa24f71144538..a21bd2dc9ec69833e71829f53d88641cd755fb21 100644 (file)
@@ -16,7 +16,6 @@
        url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")];
 
 #[crate_type = "lib"];
-
 #[no_core];
 
 extern mod core(vers = "0.6");
@@ -24,8 +23,55 @@ extern mod std(vers = "0.6");
 extern mod rustc(vers = "0.6");
 extern mod syntax(vers = "0.6");
 
+use core::*;
+use std::getopts;
+use getopts::{optflag, optopt, opt_present};
 use rustc::metadata::{filesearch};
 
+mod api;
+mod usage;
+mod util;
+
+use util::*;
+
 pub fn main() {
+    let args = os::args();
+    let opts = ~[optflag(~"h"), optflag(~"help")];
+    let matches = &match getopts::getopts(args, opts) {
+        result::Ok(m) => m,
+        result::Err(f) => {
+            fail fmt!("%s", getopts::fail_str(f));
+        }
+    };
+    let help = opt_present(matches, ~"h") || opt_present(matches, ~"help");
+    let mut args = copy matches.free;
+
+    args.shift();
 
+    if (args.len() < 1) {
+        return usage::general();
+    }
+
+    let cmd = copy args[0];
+
+    if !is_cmd(cmd) {
+        return usage::general();
+    } else if help {
+        match cmd {
+            ~"build" => usage::build(),
+            ~"clean" => usage::clean(),
+            ~"install" => usage::install(),
+            ~"prefer" => usage::prefer(),
+            ~"test" => usage::test(),
+            ~"uninstall" => usage::uninstall(),
+            ~"unprefer" => usage::unprefer(),
+            _ => usage::general()
+        }
+    }
+
+    Ctx { cmd: cmd, args: args }
 }
+
+pub use Crate = api::Crate;
+pub use build = api::build;
+pub use util = api::util;
diff --git a/src/librustpkg/usage.rs b/src/librustpkg/usage.rs
new file mode 100644 (file)
index 0000000..64fbb99
--- /dev/null
@@ -0,0 +1,100 @@
+use core::io;
+
+pub fn general() {
+    io::println(~"Usage: rustpkg [options] <cmd> [args..]
+
+Where <cmd> is one of:
+    build, clean, install, prefer, test, uninstall, unprefer
+
+Options:
+
+    -h, --help                  Display this message
+    <cmd> -h, <cmd> --help      Display help for <cmd>");
+}
+
+pub fn build() {
+    io::println(~"rustpkg [options..] build
+
+Build all targets described in the package script in the current
+directory.
+
+Options:
+    -c, --cfg      Pass a cfg flag to the package script");
+}
+
+pub fn clean() {
+    io::println(~"rustpkg clean
+
+Remove all build files in the work cache for the package in the current
+directory.");
+}
+
+pub fn install() {
+    io::println(~"rustpkg [options..] install [url] [target]
+
+Install a package from a URL by Git or cURL (FTP, HTTP, etc.).
+If target is provided, Git will checkout the branch or tag before
+continuing. If the URL is a TAR file (with or without compression),
+extract it before installing. If a URL isn't provided, the package will
+be built and installed from the current directory (which is
+functionally the same as `rustpkg build` and installing the result).
+
+Examples:
+    rustpkg install
+    rustpkg install git://github.com/mozilla/servo.git
+    rustpkg install git://github.com/mozilla/servo.git v0.1.2
+    rustpkg install http://rust-lang.org/hello-world-0.3.4.tar.gz
+
+Options:
+    -c, --cfg      Pass a cfg flag to the package script
+    -p, --prefer   Prefer the package after installing
+                   (see `rustpkg prefer -h`)");
+}
+
+pub fn uninstall() {
+    io::println(~"rustpkg uninstall <name>[@version]
+
+Remove a package by name and/or version. If version is omitted then all
+versions of the package will be removed. If the package[s] is/are depended
+on by another package then they cannot be removed.  If the package is preferred
+(see `rustpkg prefer -h`), it will attempt to prefer the next latest
+version of the package if another version is installed, otherwise it'll remove
+the symlink.");
+}
+
+pub fn prefer() {
+    io::println(~"rustpkg [options..] prefer <name>[@version]
+
+By default all binaries are given a unique name so that multiple versions can
+coexist. The prefer command will symlink the uniquely named binary to
+the binary directory under its bare name. The user will need to confirm
+if the symlink will overwrite another. If version is not supplied, the latest
+version of the package will be preferred.
+
+Example:
+    export PATH=$PATH:/home/user/.rustpkg/bin
+    rustpkg prefer machine@1.2.4
+    machine -v
+    ==> v1.2.4
+    rustpkg prefer machine@0.4.6
+    machine -v
+    ==> v0.4.6");
+}
+
+pub fn unprefer() {
+    io::println(~"rustpkg [options..] unprefer <name>
+
+Remove all symlinks from the store to the binary directory for a package
+name. See `rustpkg prefer -h` for more information.");
+}
+
+pub fn test() {
+    io::println(~"rustpkg [options..] test
+
+Build all targets described in the package script in the current directory
+with the test flag. The test bootstraps will be run afterwards and the output
+and exit code will be redirected.
+
+Options:
+    -c, --cfg      Pass a cfg flag to the package script");
+}
diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs
new file mode 100644 (file)
index 0000000..304c486
--- /dev/null
@@ -0,0 +1,6 @@
+pub fn is_cmd(cmd: ~str) -> bool {
+    let cmds = &[~"build", ~"clean", ~"install", ~"prefer", ~"test",
+                 ~"uninstall", ~"unprefer"];
+
+    vec::contains(cmds, &cmd)
+}