Skip to content

Commit

Permalink
Only --path and cwd crate installation need workspace info
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Sep 6, 2020
1 parent f929619 commit 392b902
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/bin/cargo/commands/install.rs
Expand Up @@ -75,26 +75,12 @@ pub fn cli() -> App {
}

pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let workspace;
if let Some(path) = args.value_of_path("path", config) {
config.reload_rooted_at(path)?;
// Only provide worksapce information for local crate installation
workspace = args.workspace(config).ok();
} else {
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
workspace = None;
}

let mut compile_opts = args.compile_options(
config,
CompileMode::Build,
workspace.as_ref(),
ProfileChecking::Checked,
)?;

compile_opts.build_config.requested_profile =
args.get_profile_name(config, "release", ProfileChecking::Checked)?;

let krates = args
.values_of("crate")
.unwrap_or_default()
Expand Down Expand Up @@ -130,6 +116,26 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let version = args.value_of("version");
let root = args.value_of("root");

// We only provide worksapce information for local crate installation from
// one of the following sources:
// - From current working directory (only work for edition 2015).
// - From a specific local file path.
let workspace = if from_cwd || args.is_present("path") {
args.workspace(config).ok()
} else {
None
};

let mut compile_opts = args.compile_options(
config,
CompileMode::Build,
workspace.as_ref(),
ProfileChecking::Checked,
)?;

compile_opts.build_config.requested_profile =
args.get_profile_name(config, "release", ProfileChecking::Checked)?;

if args.is_present("list") {
ops::install_list(root, config)?;
} else {
Expand Down

0 comments on commit 392b902

Please sign in to comment.