Skip to content

Commit

Permalink
Auto merge of #4578 - derekdreery:refactor/cargo_util_config, r=alexc…
Browse files Browse the repository at this point in the history
…richton

Remove some cells from Config

In most cases it makes sense to not use interior mutability in Config, so that mutability is more transparent. This PR removes Cells in these cases. It leaves those cases where parameters are only initialized on first access (LazyCell).
  • Loading branch information
bors committed Oct 7, 2017
2 parents 49ab521 + 24d745a commit 446ed6e
Show file tree
Hide file tree
Showing 33 changed files with 75 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ not affect how many jobs are used when running the benchmarks.
Compilation can be customized with the `bench` profile in the manifest.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-bench; args={:?}",
env::args().collect::<Vec<_>>());

Expand Down
2 changes: 1 addition & 1 deletion src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ the manifest. The default profile for this command is `dev`, but passing
the --release flag will use the `release` profile instead.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-build; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
Expand Down
11 changes: 6 additions & 5 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ See 'cargo help <command>' for more information on a specific command.
fn main() {
env_logger::init().unwrap();

let config = match Config::default() {
let mut config = match Config::default() {
Ok(cfg) => cfg,
Err(e) => {
let mut shell = Shell::new();
Expand All @@ -92,7 +92,7 @@ fn main() {
})
.collect());
let rest = &args;
cargo::call_main_without_stdin(execute, &config, USAGE, rest, true)
cargo::call_main_without_stdin(execute, &mut config, USAGE, rest, true)
})();

match result {
Expand Down Expand Up @@ -146,7 +146,7 @@ each_subcommand!(declare_mod);
because they are fundamental (and intertwined). Other commands can rely
on this top-level information.
*/
fn execute(flags: Flags, config: &Config) -> CliResult {
fn execute(flags: Flags, config: &mut Config) -> CliResult {
config.configure(flags.flag_verbose,
flags.flag_quiet,
&flags.flag_color,
Expand Down Expand Up @@ -250,11 +250,12 @@ fn execute(flags: Flags, config: &Config) -> CliResult {
execute_external_subcommand(config, &args[1], &args)
}

fn try_execute_builtin_command(config: &Config, args: &[String]) -> Option<CliResult> {
fn try_execute_builtin_command(config: &mut Config, args: &[String]) -> Option<CliResult> {
macro_rules! cmd {
($name:ident) => (if args[1] == stringify!($name).replace("_", "-") {
config.shell().set_verbosity(Verbosity::Verbose);
let r = cargo::call_main_without_stdin($name::execute, config,
let r = cargo::call_main_without_stdin($name::execute,
config,
$name::USAGE,
&args,
false);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct Options {
flag_z: Vec<String>,
}

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-check; args={:?}",
env::args().collect::<Vec<_>>());

Expand Down
2 changes: 1 addition & 1 deletion src/bin/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ given, then all packages' artifacts are removed. For more information on SPEC
and its format, see the `cargo help pkgid` command.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ current package is documented. For more information on SPEC and its format, see
the `cargo help pkgid` command.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-check; args={:?}",
env::args().collect::<Vec<_>>());

Expand Down
2 changes: 1 addition & 1 deletion src/bin/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ If the lockfile is not available, then this is the equivalent of
all updated.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/git_checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Options:
-h, --help Print this message
";

pub fn execute(_: Options, _: &Config) -> CliResult {
pub fn execute(_: Options, _: &mut Config) -> CliResult {
// This is a dummy command just so that `cargo help help` works.
// The actual delegation of help flag to subcommands is handled by the
// cargo command.
Expand Down
2 changes: 1 addition & 1 deletion src/bin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-init; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ the more explicit `install --path .`.
The `--list` option will list all installed packages (and their versions).
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
3 changes: 1 addition & 2 deletions src/bin/locate_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ pub struct ProjectLocation {
root: String
}

pub fn execute(flags: LocateProjectFlags,
config: &Config) -> CliResult {
pub fn execute(flags: LocateProjectFlags, config: &mut Config) -> CliResult {
let root = find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd())?;

let string = root.to_str()
Expand Down
2 changes: 1 addition & 1 deletion src/bin/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Options:
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ See http://doc.crates.io/crates-io.html#cargo-owner for detailed documentation
and troubleshooting.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
3 changes: 1 addition & 2 deletions src/bin/pkgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ Example Package IDs
";

pub fn execute(options: Options,
config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Options:
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Options:
--color WHEN Coloring: auto, always, never
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-read-manifest; args={:?}",
env::args().collect::<Vec<_>>());
config.shell().set_color_choice(options.flag_color.as_ref().map(|s| &s[..]))?;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ arguments to both Cargo and the binary, the ones after `--` go to the binary,
the ones before go to Cargo.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ processes spawned by Cargo, use the $RUSTFLAGS environment variable or the
`build.rustflags` configuration option.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-rustc; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ current package is documented. For more information on SPEC and its format, see
the `cargo help pkgid` command.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ To get the list of all options available for the test binaries use this:
cargo test -- --help
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-test; args={:?}",
env::args().collect::<Vec<_>>());

Expand Down
2 changes: 1 addition & 1 deletion src/bin/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ uninstalled for a crate but the `--bin` and `--example` flags can be used to
only uninstall particular binaries.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ updated.
For more information about package id specifications, see `cargo help pkgid`.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/verify_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Options:
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";

pub fn execute(args: Flags, config: &Config) -> CliResult {
pub fn execute(args: Flags, config: &mut Config) -> CliResult {
config.configure(args.flag_verbose,
args.flag_quiet,
&args.flag_color,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Options:
--color WHEN Coloring: auto, always, never
";

pub fn execute(_: Options, _: &Config) -> CliResult {
pub fn execute(_: Options, _: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-version; args={:?}", env::args().collect::<Vec<_>>());

println!("{}", cargo::version());
Expand Down
2 changes: 1 addition & 1 deletion src/bin/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ download the yanked version to use it. Cargo will, however, not allow any new
crates to be locked to any yanked version.
";

pub fn execute(options: Options, config: &Config) -> CliResult {
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ impl fmt::Display for VersionInfo {
}

pub fn call_main_without_stdin<'de, Flags: Deserialize<'de>>(
exec: fn(Flags, &Config) -> CliResult,
config: &Config,
exec: fn(Flags, &mut Config) -> CliResult,
config: &mut Config,
usage: &str,
args: &[String],
options_first: bool) -> CliResult
Expand Down
Loading

0 comments on commit 446ed6e

Please sign in to comment.