Skip to content

Commit

Permalink
Auto merge of rust-lang#5176 - alexcrichton:rustfmt, r=alexcrichton
Browse files Browse the repository at this point in the history
Add `cargo fmt` to CI and delete `rustfmt.toml`

This commit adds CI to run `cargo fmt` over Cargo itself as well as the internal
`crates-io` crate. This should switch Cargo to the "default style" (aka whatever
rustfmt spits out) and ensure that we keep it that way via CI. Hopefully this
won't be too much of a bother to keep up and running in CI as it should just be
a `cargo fmt` away!
  • Loading branch information
bors committed Mar 15, 2018
2 parents 1eb4c8f + 3d85814 commit 805fbeb
Show file tree
Hide file tree
Showing 189 changed files with 31,476 additions and 17,028 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ matrix:

- env: TARGET=x86_64-unknown-linux-gnu
ALT=i686-unknown-linux-gnu
rust: nightly
rust: nightly-2018-03-07
install:
- mdbook --help || cargo install mdbook --force
script:
- cargo test
- cargo doc --no-deps
- (cd src/doc && mdbook build --dest-dir ../../target/doc)

- before_script: rustup component add rustfmt-preview
script: cargo fmt -- --write-mode diff

exclude:
- rust: stable

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ environment:

install:
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly-2018-03-07
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustup target add %OTHER_TARGET%
- rustc -V
Expand Down
1 change: 0 additions & 1 deletion rustfmt.toml

This file was deleted.

44 changes: 22 additions & 22 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
extern crate cargo;
extern crate clap;
extern crate env_logger;
#[macro_use]
extern crate failure;
extern crate git2_curl;
extern crate toml;
extern crate log;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate clap;
extern crate toml;

use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::collections::BTreeSet;

use cargo::core::shell::Shell;
use cargo::util::{self, CliResult, lev_distance, Config, CargoResult};
use cargo::util::{self, lev_distance, CargoResult, CliResult, Config};
use cargo::util::{CliError, ProcessError};

mod cli;
mod command_prelude;
mod commands;


fn main() {
env_logger::init();

Expand Down Expand Up @@ -53,7 +52,8 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
match config.get_string(&alias_name) {
Ok(value) => {
if let Some(record) = value {
let alias_commands = record.val
let alias_commands = record
.val
.split_whitespace()
.map(|s| s.to_string())
.collect();
Expand All @@ -63,10 +63,8 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
Err(_) => {
let value = config.get_list(&alias_name)?;
if let Some(record) = value {
let alias_commands: Vec<String> = record.val
.iter()
.map(|s| s.0.to_string())
.collect();
let alias_commands: Vec<String> =
record.val.iter().map(|s| s.0.to_string()).collect();
result = Ok(Some(alias_commands));
}
}
Expand Down Expand Up @@ -95,10 +93,10 @@ fn list_commands(config: &Config) -> BTreeSet<(String, Option<String>)> {
}
if is_executable(entry.path()) {
let end = filename.len() - suffix.len();
commands.insert(
(filename[prefix.len()..end].to_string(),
Some(path.display().to_string()))
);
commands.insert((
filename[prefix.len()..end].to_string(),
Some(path.display().to_string()),
));
}
}
}
Expand All @@ -110,7 +108,6 @@ fn list_commands(config: &Config) -> BTreeSet<(String, Option<String>)> {
commands
}


fn find_closest(config: &Config, cmd: &str) -> Option<String> {
let cmds = list_commands(config);
// Only consider candidates with a lev_distance of 3 or less so we don't
Expand All @@ -133,22 +130,23 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
Some(command) => command,
None => {
let err = match find_closest(config, cmd) {
Some(closest) => {
format_err!("no such subcommand: `{}`\n\n\tDid you mean `{}`?\n",
cmd,
closest)
}
Some(closest) => format_err!(
"no such subcommand: `{}`\n\n\tDid you mean `{}`?\n",
cmd,
closest
),
None => format_err!("no such subcommand: `{}`", cmd),
};
return Err(CliError::new(err, 101))
return Err(CliError::new(err, 101));
}
};

let cargo_exe = config.cargo_exe()?;
let err = match util::process(&command)
.env(cargo::CARGO_ENV, cargo_exe)
.args(&args[1..])
.exec_replace() {
.exec_replace()
{
Ok(()) => return Ok(()),
Err(e) => e,
};
Expand All @@ -170,7 +168,9 @@ fn is_executable<P: AsRef<Path>>(path: P) -> bool {
}
#[cfg(windows)]
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
fs::metadata(path).map(|metadata| metadata.is_file()).unwrap_or(false)
fs::metadata(path)
.map(|metadata| metadata.is_file())
.unwrap_or(false)
}

fn search_directories(config: &Config) -> Vec<PathBuf> {
Expand Down
83 changes: 43 additions & 40 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate clap;

use clap::{AppSettings, Arg, ArgMatches};

use cargo::{self, Config, CliResult};
use cargo::{self, CliResult, Config};

use super::list_commands;
use super::commands;
Expand All @@ -15,10 +15,10 @@ pub fn main(config: &mut Config) -> CliResult {
let version = cargo::version();
println!("{}", version);
if is_verbose {
println!("release: {}.{}.{}",
version.major,
version.minor,
version.patch);
println!(
"release: {}.{}.{}",
version.major, version.minor, version.patch
);
if let Some(ref cfg) = version.cfg_info {
if let Some(ref ci) = cfg.commit_info {
println!("commit-hash: {}", ci.commit_hash);
Expand Down Expand Up @@ -51,20 +51,24 @@ pub fn main(config: &mut Config) -> CliResult {
return Ok(());
}

if args.subcommand_name().is_none() {
}
if args.subcommand_name().is_none() {}

execute_subcommand(config, args)
}

fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult {
config.configure(
args.occurrences_of("verbose") as u32,
if args.is_present("quiet") { Some(true) } else { None },
if args.is_present("quiet") {
Some(true)
} else {
None
},
&args.value_of("color").map(|s| s.to_string()),
args.is_present("frozen"),
args.is_present("locked"),
&args.values_of_lossy("unstable-features").unwrap_or_default(),
&args.values_of_lossy("unstable-features")
.unwrap_or_default(),
)?;

let (cmd, args) = match args.subcommand() {
Expand All @@ -80,7 +84,11 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult {
}

if let Some(mut alias) = super::aliased_command(config, cmd)? {
alias.extend(args.values_of("").unwrap_or_default().map(|s| s.to_string()));
alias.extend(
args.values_of("")
.unwrap_or_default()
.map(|s| s.to_string()),
);
let args = cli()
.setting(AppSettings::NoBinaryName)
.get_matches_from_safe(alias)?;
Expand All @@ -91,7 +99,6 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult {
super::execute_external_subcommand(config, cmd, &ext_args)
}


fn cli() -> App {
let app = App::new("cargo")
.settings(&[
Expand All @@ -101,7 +108,8 @@ fn cli() -> App {
AppSettings::AllowExternalSubcommands,
])
.about("")
.template("\
.template(
"\
Rust's package manager
USAGE:
Expand All @@ -126,44 +134,39 @@ Some common cargo commands are (see all commands with --list):
install Install a Rust binary
uninstall Uninstall a Rust binary
See 'cargo help <command>' for more information on a specific command."
)
.arg(
opt("version", "Print version info and exit")
.short("V")
)
.arg(
opt("list", "List installed commands")
See 'cargo help <command>' for more information on a specific command.",
)
.arg(opt("version", "Print version info and exit").short("V"))
.arg(opt("list", "List installed commands"))
.arg(opt("explain", "Run `rustc --explain CODE`").value_name("CODE"))
.arg(
opt("explain", "Run `rustc --explain CODE`")
.value_name("CODE")
)
.arg(
opt("verbose", "Use verbose output (-vv very verbose/build.rs output)")
.short("v").multiple(true).global(true)
opt(
"verbose",
"Use verbose output (-vv very verbose/build.rs output)",
).short("v")
.multiple(true)
.global(true),
)
.arg(
opt("quiet", "No output printed to stdout")
.short("q").global(true)
.short("q")
.global(true),
)
.arg(
opt("color", "Coloring: auto, always, never")
.value_name("WHEN").global(true)
)
.arg(
opt("frozen", "Require Cargo.lock and cache are up to date")
.global(true)
)
.arg(
opt("locked", "Require Cargo.lock is up to date")
.global(true)
.value_name("WHEN")
.global(true),
)
.arg(opt("frozen", "Require Cargo.lock and cache are up to date").global(true))
.arg(opt("locked", "Require Cargo.lock is up to date").global(true))
.arg(
Arg::with_name("unstable-features").help("Unstable (nightly-only) flags to Cargo")
.short("Z").value_name("FLAG").multiple(true).global(true)
Arg::with_name("unstable-features")
.help("Unstable (nightly-only) flags to Cargo")
.short("Z")
.value_name("FLAG")
.multiple(true)
.global(true),
)
.subcommands(commands::builtin())
;
.subcommands(commands::builtin());
app
}
Loading

0 comments on commit 805fbeb

Please sign in to comment.