Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ macro_rules! each_subcommand{ ($mac:ident) => ({
$mac!(generate_lockfile);
$mac!(git_checkout);
$mac!(help);
$mac!(install);
$mac!(locate_project);
$mac!(login);
$mac!(new);
Expand Down
89 changes: 89 additions & 0 deletions src/bin/install.rs
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]
Copy link
Member

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 the Options structure above

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`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifed

typo

Copy link
Member Author

Choose a reason for hiding this comment

The 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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be accessible through config.home().join("bin")


ops::install(&root,
&compile_opts).map_err(|err| {
CliError::from_boxed(err, 101)
}).map(|_| None)
Copy link
Member

Choose a reason for hiding this comment

The 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)

}
17 changes: 17 additions & 0 deletions src/cargo/ops/cargo_install.rs
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(())
}
2 changes: 2 additions & 0 deletions src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub use self::cargo_rustc::Platform;
pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
pub use self::cargo_rustc::{CommandType, CommandPrototype, ExecEngine, ProcessEngine};
pub use self::cargo_run::run;
pub use self::cargo_install::install;
pub use self::cargo_new::{new, NewOptions, VersionControl};
pub use self::cargo_doc::{doc, DocOptions};
pub use self::cargo_generate_lockfile::{generate_lockfile};
Expand All @@ -29,6 +30,7 @@ mod cargo_compile;
mod cargo_doc;
mod cargo_fetch;
mod cargo_generate_lockfile;
mod cargo_install;
mod cargo_new;
mod cargo_package;
mod cargo_pkgid;
Expand Down
1 change: 1 addition & 0 deletions tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,4 @@ pub static DOWNLOADING: &'static str = " Downloading";
pub static UPLOADING: &'static str = " Uploading";
pub static VERIFYING: &'static str = " Verifying";
pub static ARCHIVING: &'static str = " Archiving";
pub static INSTALLED: &'static str = " Installed";