Skip to content

Commit b902398

Browse files
committed
Add a dry_run argument to resolve_ws().
1 parent b95fb6e commit b902398

File tree

14 files changed

+48
-18
lines changed

14 files changed

+48
-18
lines changed

Diff for: benches/benchsuite/benches/resolve.rs

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn do_resolve<'gctx>(gctx: &'gctx GlobalContext, ws_root: &Path) -> ResolveInfo<
3333
let force_all_targets = ForceAllTargets::No;
3434
// Do an initial run to download anything necessary so that it does
3535
// not confuse criterion's warmup.
36+
let dry_run = false;
3637
let ws_resolve = cargo::ops::resolve_ws_with_opts(
3738
&ws,
3839
&mut target_data,
@@ -41,6 +42,7 @@ fn do_resolve<'gctx>(gctx: &'gctx GlobalContext, ws_root: &Path) -> ResolveInfo<
4142
&specs,
4243
has_dev_units,
4344
force_all_targets,
45+
dry_run,
4446
)
4547
.unwrap();
4648
ResolveInfo {
@@ -71,6 +73,7 @@ fn resolve_ws(c: &mut Criterion) {
7173
// iterator once, and we don't want to call `do_resolve` in every
7274
// "step", since that would just be some useless work.
7375
let mut lazy_info = None;
76+
let dry_run = false;
7477
group.bench_function(&ws_name, |b| {
7578
let ResolveInfo {
7679
ws,
@@ -91,6 +94,7 @@ fn resolve_ws(c: &mut Criterion) {
9194
specs,
9295
*has_dev_units,
9396
*force_all_targets,
97+
dry_run,
9498
)
9599
.unwrap();
96100
})

Diff for: src/bin/cargo/commands/add.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,9 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
214214
};
215215
add(&ws, &options)?;
216216

217-
if !dry_run {
218-
// Reload the workspace since we've changed dependencies
219-
let ws = args.workspace(gctx)?;
220-
resolve_ws(&ws)?;
221-
}
217+
// Reload the workspace since we've changed dependencies
218+
let ws = args.workspace(gctx)?;
219+
resolve_ws(&ws, dry_run)?;
222220

223221
Ok(())
224222
}

Diff for: src/bin/cargo/commands/remove.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
121121
ws.gctx()
122122
.shell()
123123
.set_verbosity(cargo::core::Verbosity::Quiet);
124-
let resolve = resolve_ws(&ws);
124+
let resolve = resolve_ws(&ws, dry_run);
125125
ws.gctx().shell().set_verbosity(verbosity);
126126
resolve?.1
127127
};
128128

129129
// Attempt to gc unused patches and re-resolve if anything is removed
130130
if gc_unused_patches(&workspace, &resolve)? {
131131
let ws = args.workspace(gctx)?;
132-
resolve_ws(&ws)?;
132+
resolve_ws(&ws, dry_run)?;
133133
}
134134
}
135135
Ok(())

Diff for: src/cargo/core/compiler/standard_lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub fn resolve_std<'gctx>(
149149
let cli_features = CliFeatures::from_command_line(
150150
&features, /*all_features*/ false, /*uses_default_features*/ false,
151151
)?;
152+
let dry_run = false;
152153
let resolve = ops::resolve_ws_with_opts(
153154
&std_ws,
154155
target_data,
@@ -157,6 +158,7 @@ pub fn resolve_std<'gctx>(
157158
&specs,
158159
HasDevUnits::No,
159160
crate::core::resolver::features::ForceAllTargets::No,
161+
dry_run,
160162
)?;
161163
Ok((
162164
resolve.pkg_set,

Diff for: src/cargo/ops/cargo_clean.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
7777
if opts.spec.is_empty() {
7878
clean_ctx.remove_paths(&[target_dir.into_path_unlocked()])?;
7979
} else {
80-
clean_specs(&mut clean_ctx, &ws, &profiles, &opts.targets, &opts.spec)?;
80+
clean_specs(
81+
&mut clean_ctx,
82+
&ws,
83+
&profiles,
84+
&opts.targets,
85+
&opts.spec,
86+
opts.dry_run,
87+
)?;
8188
}
8289
}
8390

@@ -91,11 +98,12 @@ fn clean_specs(
9198
profiles: &Profiles,
9299
targets: &[String],
93100
spec: &[String],
101+
dry_run: bool,
94102
) -> CargoResult<()> {
95103
// Clean specific packages.
96104
let requested_kinds = CompileKind::from_requested_targets(clean_ctx.gctx, targets)?;
97105
let target_data = RustcTargetData::new(ws, &requested_kinds)?;
98-
let (pkg_set, resolve) = ops::resolve_ws(ws)?;
106+
let (pkg_set, resolve) = ops::resolve_ws(ws, dry_run)?;
99107
let prof_dir_name = profiles.get_dir_name();
100108
let host_layout = Layout::new(ws, None, &prof_dir_name)?;
101109
// Convert requested kinds to a Vec of layouts.

Diff for: src/cargo/ops/cargo_compile/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ pub fn create_bcx<'a, 'gctx>(
264264
HasDevUnits::No
265265
}
266266
};
267+
let dry_run = false;
267268
let resolve = ops::resolve_ws_with_opts(
268269
ws,
269270
&mut target_data,
@@ -272,6 +273,7 @@ pub fn create_bcx<'a, 'gctx>(
272273
&specs,
273274
has_dev_units,
274275
crate::core::resolver::features::ForceAllTargets::No,
276+
dry_run,
275277
)?;
276278
let WorkspaceResolve {
277279
mut pkg_set,

Diff for: src/cargo/ops/cargo_fetch.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub fn fetch<'a>(
1919
options: &FetchOptions<'a>,
2020
) -> CargoResult<(Resolve, PackageSet<'a>)> {
2121
ws.emit_warnings()?;
22-
let (mut packages, resolve) = ops::resolve_ws(ws)?;
22+
let dry_run = false;
23+
let (mut packages, resolve) = ops::resolve_ws(ws, dry_run)?;
2324

2425
let jobs = Some(JobsConfig::Integer(1));
2526
let keep_going = false;

Diff for: src/cargo/ops/cargo_install.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ impl<'gctx> InstallablePackage<'gctx> {
561561
// It would be best if `source` could be passed in here to avoid a
562562
// duplicate "Updating", but since `source` is taken by value, then it
563563
// wouldn't be available for `compile_ws`.
564-
let (pkg_set, resolve) = ops::resolve_ws(&self.ws)?;
564+
let dry_run = false;
565+
let (pkg_set, resolve) = ops::resolve_ws(&self.ws, dry_run)?;
565566
ops::check_yanked(
566567
self.ws.gctx(),
567568
&pkg_set,

Diff for: src/cargo/ops/cargo_output_metadata.rs

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ fn build_resolve_graph(
142142

143143
// Note that even with --filter-platform we end up downloading host dependencies as well,
144144
// as that is the behavior of download_accessible.
145+
let dry_run = false;
145146
let ws_resolve = ops::resolve_ws_with_opts(
146147
ws,
147148
&mut target_data,
@@ -150,6 +151,7 @@ fn build_resolve_graph(
150151
&specs,
151152
HasDevUnits::Yes,
152153
force_all,
154+
dry_run,
153155
)?;
154156

155157
let package_map: BTreeMap<PackageId, Package> = ws_resolve

Diff for: src/cargo/ops/cargo_package.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
190190

191191
if ws.root().join("Cargo.lock").exists() {
192192
// Make sure the Cargo.lock is up-to-date and valid.
193-
let _ = ops::resolve_ws(ws)?;
193+
let dry_run = false;
194+
let _ = ops::resolve_ws(ws, dry_run)?;
194195
// If Cargo.lock does not exist, it will be generated by `build_lock`
195196
// below, and will be validated during the verification step.
196197
}

Diff for: src/cargo/ops/fix.rs

+2
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ fn check_resolver_change<'gctx>(
506506
assert_eq!(ws.resolve_behavior(), ResolveBehavior::V1);
507507
let specs = opts.compile_opts.spec.to_package_id_specs(ws)?;
508508
let mut resolve_differences = |has_dev_units| -> CargoResult<(WorkspaceResolve<'_>, DiffMap)> {
509+
let dry_run = false;
509510
let ws_resolve = ops::resolve_ws_with_opts(
510511
ws,
511512
target_data,
@@ -514,6 +515,7 @@ fn check_resolver_change<'gctx>(
514515
&specs,
515516
has_dev_units,
516517
crate::core::resolver::features::ForceAllTargets::No,
518+
dry_run,
517519
)?;
518520

519521
let feature_opts = FeatureOpts::new_behavior(ResolveBehavior::V2, has_dev_units);

Diff for: src/cargo/ops/resolve.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ version. This may also occur with an optional dependency that is not enabled.";
115115
///
116116
/// This is a simple interface used by commands like `clean`, `fetch`, and
117117
/// `package`, which don't specify any options or features.
118-
pub fn resolve_ws<'a>(ws: &Workspace<'a>) -> CargoResult<(PackageSet<'a>, Resolve)> {
118+
pub fn resolve_ws<'a>(ws: &Workspace<'a>, dry_run: bool) -> CargoResult<(PackageSet<'a>, Resolve)> {
119119
let mut registry = PackageRegistry::new(ws.gctx())?;
120-
let resolve = resolve_with_registry(ws, &mut registry)?;
120+
let resolve = resolve_with_registry(ws, &mut registry, dry_run)?;
121121
let packages = get_resolved_packages(&resolve, registry)?;
122122
Ok((packages, resolve))
123123
}
@@ -140,6 +140,7 @@ pub fn resolve_ws_with_opts<'gctx>(
140140
specs: &[PackageIdSpec],
141141
has_dev_units: HasDevUnits,
142142
force_all_targets: ForceAllTargets,
143+
dry_run: bool,
143144
) -> CargoResult<WorkspaceResolve<'gctx>> {
144145
let mut registry = PackageRegistry::new(ws.gctx())?;
145146
let (resolve, resolved_with_overrides) = if ws.ignore_lock() {
@@ -160,7 +161,7 @@ pub fn resolve_ws_with_opts<'gctx>(
160161
} else if ws.require_optional_deps() {
161162
// First, resolve the root_package's *listed* dependencies, as well as
162163
// downloading and updating all remotes and such.
163-
let resolve = resolve_with_registry(ws, &mut registry)?;
164+
let resolve = resolve_with_registry(ws, &mut registry, dry_run)?;
164165
// No need to add patches again, `resolve_with_registry` has done it.
165166
let add_patches = false;
166167

@@ -269,6 +270,7 @@ pub fn resolve_ws_with_opts<'gctx>(
269270
fn resolve_with_registry<'gctx>(
270271
ws: &Workspace<'gctx>,
271272
registry: &mut PackageRegistry<'gctx>,
273+
dry_run: bool,
272274
) -> CargoResult<Resolve> {
273275
let prev = ops::load_pkg_lockfile(ws)?;
274276
let mut resolve = resolve_with_previous(
@@ -283,7 +285,11 @@ fn resolve_with_registry<'gctx>(
283285
)?;
284286

285287
let print = if !ws.is_ephemeral() && ws.require_optional_deps() {
286-
ops::write_pkg_lockfile(ws, &mut resolve)?
288+
if !dry_run {
289+
ops::write_pkg_lockfile(ws, &mut resolve)?
290+
} else {
291+
true
292+
}
287293
} else {
288294
// This mostly represents
289295
// - `cargo install --locked` and the only change is the package is no longer local but

Diff for: src/cargo/ops/tree/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
131131
} else {
132132
ForceAllTargets::No
133133
};
134+
let dry_run = false;
134135
let ws_resolve = ops::resolve_ws_with_opts(
135136
ws,
136137
&mut target_data,
@@ -139,6 +140,7 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
139140
&specs,
140141
has_dev,
141142
force_all,
143+
dry_run,
142144
)?;
143145

144146
let package_map: HashMap<PackageId, &Package> = ws_resolve

Diff for: src/cargo/ops/vendor.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ fn sync(
8080
workspaces: &[&Workspace<'_>],
8181
opts: &VendorOptions<'_>,
8282
) -> CargoResult<VendorConfig> {
83+
let dry_run = false;
8384
let canonical_destination = try_canonicalize(opts.destination);
8485
let canonical_destination = canonical_destination.as_deref().unwrap_or(opts.destination);
8586
let dest_dir_already_exists = canonical_destination.exists();
@@ -112,7 +113,7 @@ fn sync(
112113
// crate to work with.
113114
for ws in workspaces {
114115
let (packages, resolve) =
115-
ops::resolve_ws(ws).with_context(|| "failed to load pkg lockfile")?;
116+
ops::resolve_ws(ws, dry_run).with_context(|| "failed to load pkg lockfile")?;
116117

117118
packages
118119
.get_many(resolve.iter())
@@ -144,7 +145,7 @@ fn sync(
144145
// tables about them.
145146
for ws in workspaces {
146147
let (packages, resolve) =
147-
ops::resolve_ws(ws).with_context(|| "failed to load pkg lockfile")?;
148+
ops::resolve_ws(ws, dry_run).with_context(|| "failed to load pkg lockfile")?;
148149

149150
packages
150151
.get_many(resolve.iter())

0 commit comments

Comments
 (0)