-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Implement cargo install
#2026
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
Merged
Merged
Implement cargo install
#2026
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
use std::path::Path; | ||
|
||
use cargo::ops; | ||
use cargo::core::{SourceId, GitReference}; | ||
use cargo::util::{CliResult, Config, ToUrl, human}; | ||
|
||
#[derive(RustcDecodable)] | ||
struct Options { | ||
flag_jobs: Option<u32>, | ||
flag_features: Vec<String>, | ||
flag_no_default_features: bool, | ||
flag_debug: bool, | ||
flag_bin: Vec<String>, | ||
flag_example: Vec<String>, | ||
flag_verbose: bool, | ||
flag_quiet: bool, | ||
flag_color: Option<String>, | ||
flag_root: Option<String>, | ||
flag_list: bool, | ||
|
||
arg_crate: Option<String>, | ||
flag_vers: Option<String>, | ||
|
||
flag_git: Option<String>, | ||
flag_branch: Option<String>, | ||
flag_tag: Option<String>, | ||
flag_rev: Option<String>, | ||
|
||
flag_path: Option<String>, | ||
} | ||
|
||
pub const USAGE: &'static str = " | ||
Install a Rust binary | ||
|
||
Usage: | ||
cargo install [options] [<crate>] | ||
cargo install [options] --list | ||
|
||
Specifying what crate to install: | ||
--vers VERS Specify a version to install from crates.io | ||
--git URL Git URL to install the specified crate from | ||
--branch BRANCH Branch to use when installing from git | ||
--tag TAG Tag to use when installing from git | ||
--rev SHA Specific commit to use when installing from git | ||
--path PATH Filesystem path to local crate to install | ||
|
||
Build and install 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 | ||
--root DIR Directory to install packages into | ||
-v, --verbose Use verbose output | ||
-q, --quiet Less output printed to stdout | ||
--color WHEN Coloring: auto, always, never | ||
|
||
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 | ||
the installation root's `bin` folder. The installation root is determined, in | ||
order of precedence, by `--root`, `$CARGO_INSTALL_ROOT`, the `install.root` | ||
configuration key, and finally the home directory (which is either | ||
`$CARGO_HOME` if set or `$HOME/.cargo` by default). | ||
|
||
There are multiple sources from which a crate can be installed. The default | ||
location is crates.io but the `--git` and `--path` flags can change this source. | ||
If the source contains more than one package (such as crates.io or a git | ||
repository with multiple crates) the `<crate>` argument is required to indicate | ||
which crate should be installed. | ||
|
||
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<()>> { | ||
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); | ||
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); | ||
|
||
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: &[], | ||
exec_engine: None, | ||
mode: ops::CompileMode::Build, | ||
release: !options.flag_debug, | ||
filter: ops::CompileFilter::new(false, &options.flag_bin, &[], | ||
&options.flag_example, &[]), | ||
target_rustc_args: None, | ||
}; | ||
|
||
let source = if let Some(url) = options.flag_git { | ||
let url = try!(url.to_url().map_err(human)); | ||
let gitref = if let Some(branch) = options.flag_branch { | ||
GitReference::Branch(branch) | ||
} else if let Some(tag) = options.flag_tag { | ||
GitReference::Tag(tag) | ||
} else if let Some(rev) = options.flag_rev { | ||
GitReference::Rev(rev) | ||
} else { | ||
GitReference::Branch("master".to_string()) | ||
}; | ||
SourceId::for_git(&url, gitref) | ||
} else if let Some(path) = options.flag_path { | ||
try!(SourceId::for_path(Path::new(&path))) | ||
} else { | ||
try!(SourceId::for_central(config)) | ||
}; | ||
|
||
let krate = options.arg_crate.as_ref().map(|s| &s[..]); | ||
let vers = options.flag_vers.as_ref().map(|s| &s[..]); | ||
let root = options.flag_root.as_ref().map(|s| &s[..]); | ||
|
||
if options.flag_list { | ||
try!(ops::install_list(root, config)); | ||
} else { | ||
try!(ops::install(root, krate, &source, vers, &compile_opts)); | ||
} | ||
Ok(None) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use cargo::ops; | ||
use cargo::util::{CliResult, Config}; | ||
|
||
#[derive(RustcDecodable)] | ||
struct Options { | ||
flag_bin: Vec<String>, | ||
flag_root: Option<String>, | ||
flag_verbose: bool, | ||
flag_quiet: bool, | ||
flag_color: Option<String>, | ||
|
||
arg_spec: String, | ||
} | ||
|
||
pub const USAGE: &'static str = " | ||
Remove a Rust binary | ||
|
||
Usage: | ||
cargo uninstall [options] <spec> | ||
|
||
Options: | ||
-h, --help Print this message | ||
--root DIR Directory to uninstall packages from | ||
--bin NAME Only uninstall the binary NAME | ||
-v, --verbose Use verbose output | ||
-q, --quiet Less output printed to stdout | ||
--color WHEN Coloring: auto, always, never | ||
|
||
The argument SPEC is a package id specification (see `cargo help pkgid`) to | ||
specify which crate should be uninstalled. By default all binaries are | ||
uninstalled for a crate but the `--bin` and `--example` flags can be used to | ||
only uninstall particular binaries. | ||
"; | ||
|
||
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> { | ||
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); | ||
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); | ||
|
||
let root = options.flag_root.as_ref().map(|s| &s[..]); | ||
try!(ops::uninstall(root, &options.arg_spec, &options.flag_bin, config)); | ||
Ok(None) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'd like to note my continuing discomfort with inventing Yet Another Language-Specific Homedir Install Location, rather than using
${HOME}/.local/
, which is intended for user-scoped installation.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.
This isn't inventing a new one, as
~/.cargo
is already being used.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.
That's why it's continuing discomfort 😛