-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic work for cargo install #1967
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use cargo::ops; | ||
use cargo::util::{CliResult, CliError, Config}; | ||
use std::path::Path; | ||
|
||
#[allow(dead_code)] // for now until all options are implemented | ||
|
||
#[derive(RustcDecodable)] | ||
struct Options { | ||
flag_jobs: Option<u32>, | ||
flag_features: Vec<String>, | ||
flag_no_default_features: bool, | ||
flag_debug: bool, | ||
flag_bin: Option<String>, | ||
flag_example: Vec<String>, | ||
flag_package: Vec<String>, | ||
flag_verbose: bool, | ||
flag_root: Option<String>, | ||
} | ||
|
||
pub const USAGE: &'static str = " | ||
Install a crate onto the local system | ||
|
||
Installing new crates: | ||
cargo install [options] | ||
cargo install [options] [-p CRATE | --package CRATE] [--vers VERS] | ||
cargo install [options] --git URL [--branch BRANCH | --tag TAG | --rev SHA] | ||
cargo install [options] --path PATH | ||
|
||
Managing installed crates: | ||
cargo install [options] --list | ||
|
||
Options: | ||
-h, --help Print this message | ||
-j N, --jobs N The number of jobs to run in parallel | ||
--features FEATURES Space-separated list of features to activate | ||
--no-default-features Do not build the `default` feature | ||
--debug Build in debug mode instead of release mode | ||
--bin NAME Only install the binary NAME | ||
--example EXAMPLE Install the example EXAMPLE instead of binaries | ||
-p, --package CRATE Install this crate from crates.io or select the | ||
package in a repository/path to install. | ||
-v, --verbose Use verbose output | ||
--root DIR Directory to install packages into | ||
|
||
This command manages Cargo's local set of install binary crates. Only packages | ||
which have [[bin]] targets can be installed, and all binaries are installed into | ||
`$HOME/.cargo/bin` by default (or `$CARGO_HOME/bin` if you change the home | ||
directory). | ||
|
||
There are multiple methods of installing a new crate onto the system. The | ||
`cargo install` command with no arguments will install the current crate (as | ||
specifed by the current directory). Otherwise the `-p`, `--package`, `--git`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
typo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hehe, I copied straight from the RFC... |
||
and `--path` options all specify the source from which a crate is being | ||
installed. The `-p` and `--package` options will download crates from crates.io. | ||
|
||
Crates from crates.io can optionally specify the version they wish to install | ||
via the `--vers` flags, and similarly packages from git repositories can | ||
optionally specify the branch, tag, or revision that should be installed. If a | ||
crate has multiple binaries, the `--bin` argument can selectively install only | ||
one of them, and if you'd rather install examples the `--example` argument can | ||
be used as well. | ||
|
||
The `--list` option will list all installed packages (and their versions). | ||
"; | ||
|
||
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> { | ||
config.shell().set_verbose(options.flag_verbose); | ||
|
||
let compile_opts = ops::CompileOptions { | ||
config: config, | ||
jobs: options.flag_jobs, | ||
target: None, | ||
features: &options.flag_features, | ||
no_default_features: options.flag_no_default_features, | ||
spec: None, | ||
exec_engine: None, | ||
mode: ops::CompileMode::Build, | ||
release: true, | ||
filter: ops::CompileFilter::Everything, | ||
target_rustc_args: None, | ||
}; | ||
|
||
let root = &Path::new("$HOME/.cargo/bin"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should actually be accessible through |
||
|
||
ops::install(&root, | ||
&compile_opts).map_err(|err| { | ||
CliError::from_boxed(err, 101) | ||
}).map(|_| None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nowadays this can also be written as: try!(ops::install(&root, &compile_opts));
Ok(None) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use ops; | ||
use util::CargoResult; | ||
use sources::PathSource; | ||
use std::path::Path; | ||
|
||
pub fn install(manifest_path: &Path, | ||
opts: &ops::CompileOptions) -> CargoResult<()> { | ||
let config = opts.config; | ||
let src = try!(PathSource::for_path(manifest_path.parent().unwrap(), | ||
config)); | ||
let _root = try!(src.root_package()); | ||
|
||
println!("Compiling"); | ||
try!(ops::compile(manifest_path, opts)); | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll also want to add
flag_git
/flag_branch
etc for these sorts of options to theOptions
structure above