Skip to content

Commit 392b902

Browse files
committed
Only --path and cwd crate installation need workspace info
1 parent f929619 commit 392b902

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,12 @@ pub fn cli() -> App {
7575
}
7676

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

88-
let mut compile_opts = args.compile_options(
89-
config,
90-
CompileMode::Build,
91-
workspace.as_ref(),
92-
ProfileChecking::Checked,
93-
)?;
94-
95-
compile_opts.build_config.requested_profile =
96-
args.get_profile_name(config, "release", ProfileChecking::Checked)?;
97-
9884
let krates = args
9985
.values_of("crate")
10086
.unwrap_or_default()
@@ -130,6 +116,26 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
130116
let version = args.value_of("version");
131117
let root = args.value_of("root");
132118

119+
// We only provide worksapce information for local crate installation from
120+
// one of the following sources:
121+
// - From current working directory (only work for edition 2015).
122+
// - From a specific local file path.
123+
let workspace = if from_cwd || args.is_present("path") {
124+
args.workspace(config).ok()
125+
} else {
126+
None
127+
};
128+
129+
let mut compile_opts = args.compile_options(
130+
config,
131+
CompileMode::Build,
132+
workspace.as_ref(),
133+
ProfileChecking::Checked,
134+
)?;
135+
136+
compile_opts.build_config.requested_profile =
137+
args.get_profile_name(config, "release", ProfileChecking::Checked)?;
138+
133139
if args.is_present("list") {
134140
ops::install_list(root, config)?;
135141
} else {

0 commit comments

Comments
 (0)