Skip to content

Commit ad065e7

Browse files
committed
Merge branch 'master' into trywithout
2 parents 4432ac3 + 9d84c0c commit ad065e7

File tree

114 files changed

+2653
-2335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2653
-2335
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ path = "src/cargo/lib.rs"
2222
atty = "0.2"
2323
bytesize = "1.0"
2424
cargo-platform = { path = "crates/cargo-platform", version = "0.1.1" }
25-
crates-io = { path = "crates/crates-io", version = "0.31" }
25+
crates-io = { path = "crates/crates-io", version = "0.31.1" }
2626
crossbeam-utils = "0.7"
2727
crypto-hash = "0.3.1"
2828
curl = { version = "0.4.23", features = ["http2"] }

crates/cargo-test-support/src/git.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ use some of the helper functions in this file to interact with the repository.
3939
*/
4040

4141
use crate::{path2url, project, Project, ProjectBuilder};
42-
use std::fs::{self, File};
43-
use std::io::prelude::*;
42+
use std::fs;
4443
use std::path::{Path, PathBuf};
4544
use url::Url;
4645

@@ -81,7 +80,7 @@ impl RepoBuilder {
8180
pub fn nocommit_file(self, path: &str, contents: &str) -> RepoBuilder {
8281
let dst = self.repo.workdir().unwrap().join(path);
8382
t!(fs::create_dir_all(dst.parent().unwrap()));
84-
t!(t!(File::create(&dst)).write_all(contents.as_bytes()));
83+
t!(fs::write(&dst, contents));
8584
self
8685
}
8786

crates/cargo-test-support/src/lib.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ use std::env;
112112
use std::ffi::OsStr;
113113
use std::fmt;
114114
use std::fs;
115-
use std::io::prelude::*;
116115
use std::os;
117116
use std::path::{Path, PathBuf};
118117
use std::process::{Command, Output};
@@ -166,11 +165,8 @@ impl FileBuilder {
166165

167166
fn mk(&self) {
168167
self.dirname().mkdir_p();
169-
170-
let mut file = fs::File::create(&self.path)
168+
fs::write(&self.path, &self.body)
171169
.unwrap_or_else(|e| panic!("could not create file {}: {}", self.path.display(), e));
172-
173-
t!(file.write_all(self.body.as_bytes()));
174170
}
175171

176172
fn dirname(&self) -> &Path {
@@ -458,25 +454,15 @@ impl Project {
458454

459455
/// Returns the contents of a path in the project root
460456
pub fn read_file(&self, path: &str) -> String {
461-
let mut buffer = String::new();
462-
fs::File::open(self.root().join(path))
463-
.unwrap()
464-
.read_to_string(&mut buffer)
465-
.unwrap();
466-
buffer
457+
let full = self.root().join(path);
458+
fs::read_to_string(&full)
459+
.unwrap_or_else(|e| panic!("could not read file {}: {}", full.display(), e))
467460
}
468461

469462
/// Modifies `Cargo.toml` to remove all commented lines.
470463
pub fn uncomment_root_manifest(&self) {
471-
let mut contents = String::new();
472-
fs::File::open(self.root().join("Cargo.toml"))
473-
.unwrap()
474-
.read_to_string(&mut contents)
475-
.unwrap();
476-
fs::File::create(self.root().join("Cargo.toml"))
477-
.unwrap()
478-
.write_all(contents.replace("#", "").as_bytes())
479-
.unwrap();
464+
let contents = self.read_file("Cargo.toml").replace("#", "");
465+
fs::write(self.root().join("Cargo.toml"), contents).unwrap();
480466
}
481467

482468
pub fn symlink(&self, src: impl AsRef<Path>, dst: impl AsRef<Path>) {

crates/cargo-test-support/src/registry.rs

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -162,36 +162,37 @@ pub struct Dependency {
162162
pub fn init() {
163163
let config = paths::home().join(".cargo/config");
164164
t!(fs::create_dir_all(config.parent().unwrap()));
165-
if fs::metadata(&config).is_ok() {
165+
if config.exists() {
166166
return;
167167
}
168-
t!(t!(File::create(&config)).write_all(
168+
t!(fs::write(
169+
&config,
169170
format!(
170171
r#"
171-
[source.crates-io]
172-
registry = 'https://wut'
173-
replace-with = 'dummy-registry'
172+
[source.crates-io]
173+
registry = 'https://wut'
174+
replace-with = 'dummy-registry'
174175
175-
[source.dummy-registry]
176-
registry = '{reg}'
176+
[source.dummy-registry]
177+
registry = '{reg}'
177178
178-
[registries.alternative]
179-
index = '{alt}'
180-
"#,
179+
[registries.alternative]
180+
index = '{alt}'
181+
"#,
181182
reg = registry_url(),
182183
alt = alt_registry_url()
183184
)
184-
.as_bytes()
185185
));
186186
let credentials = paths::home().join(".cargo/credentials");
187-
t!(t!(File::create(&credentials)).write_all(
188-
br#"
189-
[registry]
190-
token = "api-token"
191-
192-
[registries.alternative]
193-
token = "api-token"
194-
"#
187+
t!(fs::write(
188+
&credentials,
189+
r#"
190+
[registry]
191+
token = "api-token"
192+
193+
[registries.alternative]
194+
token = "api-token"
195+
"#
195196
));
196197

197198
// Initialize a new registry.
@@ -404,8 +405,7 @@ impl Package {
404405
})
405406
.collect::<Vec<_>>();
406407
let cksum = {
407-
let mut c = Vec::new();
408-
t!(t!(File::open(&self.archive_dst())).read_to_end(&mut c));
408+
let c = t!(fs::read(&self.archive_dst()));
409409
cksum(&c)
410410
};
411411
let name = if self.invalid_json {
@@ -442,10 +442,9 @@ impl Package {
442442
} else {
443443
registry_path.join(&file)
444444
};
445-
let mut prev = String::new();
446-
let _ = File::open(&dst).and_then(|mut f| f.read_to_string(&mut prev));
445+
let prev = fs::read_to_string(&dst).unwrap_or(String::new());
447446
t!(fs::create_dir_all(dst.parent().unwrap()));
448-
t!(t!(File::create(&dst)).write_all((prev + &line[..] + "\n").as_bytes()));
447+
t!(fs::write(&dst, prev + &line[..] + "\n"));
449448

450449
// Add the new file to the index.
451450
if !self.local {
@@ -474,6 +473,27 @@ impl Package {
474473
}
475474

476475
fn make_archive(&self) {
476+
let dst = self.archive_dst();
477+
t!(fs::create_dir_all(dst.parent().unwrap()));
478+
let f = t!(File::create(&dst));
479+
let mut a = Builder::new(GzEncoder::new(f, Compression::default()));
480+
481+
if !self.files.iter().any(|(name, _)| name == "Cargo.toml") {
482+
self.append_manifest(&mut a);
483+
}
484+
if self.files.is_empty() {
485+
self.append(&mut a, "src/lib.rs", "");
486+
} else {
487+
for &(ref name, ref contents) in self.files.iter() {
488+
self.append(&mut a, name, contents);
489+
}
490+
}
491+
for &(ref name, ref contents) in self.extra_files.iter() {
492+
self.append_extra(&mut a, name, contents);
493+
}
494+
}
495+
496+
fn append_manifest<W: Write>(&self, ar: &mut Builder<W>) {
477497
let mut manifest = format!(
478498
r#"
479499
[package]
@@ -509,21 +529,7 @@ impl Package {
509529
manifest.push_str("[lib]\nproc-macro = true\n");
510530
}
511531

512-
let dst = self.archive_dst();
513-
t!(fs::create_dir_all(dst.parent().unwrap()));
514-
let f = t!(File::create(&dst));
515-
let mut a = Builder::new(GzEncoder::new(f, Compression::default()));
516-
self.append(&mut a, "Cargo.toml", &manifest);
517-
if self.files.is_empty() {
518-
self.append(&mut a, "src/lib.rs", "");
519-
} else {
520-
for &(ref name, ref contents) in self.files.iter() {
521-
self.append(&mut a, name, contents);
522-
}
523-
}
524-
for &(ref name, ref contents) in self.extra_files.iter() {
525-
self.append_extra(&mut a, name, contents);
526-
}
532+
self.append(ar, "Cargo.toml", &manifest);
527533
}
528534

529535
fn append<W: Write>(&self, ar: &mut Builder<W>, file: &str, contents: &str) {

crates/crates-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crates-io"
3-
version = "0.31.0"
3+
version = "0.31.1"
44
edition = "2018"
55
authors = ["Alex Crichton <alex@alexcrichton.com>"]
66
license = "MIT OR Apache-2.0"

crates/crates-io/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ impl Registry {
139139
}
140140

141141
pub fn host_is_crates_io(&self) -> bool {
142-
Url::parse(self.host())
143-
.map(|u| u.host_str() == Some("crates.io"))
144-
.unwrap_or(false)
142+
is_url_crates_io(&self.host)
145143
}
146144

147145
pub fn add_owners(&mut self, krate: &str, owners: &[&str]) -> Result<String> {
@@ -420,3 +418,10 @@ fn reason(code: u32) -> &'static str {
420418
_ => "<unknown>",
421419
}
422420
}
421+
422+
/// Returns `true` if the host of the given URL is "crates.io".
423+
pub fn is_url_crates_io(url: &str) -> bool {
424+
Url::parse(url)
425+
.map(|u| u.host_str() == Some("crates.io"))
426+
.unwrap_or(false)
427+
}

src/bin/cargo/commands/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6565
)?;
6666

6767
if let Some(out_dir) = args.value_of_path("out-dir", config) {
68-
compile_opts.export_dir = Some(out_dir);
68+
compile_opts.build_config.export_dir = Some(out_dir);
6969
} else if let Some(out_dir) = config.build_config()?.out_dir.as_ref() {
7070
let out_dir = out_dir.resolve_path(config);
71-
compile_opts.export_dir = Some(out_dir);
71+
compile_opts.build_config.export_dir = Some(out_dir);
7272
}
73-
if compile_opts.export_dir.is_some() {
73+
if compile_opts.build_config.export_dir.is_some() {
7474
config
7575
.cli_unstable()
7676
.fail_if_stable_opt("--out-dir", 6790)?;

src/bin/cargo/commands/tree.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::cli;
12
use crate::command_prelude::*;
23
use anyhow::{bail, format_err};
34
use cargo::core::dependency::DepKind;
@@ -88,9 +89,22 @@ pub fn cli() -> App {
8889
.short("f")
8990
.default_value("{p}"),
9091
)
92+
.arg(
93+
// Backwards compatibility with old cargo-tree.
94+
Arg::with_name("version")
95+
.long("version")
96+
.short("V")
97+
.hidden(true),
98+
)
9199
}
92100

93101
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
102+
if args.is_present("version") {
103+
let verbose = args.occurrences_of("verbose") > 0;
104+
let version = cli::get_version_string(verbose);
105+
print!("{}", version);
106+
return Ok(());
107+
}
94108
let prefix = if args.is_present("no-indent") {
95109
config
96110
.shell()
@@ -106,12 +120,13 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
106120
};
107121
let prefix = tree::Prefix::from_str(prefix).map_err(|e| anyhow::anyhow!("{}", e))?;
108122

123+
let no_dedupe = args.is_present("no-dedupe") || args.is_present("all");
109124
if args.is_present("all") {
110-
return Err(format_err!(
111-
"The `cargo tree` --all flag has been changed to --no-dedupe.\n\
112-
If you are looking to display all workspace members, use the --workspace flag."
113-
)
114-
.into());
125+
config.shell().warn(
126+
"The `cargo tree` --all flag has been changed to --no-dedupe, \
127+
and may be removed in a future version.\n\
128+
If you are looking to display all workspace members, use the --workspace flag.",
129+
)?;
115130
}
116131

117132
let target = if args.is_present("all-targets") {
@@ -170,7 +185,7 @@ subtree of the package given to -p.\n\
170185
edge_kinds,
171186
invert,
172187
prefix,
173-
no_dedupe: args.is_present("no-dedupe"),
188+
no_dedupe,
174189
duplicates: args.is_present("duplicates"),
175190
charset,
176191
format: args.value_of("format").unwrap().to_string(),

src/bin/cargo/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ fn is_executable<P: AsRef<Path>>(path: P) -> bool {
165165
}
166166
#[cfg(windows)]
167167
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
168-
fs::metadata(path)
169-
.map(|metadata| metadata.is_file())
170-
.unwrap_or(false)
168+
path.as_ref().is_file()
171169
}
172170

173171
fn search_directories(config: &Config) -> Vec<PathBuf> {

src/cargo/core/compiler/build_config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::util::ProcessBuilder;
44
use crate::util::{CargoResult, Config, RustfixDiagnosticServer};
55
use serde::ser;
66
use std::cell::RefCell;
7+
use std::path::PathBuf;
78

89
/// Configuration information for a rustc build.
910
#[derive(Debug)]
@@ -26,7 +27,15 @@ pub struct BuildConfig {
2627
pub unit_graph: bool,
2728
/// An optional override of the rustc process for primary units
2829
pub primary_unit_rustc: Option<ProcessBuilder>,
30+
/// A thread used by `cargo fix` to receive messages on a socket regarding
31+
/// the success/failure of applying fixes.
2932
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
33+
/// The directory to copy final artifacts to. Note that even if `out_dir` is
34+
/// set, a copy of artifacts still could be found a `target/(debug\release)`
35+
/// as usual.
36+
// Note that, although the cmd-line flag name is `out-dir`, in code we use
37+
// `export_dir`, to avoid confusion with out dir at `target/debug/deps`.
38+
pub export_dir: Option<PathBuf>,
3039
}
3140

3241
impl BuildConfig {
@@ -70,6 +79,7 @@ impl BuildConfig {
7079
unit_graph: false,
7180
primary_unit_rustc: None,
7281
rustfix_diagnostic_server: RefCell::new(None),
82+
export_dir: None,
7383
})
7484
}
7585

0 commit comments

Comments
 (0)