mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
$cargo fmt --all
This commit is contained in:
parent
e86afe2efa
commit
db09895f3c
@ -50,8 +50,11 @@ the `cargo help pkgid` command.
|
||||
|
||||
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
||||
let ws = args.workspace(config)?;
|
||||
let mut compile_opts =
|
||||
args.compile_options_for_single_package(config, CompileMode::Doc { deps: false }, Some(&ws))?;
|
||||
let mut compile_opts = args.compile_options_for_single_package(
|
||||
config,
|
||||
CompileMode::Doc { deps: false },
|
||||
Some(&ws),
|
||||
)?;
|
||||
let target_args = values(args, "args");
|
||||
compile_opts.target_rustdoc_args = if target_args.is_empty() {
|
||||
None
|
||||
|
@ -4,8 +4,8 @@ use std::fmt::{self, Formatter};
|
||||
use std::hash::{self, Hash};
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use log::trace;
|
||||
|
@ -2,7 +2,7 @@ use std::collections::BTreeMap;
|
||||
use std::env;
|
||||
use std::fmt;
|
||||
use std::fs;
|
||||
use std::io::{BufReader, BufRead, ErrorKind};
|
||||
use std::io::{BufRead, BufReader, ErrorKind};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use git2::Config as GitConfig;
|
||||
@ -410,7 +410,6 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
/// IgnoreList
|
||||
struct IgnoreList {
|
||||
/// git like formatted entries
|
||||
@ -428,7 +427,7 @@ impl IgnoreList {
|
||||
}
|
||||
}
|
||||
|
||||
/// add a new entry to the ignore list. Requires two arguments with the
|
||||
/// add a new entry to the ignore list. Requires two arguments with the
|
||||
/// entry in two different formats. One for "git style" entries and one for
|
||||
/// "mercurial like" entries.
|
||||
fn push(&mut self, ignore: &str, hg_ignore: &str) {
|
||||
@ -451,23 +450,23 @@ impl IgnoreList {
|
||||
/// file.
|
||||
fn format_existing<T: BufRead>(&self, existing: T, vcs: VersionControl) -> String {
|
||||
// TODO: is unwrap safe?
|
||||
let existing_items = existing.lines().collect::<Result<Vec<_>, _>>().unwrap();
|
||||
let existing_items = existing.lines().collect::<Result<Vec<_>, _>>().unwrap();
|
||||
|
||||
let ignore_items = match vcs {
|
||||
VersionControl::Hg => &self.hg_ignore,
|
||||
_ => &self.ignore,
|
||||
let ignore_items = match vcs {
|
||||
VersionControl::Hg => &self.hg_ignore,
|
||||
_ => &self.ignore,
|
||||
};
|
||||
|
||||
let mut out = "\n\n#Added by cargo\n\
|
||||
#\n\
|
||||
#already existing elements are commented out\n".
|
||||
to_string();
|
||||
#\n\
|
||||
#already existing elements are commented out\n"
|
||||
.to_string();
|
||||
|
||||
for item in ignore_items {
|
||||
out.push('\n');
|
||||
if existing_items.contains(item) {
|
||||
out.push('#');
|
||||
}
|
||||
}
|
||||
out.push_str(item)
|
||||
}
|
||||
|
||||
@ -478,25 +477,25 @@ impl IgnoreList {
|
||||
/// write the ignore file to the given directory. If the ignore file for the
|
||||
/// given vcs system already exists, its content is read and duplicate ignore
|
||||
/// file entries are filtered out.
|
||||
fn write_ignore_file(base_path: &Path, list: &IgnoreList, vcs: VersionControl) -> CargoResult<String>{
|
||||
fn write_ignore_file(
|
||||
base_path: &Path,
|
||||
list: &IgnoreList,
|
||||
vcs: VersionControl,
|
||||
) -> CargoResult<String> {
|
||||
let fp_ignore = match vcs {
|
||||
VersionControl::Git => base_path.join(".gitignore"),
|
||||
VersionControl::Hg => base_path.join(".hgignore"),
|
||||
VersionControl::Pijul => base_path.join(".ignore"),
|
||||
VersionControl::Hg => base_path.join(".hgignore"),
|
||||
VersionControl::Pijul => base_path.join(".ignore"),
|
||||
VersionControl::Fossil => return Ok("".to_string()),
|
||||
VersionControl::NoVcs => return Ok("".to_string()),
|
||||
VersionControl::NoVcs => return Ok("".to_string()),
|
||||
};
|
||||
|
||||
let ignore: String = match fs::File::open(&fp_ignore) {
|
||||
Err(why) => {
|
||||
match why.kind() {
|
||||
ErrorKind::NotFound => list.format_new(vcs),
|
||||
_ => return Err(failure::format_err!("{}", why)),
|
||||
}
|
||||
},
|
||||
Ok(file) => {
|
||||
list.format_existing(BufReader::new(file), vcs)
|
||||
Err(why) => match why.kind() {
|
||||
ErrorKind::NotFound => list.format_new(vcs),
|
||||
_ => return Err(failure::format_err!("{}", why)),
|
||||
},
|
||||
Ok(file) => list.format_existing(BufReader::new(file), vcs),
|
||||
};
|
||||
|
||||
paths::append(&fp_ignore, ignore.as_bytes())?;
|
||||
@ -540,7 +539,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
|
||||
let name = opts.name;
|
||||
let cfg = global_config(config)?;
|
||||
|
||||
|
||||
// using the push method with two arguments ensures that the entries for
|
||||
// both ignore and hgignore are in sync.
|
||||
let mut ignore = IgnoreList::new();
|
||||
@ -562,7 +560,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
|
||||
init_vcs(path, vcs, config)?;
|
||||
write_ignore_file(path, &ignore, vcs)?;
|
||||
|
||||
|
||||
let (author_name, email) = discover_author()?;
|
||||
// Hoo boy, sure glad we've got exhaustiveness checking behind us.
|
||||
let author = match (cfg.name, cfg.email, author_name, email) {
|
||||
|
@ -337,8 +337,8 @@ pub fn process_error(
|
||||
|
||||
#[cfg(windows)]
|
||||
fn status_to_string(status: ExitStatus) -> String {
|
||||
use winapi::um::winnt::*;
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::um::winnt::*;
|
||||
|
||||
let mut base = status.to_string();
|
||||
let extra = match status.code().unwrap() as DWORD {
|
||||
|
@ -28,7 +28,7 @@ pub struct ProcessBuilder {
|
||||
/// [jobserver_docs]: https://docs.rs/jobserver/0.1.6/jobserver/
|
||||
jobserver: Option<Client>,
|
||||
/// Whether to include environment variable in display
|
||||
display_env_vars: bool
|
||||
display_env_vars: bool,
|
||||
}
|
||||
|
||||
impl fmt::Display for ProcessBuilder {
|
||||
|
@ -661,7 +661,7 @@ fn toml_targets_and_inferred(
|
||||
|
||||
let autodiscover = match autodiscover {
|
||||
Some(autodiscover) => autodiscover,
|
||||
None =>
|
||||
None => {
|
||||
if edition == Edition::Edition2015 {
|
||||
if !rem_targets.is_empty() {
|
||||
let mut rem_targets_str = String::new();
|
||||
@ -696,6 +696,7 @@ https://github.com/rust-lang/cargo/issues/5330",
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if autodiscover {
|
||||
|
@ -1118,9 +1118,7 @@ fn unknown_registry() {
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
Package::new("baz", "0.0.1")
|
||||
.alternative(true)
|
||||
.publish();
|
||||
Package::new("baz", "0.0.1").alternative(true).publish();
|
||||
Package::new("bar", "0.0.1")
|
||||
.registry_dep("baz", "0.0.1")
|
||||
.publish();
|
||||
@ -1134,16 +1132,15 @@ fn unknown_registry() {
|
||||
config.insert(start + start_index, '#');
|
||||
fs::write(&cfg_path, config).unwrap();
|
||||
|
||||
p.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.run();
|
||||
p.cargo("build").masquerade_as_nightly_cargo().run();
|
||||
|
||||
// Important parts:
|
||||
// foo -> bar registry = null
|
||||
// bar -> baz registry = alternate
|
||||
p.cargo("metadata --format-version=1")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_json(r#"
|
||||
.with_json(
|
||||
r#"
|
||||
{
|
||||
"packages": [
|
||||
{
|
||||
@ -1244,6 +1241,7 @@ fn unknown_registry() {
|
||||
"version": 1,
|
||||
"workspace_root": "[..]/foo"
|
||||
}
|
||||
"#)
|
||||
"#,
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
@ -1584,11 +1584,10 @@ fn vv_prints_rustc_env_vars() {
|
||||
r#"[RUNNING] `[..]set CARGO_PKG_AUTHORS="escape='\"@example.com"&& [..]rustc [..]`"#
|
||||
)
|
||||
} else {
|
||||
b.with_stderr_contains(
|
||||
"[RUNNING] `[..]CARGO_PKG_NAME=foo [..]rustc [..]`"
|
||||
).with_stderr_contains(
|
||||
r#"[RUNNING] `[..]CARGO_PKG_AUTHORS='escape='\''"@example.com' [..]rustc [..]`"#
|
||||
)
|
||||
b.with_stderr_contains("[RUNNING] `[..]CARGO_PKG_NAME=foo [..]rustc [..]`")
|
||||
.with_stderr_contains(
|
||||
r#"[RUNNING] `[..]CARGO_PKG_AUTHORS='escape='\''"@example.com' [..]rustc [..]`"#,
|
||||
)
|
||||
};
|
||||
|
||||
b.run();
|
||||
|
@ -1263,8 +1263,14 @@ fn fix_to_broken_code() {
|
||||
fn fix_with_common() {
|
||||
let p = project()
|
||||
.file("src/lib.rs", "")
|
||||
.file("tests/t1.rs", "mod common; #[test] fn t1() { common::try(); }")
|
||||
.file("tests/t2.rs", "mod common; #[test] fn t2() { common::try(); }")
|
||||
.file(
|
||||
"tests/t1.rs",
|
||||
"mod common; #[test] fn t1() { common::try(); }",
|
||||
)
|
||||
.file(
|
||||
"tests/t2.rs",
|
||||
"mod common; #[test] fn t2() { common::try(); }",
|
||||
)
|
||||
.file("tests/common/mod.rs", "pub fn try() {}")
|
||||
.build();
|
||||
|
||||
|
@ -49,7 +49,9 @@ fn simple_git_ignore_exists() {
|
||||
// write a .gitignore file with one entry
|
||||
fs::create_dir_all(paths::root().join("foo")).unwrap();
|
||||
let mut ignore_file = File::create(paths::root().join("foo/.gitignore")).unwrap();
|
||||
ignore_file.write("/target\n**/some.file".as_bytes()).unwrap();
|
||||
ignore_file
|
||||
.write("/target\n**/some.file".as_bytes())
|
||||
.unwrap();
|
||||
|
||||
cargo_process("init --lib foo --edition 2015")
|
||||
.env("USER", "foo")
|
||||
@ -70,14 +72,14 @@ fn simple_git_ignore_exists() {
|
||||
assert_eq!(
|
||||
contents,
|
||||
"/target\n\
|
||||
**/some.file\n\n\
|
||||
#Added by cargo\n\
|
||||
#\n\
|
||||
#already existing elements are commented out\n\
|
||||
\n\
|
||||
#/target\n\
|
||||
**/*.rs.bk\n\
|
||||
Cargo.lock",
|
||||
**/some.file\n\n\
|
||||
#Added by cargo\n\
|
||||
#\n\
|
||||
#already existing elements are commented out\n\
|
||||
\n\
|
||||
#/target\n\
|
||||
**/*.rs.bk\n\
|
||||
Cargo.lock",
|
||||
);
|
||||
|
||||
cargo_process("build").cwd(&paths::root().join("foo")).run();
|
||||
|
@ -1598,7 +1598,8 @@ fn metadata_links() {
|
||||
.build();
|
||||
|
||||
p.cargo("metadata")
|
||||
.with_json(r#"
|
||||
.with_json(
|
||||
r#"
|
||||
{
|
||||
"packages": [
|
||||
{
|
||||
@ -1664,6 +1665,7 @@ fn metadata_links() {
|
||||
],
|
||||
"workspace_root": "[..]/foo"
|
||||
}
|
||||
"#)
|
||||
"#,
|
||||
)
|
||||
.run()
|
||||
}
|
||||
|
@ -89,15 +89,11 @@ fn simple_git() {
|
||||
.unwrap()
|
||||
.read_to_string(&mut contents)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
contents,
|
||||
"/target\n**/*.rs.bk\nCargo.lock",
|
||||
);
|
||||
assert_eq!(contents, "/target\n**/*.rs.bk\nCargo.lock",);
|
||||
|
||||
cargo_process("build").cwd(&paths::root().join("foo")).run();
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn no_argument() {
|
||||
cargo_process("new")
|
||||
|
@ -1254,12 +1254,14 @@ fn package_with_select_features() {
|
||||
required = []
|
||||
optional = []
|
||||
"#,
|
||||
).file(
|
||||
)
|
||||
.file(
|
||||
"src/main.rs",
|
||||
"#[cfg(not(feature = \"required\"))]
|
||||
compile_error!(\"This crate requires `required` feature!\");
|
||||
fn main() {}",
|
||||
).build();
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("package --features required")
|
||||
.masquerade_as_nightly_cargo()
|
||||
@ -1284,12 +1286,14 @@ fn package_with_all_features() {
|
||||
required = []
|
||||
optional = []
|
||||
"#,
|
||||
).file(
|
||||
)
|
||||
.file(
|
||||
"src/main.rs",
|
||||
"#[cfg(not(feature = \"required\"))]
|
||||
compile_error!(\"This crate requires `required` feature!\");
|
||||
fn main() {}",
|
||||
).build();
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("package --all-features")
|
||||
.masquerade_as_nightly_cargo()
|
||||
@ -1314,12 +1318,14 @@ fn package_no_default_features() {
|
||||
default = ["required"]
|
||||
required = []
|
||||
"#,
|
||||
).file(
|
||||
)
|
||||
.file(
|
||||
"src/main.rs",
|
||||
"#[cfg(not(feature = \"required\"))]
|
||||
compile_error!(\"This crate requires `required` feature!\");
|
||||
fn main() {}",
|
||||
).build();
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("package --no-default-features")
|
||||
.masquerade_as_nightly_cargo()
|
||||
|
@ -3,8 +3,8 @@ use std::fs::File;
|
||||
use std::io::{prelude::*, SeekFrom};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::support::registry::{self, alt_api_path};
|
||||
use crate::support::find_json_mismatch;
|
||||
use crate::support::registry::{self, alt_api_path};
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use flate2::read::GzDecoder;
|
||||
|
@ -186,7 +186,6 @@ pub fn init() {
|
||||
"#
|
||||
));
|
||||
|
||||
|
||||
// Init a new registry
|
||||
let _ = repo(®istry_path())
|
||||
.file(
|
||||
|
Loading…
x
Reference in New Issue
Block a user