Skip to content

Commit e4918c4

Browse files
committed
Remove Config from CompileOptions.
1 parent 4c7a638 commit e4918c4

12 files changed

+63
-86
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
156156
ops::install_list(root, config)?;
157157
} else {
158158
ops::install(
159+
config,
159160
root,
160161
krates,
161162
source,

src/cargo/ops/cargo_compile.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ use crate::util::{closest_msg, profile, CargoResult};
4646

4747
/// Contains information about how a package should be compiled.
4848
#[derive(Debug)]
49-
pub struct CompileOptions<'a> {
50-
pub config: &'a Config,
49+
pub struct CompileOptions {
5150
/// Configuration information for a rustc build
5251
pub build_config: BuildConfig,
5352
/// Extra features to build for the root package
@@ -79,10 +78,9 @@ pub struct CompileOptions<'a> {
7978
pub export_dir: Option<PathBuf>,
8079
}
8180

82-
impl<'a> CompileOptions<'a> {
83-
pub fn new(config: &'a Config, mode: CompileMode) -> CargoResult<CompileOptions<'a>> {
81+
impl<'a> CompileOptions {
82+
pub fn new(config: &Config, mode: CompileMode) -> CargoResult<CompileOptions> {
8483
Ok(CompileOptions {
85-
config,
8684
build_config: BuildConfig::new(config, None, &None, mode)?,
8785
features: Vec::new(),
8886
all_features: false,
@@ -242,10 +240,7 @@ pub enum CompileFilter {
242240
},
243241
}
244242

245-
pub fn compile<'a>(
246-
ws: &Workspace<'a>,
247-
options: &CompileOptions<'a>,
248-
) -> CargoResult<Compilation<'a>> {
243+
pub fn compile<'a>(ws: &Workspace<'a>, options: &CompileOptions) -> CargoResult<Compilation<'a>> {
249244
let exec: Arc<dyn Executor> = Arc::new(DefaultExecutor);
250245
compile_with_exec(ws, options, &exec)
251246
}
@@ -254,7 +249,7 @@ pub fn compile<'a>(
254249
/// calls and add custom logic. `compile` uses `DefaultExecutor` which just passes calls through.
255250
pub fn compile_with_exec<'a>(
256251
ws: &Workspace<'a>,
257-
options: &CompileOptions<'a>,
252+
options: &CompileOptions,
258253
exec: &Arc<dyn Executor>,
259254
) -> CargoResult<Compilation<'a>> {
260255
ws.emit_warnings()?;
@@ -263,11 +258,10 @@ pub fn compile_with_exec<'a>(
263258

264259
pub fn compile_ws<'a>(
265260
ws: &Workspace<'a>,
266-
options: &CompileOptions<'a>,
261+
options: &CompileOptions,
267262
exec: &Arc<dyn Executor>,
268263
) -> CargoResult<Compilation<'a>> {
269264
let CompileOptions {
270-
config,
271265
ref build_config,
272266
ref spec,
273267
ref features,
@@ -280,6 +274,7 @@ pub fn compile_ws<'a>(
280274
rustdoc_document_private_items,
281275
ref export_dir,
282276
} = *options;
277+
let config = ws.config();
283278

284279
match build_config.mode {
285280
CompileMode::Test

src/cargo/ops/cargo_doc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use std::process::Command;
99

1010
/// Strongly typed options for the `cargo doc` command.
1111
#[derive(Debug)]
12-
pub struct DocOptions<'a> {
12+
pub struct DocOptions {
1313
/// Whether to attempt to open the browser after compiling the docs
1414
pub open_result: bool,
1515
/// Options to pass through to the compiler
16-
pub compile_opts: ops::CompileOptions<'a>,
16+
pub compile_opts: ops::CompileOptions,
1717
}
1818

1919
/// Main method for `cargo doc`.
20-
pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
20+
pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
2121
let specs = options.compile_opts.spec.to_package_id_specs(ws)?;
2222
let opts = ResolveOpts::new(
2323
/*dev_deps*/ true,
@@ -85,7 +85,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
8585
.join(&name)
8686
.join("index.html");
8787
if path.exists() {
88-
let mut shell = options.compile_opts.config.shell();
88+
let mut shell = ws.config().shell();
8989
shell.status("Opening", path.display())?;
9090
open_docs(&path, &mut shell)?;
9191
}

src/cargo/ops/cargo_install.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,22 @@ impl Drop for Transaction {
3535
}
3636

3737
pub fn install(
38+
config: &Config,
3839
root: Option<&str>,
3940
krates: Vec<&str>,
4041
source_id: SourceId,
4142
from_cwd: bool,
4243
vers: Option<&str>,
43-
opts: &ops::CompileOptions<'_>,
44+
opts: &ops::CompileOptions,
4445
force: bool,
4546
no_track: bool,
4647
) -> CargoResult<()> {
47-
let root = resolve_root(root, opts.config)?;
48-
let map = SourceConfigMap::new(opts.config)?;
48+
let root = resolve_root(root, config)?;
49+
let map = SourceConfigMap::new(config)?;
4950

5051
let (installed_anything, scheduled_error) = if krates.len() <= 1 {
5152
install_one(
53+
config,
5254
&root,
5355
&map,
5456
krates.into_iter().next(),
@@ -69,6 +71,7 @@ pub fn install(
6971
let root = root.clone();
7072
let map = map.clone();
7173
match install_one(
74+
config,
7275
&root,
7376
&map,
7477
Some(krate),
@@ -82,7 +85,7 @@ pub fn install(
8285
) {
8386
Ok(()) => succeeded.push(krate),
8487
Err(e) => {
85-
crate::display_error(&e, &mut opts.config.shell());
88+
crate::display_error(&e, &mut config.shell());
8689
failed.push(krate)
8790
}
8891
}
@@ -100,7 +103,7 @@ pub fn install(
100103
));
101104
}
102105
if !succeeded.is_empty() || !failed.is_empty() {
103-
opts.config.shell().status("Summary", summary.join(" "))?;
106+
config.shell().status("Summary", summary.join(" "))?;
104107
}
105108

106109
(!succeeded.is_empty(), !failed.is_empty())
@@ -117,7 +120,7 @@ pub fn install(
117120
}
118121
}
119122

120-
opts.config.shell().warn(&format!(
123+
config.shell().warn(&format!(
121124
"be sure to add `{}` to your PATH to be \
122125
able to run the installed binaries",
123126
dst.display()
@@ -132,19 +135,18 @@ pub fn install(
132135
}
133136

134137
fn install_one(
138+
config: &Config,
135139
root: &Filesystem,
136140
map: &SourceConfigMap<'_>,
137141
krate: Option<&str>,
138142
source_id: SourceId,
139143
from_cwd: bool,
140144
vers: Option<&str>,
141-
opts: &ops::CompileOptions<'_>,
145+
opts: &ops::CompileOptions,
142146
force: bool,
143147
no_track: bool,
144148
is_first_install: bool,
145149
) -> CargoResult<()> {
146-
let config = opts.config;
147-
148150
let pkg = if source_id.is_git() {
149151
select_pkg(
150152
GitSource::new(source_id, config)?,

src/cargo/ops/cargo_package.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
704704
ops::compile_with_exec(
705705
&ws,
706706
&ops::CompileOptions {
707-
config,
708707
build_config: BuildConfig::new(config, opts.jobs, &opts.target, CompileMode::Build)?,
709708
features: opts.features.clone(),
710709
no_default_features: opts.no_default_features,

src/cargo/ops/cargo_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::util::{CargoResult, ProcessError};
88

99
pub fn run(
1010
ws: &Workspace<'_>,
11-
options: &ops::CompileOptions<'_>,
11+
options: &ops::CompileOptions,
1212
args: &[OsString],
1313
) -> CargoResult<Option<ProcessError>> {
1414
let config = ws.config();

src/cargo/ops/cargo_test.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ use crate::core::shell::Verbosity;
55
use crate::core::Workspace;
66
use crate::ops;
77
use crate::util::errors::CargoResult;
8-
use crate::util::{CargoTestError, ProcessError, Test};
8+
use crate::util::{CargoTestError, Config, ProcessError, Test};
99

10-
pub struct TestOptions<'a> {
11-
pub compile_opts: ops::CompileOptions<'a>,
10+
pub struct TestOptions {
11+
pub compile_opts: ops::CompileOptions,
1212
pub no_run: bool,
1313
pub no_fail_fast: bool,
1414
}
1515

1616
pub fn run_tests(
1717
ws: &Workspace<'_>,
18-
options: &TestOptions<'_>,
18+
options: &TestOptions,
1919
test_args: &[&str],
2020
) -> CargoResult<Option<CargoTestError>> {
2121
let compilation = compile_tests(ws, options)?;
2222

2323
if options.no_run {
2424
return Ok(None);
2525
}
26-
let (test, mut errors) = run_unit_tests(options, test_args, &compilation)?;
26+
let (test, mut errors) = run_unit_tests(ws.config(), options, test_args, &compilation)?;
2727

2828
// If we have an error and want to fail fast, then return.
2929
if !errors.is_empty() && !options.no_fail_fast {
3030
return Ok(Some(CargoTestError::new(test, errors)));
3131
}
3232

33-
let (doctest, docerrors) = run_doc_tests(options, test_args, &compilation)?;
33+
let (doctest, docerrors) = run_doc_tests(ws.config(), options, test_args, &compilation)?;
3434
let test = if docerrors.is_empty() { test } else { doctest };
3535
errors.extend(docerrors);
3636
if errors.is_empty() {
@@ -42,7 +42,7 @@ pub fn run_tests(
4242

4343
pub fn run_benches(
4444
ws: &Workspace<'_>,
45-
options: &TestOptions<'_>,
45+
options: &TestOptions,
4646
args: &[&str],
4747
) -> CargoResult<Option<CargoTestError>> {
4848
let compilation = compile_tests(ws, options)?;
@@ -54,18 +54,15 @@ pub fn run_benches(
5454
let mut args = args.to_vec();
5555
args.push("--bench");
5656

57-
let (test, errors) = run_unit_tests(options, &args, &compilation)?;
57+
let (test, errors) = run_unit_tests(ws.config(), options, &args, &compilation)?;
5858

5959
match errors.len() {
6060
0 => Ok(None),
6161
_ => Ok(Some(CargoTestError::new(test, errors))),
6262
}
6363
}
6464

65-
fn compile_tests<'a>(
66-
ws: &Workspace<'a>,
67-
options: &TestOptions<'a>,
68-
) -> CargoResult<Compilation<'a>> {
65+
fn compile_tests<'a>(ws: &Workspace<'a>, options: &TestOptions) -> CargoResult<Compilation<'a>> {
6966
let mut compilation = ops::compile(ws, &options.compile_opts)?;
7067
compilation
7168
.tests
@@ -75,12 +72,12 @@ fn compile_tests<'a>(
7572

7673
/// Runs the unit and integration tests of a package.
7774
fn run_unit_tests(
78-
options: &TestOptions<'_>,
75+
config: &Config,
76+
options: &TestOptions,
7977
test_args: &[&str],
8078
compilation: &Compilation<'_>,
8179
) -> CargoResult<(Test, Vec<ProcessError>)> {
82-
let config = options.compile_opts.config;
83-
let cwd = options.compile_opts.config.cwd();
80+
let cwd = config.cwd();
8481

8582
let mut errors = Vec::new();
8683

@@ -133,12 +130,12 @@ fn run_unit_tests(
133130
}
134131

135132
fn run_doc_tests(
136-
options: &TestOptions<'_>,
133+
config: &Config,
134+
options: &TestOptions,
137135
test_args: &[&str],
138136
compilation: &Compilation<'_>,
139137
) -> CargoResult<(Test, Vec<ProcessError>)> {
140138
let mut errors = Vec::new();
141-
let config = options.compile_opts.config;
142139

143140
// The unstable doctest-xcompile feature enables both per-target-ignores and
144141
// cross-compiling doctests. As a side effect, this feature also gates running

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl InstallTracker {
159159
dst: &Path,
160160
pkg: &Package,
161161
force: bool,
162-
opts: &CompileOptions<'_>,
162+
opts: &CompileOptions,
163163
target: &str,
164164
_rustc: &str,
165165
) -> CargoResult<(Freshness, BTreeMap<String, Option<PackageId>>)> {
@@ -267,7 +267,7 @@ impl InstallTracker {
267267
package: &Package,
268268
bins: &BTreeSet<String>,
269269
version_req: Option<String>,
270-
opts: &CompileOptions<'_>,
270+
opts: &CompileOptions,
271271
target: &str,
272272
rustc: &str,
273273
) {
@@ -401,7 +401,7 @@ impl CrateListingV2 {
401401
pkg: &Package,
402402
bins: &BTreeSet<String>,
403403
version_req: Option<String>,
404-
opts: &CompileOptions<'_>,
404+
opts: &CompileOptions,
405405
target: &str,
406406
rustc: &str,
407407
) {
@@ -490,12 +490,7 @@ impl InstallInfo {
490490
/// Determine if this installation is "up to date", or if it needs to be reinstalled.
491491
///
492492
/// This does not do Package/Source/Version checking.
493-
fn is_up_to_date(
494-
&self,
495-
opts: &CompileOptions<'_>,
496-
target: &str,
497-
exes: &BTreeSet<String>,
498-
) -> bool {
493+
fn is_up_to_date(&self, opts: &CompileOptions, target: &str, exes: &BTreeSet<String>) -> bool {
499494
self.features == feature_set(&opts.features)
500495
&& self.all_features == opts.all_features
501496
&& self.no_default_features == opts.no_default_features

src/cargo/ops/fix.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ use rustfix::{self, CodeFix};
5353

5454
use crate::core::Workspace;
5555
use crate::ops::{self, CompileOptions};
56-
use crate::util;
5756
use crate::util::diagnostic_server::{Message, RustfixDiagnosticServer};
5857
use crate::util::errors::CargoResult;
59-
use crate::util::ProcessBuilder;
58+
use crate::util::{self, Config, ProcessBuilder};
6059
use crate::util::{existing_vcs_repo, LockServer, LockServerClient};
6160

6261
const FIX_ENV: &str = "__CARGO_FIX_PLZ";
@@ -69,15 +68,15 @@ pub struct FixOptions<'a> {
6968
pub edition: bool,
7069
pub prepare_for: Option<&'a str>,
7170
pub idioms: bool,
72-
pub compile_opts: CompileOptions<'a>,
71+
pub compile_opts: CompileOptions,
7372
pub allow_dirty: bool,
7473
pub allow_no_vcs: bool,
7574
pub allow_staged: bool,
7675
pub broken_code: bool,
7776
}
7877

7978
pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
80-
check_version_control(opts)?;
79+
check_version_control(ws.config(), opts)?;
8180

8281
// Spin up our lock server, which our subprocesses will use to synchronize fixes.
8382
let lock_server = LockServer::new()?;
@@ -116,7 +115,7 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
116115
server.configure(&mut wrapper);
117116
}
118117

119-
let rustc = opts.compile_opts.config.load_global_rustc(Some(ws))?;
118+
let rustc = ws.config().load_global_rustc(Some(ws))?;
120119
wrapper.arg(&rustc.path);
121120

122121
// primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
@@ -127,11 +126,10 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
127126
Ok(())
128127
}
129128

130-
fn check_version_control(opts: &FixOptions<'_>) -> CargoResult<()> {
129+
fn check_version_control(config: &Config, opts: &FixOptions<'_>) -> CargoResult<()> {
131130
if opts.allow_no_vcs {
132131
return Ok(());
133132
}
134-
let config = opts.compile_opts.config;
135133
if !existing_vcs_repo(config.cwd(), config.cwd()) {
136134
anyhow::bail!(
137135
"no VCS found for this package and `cargo fix` can potentially \

0 commit comments

Comments
 (0)