Skip to content

Commit aa7e623

Browse files
Merge branch 'master' into nocapture_test_msg
2 parents e976813 + 211fd7e commit aa7e623

Some content is hidden

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

74 files changed

+621
-286
lines changed

Cargo.lock

Lines changed: 160 additions & 116 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ crates-io = { version = "0.38.0", path = "crates/crates-io" }
3434
criterion = { version = "0.5.1", features = ["html_reports"] }
3535
curl = "0.4.44"
3636
curl-sys = "0.4.65"
37-
env_logger = "0.10.0"
3837
filetime = "0.2.21"
3938
flate2 = { version = "1.0.26", default-features = false, features = ["zlib"] }
4039
fwdansi = "1.1.0"
@@ -58,9 +57,8 @@ lazy_static = "1.4.0"
5857
lazycell = "1.3.0"
5958
libc = "0.2.147"
6059
libgit2-sys = "0.15.2"
61-
log = "0.4.19"
6260
memchr = "2.5.0"
63-
miow = "0.5.0"
61+
miow = "0.6.0"
6462
opener = "0.6.1"
6563
openssl ="0.10.55"
6664
os_info = "3.7.0"
@@ -69,7 +67,6 @@ pathdiff = "0.2"
6967
percent-encoding = "2.3"
7068
pkg-config = "0.3.27"
7169
pretty_assertions = "1.4.0"
72-
pretty_env_logger = "0.5.0"
7370
proptest = "1.2.0"
7471
pulldown-cmark = { version = "0.9.3", default-features = false }
7572
rand = "0.8.5"
@@ -94,6 +91,8 @@ thiserror = "1.0.44"
9491
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
9592
toml = "0.7.6"
9693
toml_edit = "0.19.14"
94+
tracing = "0.1.37"
95+
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
9796
unicase = "2.6.0"
9897
unicode-width = "0.1.10"
9998
unicode-xid = "0.2.4"
@@ -132,7 +131,6 @@ clap = { workspace = true, features = ["wrap_help"] }
132131
crates-io.workspace = true
133132
curl = { workspace = true, features = ["http2"] }
134133
curl-sys.workspace = true
135-
env_logger.workspace = true
136134
filetime.workspace = true
137135
flate2.workspace = true
138136
git2.workspace = true
@@ -153,13 +151,11 @@ jobserver.workspace = true
153151
lazycell.workspace = true
154152
libc.workspace = true
155153
libgit2-sys.workspace = true
156-
log.workspace = true
157154
memchr.workspace = true
158155
opener.workspace = true
159156
os_info.workspace = true
160157
pasetors.workspace = true
161158
pathdiff.workspace = true
162-
pretty_env_logger = { workspace = true, optional = true }
163159
pulldown-cmark.workspace = true
164160
rand.workspace = true
165161
rustfix.workspace = true
@@ -178,6 +174,8 @@ termcolor.workspace = true
178174
time.workspace = true
179175
toml.workspace = true
180176
toml_edit.workspace = true
177+
tracing.workspace = true
178+
tracing-subscriber.workspace = true
181179
unicase.workspace = true
182180
unicode-width.workspace = true
183181
unicode-xid.workspace = true
@@ -218,6 +216,5 @@ doc = false
218216
[features]
219217
vendored-openssl = ["openssl/vendored"]
220218
vendored-libgit2 = ["libgit2-sys/vendored"]
221-
pretty-env-logger = ["pretty_env_logger"]
222219
# This is primarily used by rust-lang/rust distributing cargo the executable.
223220
all-static = ['vendored-openssl', 'curl/static-curl', 'curl/force-system-lib-on-osx']

crates/cargo-util/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ filetime.workspace = true
1414
hex.workspace = true
1515
jobserver.workspace = true
1616
libc.workspace = true
17-
log.workspace = true
1817
same-file.workspace = true
1918
shell-escape.workspace = true
2019
tempfile.workspace = true
20+
tracing.workspace = true
2121
walkdir.workspace = true
2222

2323
[target.'cfg(target_os = "macos")'.dependencies]

crates/cargo-util/src/paths.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
237237
Err(e) => {
238238
// Ignore errors while walking. If Cargo can't access it, the
239239
// build script probably can't access it, either.
240-
log::debug!("failed to determine mtime while walking directory: {}", e);
240+
tracing::debug!("failed to determine mtime while walking directory: {}", e);
241241
None
242242
}
243243
})
@@ -252,7 +252,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
252252
// I'm not sure when this is really possible (maybe a
253253
// race with unlinking?). Regardless, if Cargo can't
254254
// read it, the build script probably can't either.
255-
log::debug!(
255+
tracing::debug!(
256256
"failed to determine mtime while fetching symlink metadata of {}: {}",
257257
e.path().display(),
258258
err
@@ -271,7 +271,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
271271
// Can't access the symlink target. If Cargo can't
272272
// access it, the build script probably can't access
273273
// it either.
274-
log::debug!(
274+
tracing::debug!(
275275
"failed to determine mtime of symlink target for {}: {}",
276276
e.path().display(),
277277
err
@@ -286,7 +286,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
286286
// I'm not sure when this is really possible (maybe a
287287
// race with unlinking?). Regardless, if Cargo can't
288288
// read it, the build script probably can't either.
289-
log::debug!(
289+
tracing::debug!(
290290
"failed to determine mtime while fetching metadata of {}: {}",
291291
e.path().display(),
292292
err
@@ -314,7 +314,7 @@ pub fn set_invocation_time(path: &Path) -> Result<FileTime> {
314314
"This file has an mtime of when this was started.",
315315
)?;
316316
let ft = mtime(&timestamp)?;
317-
log::debug!("invocation time for {:?} is {}", path, ft);
317+
tracing::debug!("invocation time for {:?} is {}", path, ft);
318318
Ok(ft)
319319
}
320320

@@ -508,7 +508,7 @@ pub fn link_or_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()>
508508
}
509509

510510
fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
511-
log::debug!("linking {} to {}", src.display(), dst.display());
511+
tracing::debug!("linking {} to {}", src.display(), dst.display());
512512
if same_file::is_same_file(src, dst).unwrap_or(false) {
513513
return Ok(());
514514
}
@@ -567,7 +567,7 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
567567
};
568568
link_result
569569
.or_else(|err| {
570-
log::debug!("link failed {}. falling back to fs::copy", err);
570+
tracing::debug!("link failed {}. falling back to fs::copy", err);
571571
fs::copy(src, dst).map(|_| ())
572572
})
573573
.with_context(|| {
@@ -598,8 +598,8 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
598598
pub fn set_file_time_no_err<P: AsRef<Path>>(path: P, time: FileTime) {
599599
let path = path.as_ref();
600600
match filetime::set_file_times(path, time, time) {
601-
Ok(()) => log::debug!("set file mtime {} to {}", path.display(), time),
602-
Err(e) => log::warn!(
601+
Ok(()) => tracing::debug!("set file mtime {} to {}", path.display(), time),
602+
Err(e) => tracing::warn!(
603603
"could not set mtime of {} to {}: {:?}",
604604
path.display(),
605605
time,
@@ -621,7 +621,7 @@ pub fn strip_prefix_canonical<P: AsRef<Path>>(
621621
let safe_canonicalize = |path: &Path| match path.canonicalize() {
622622
Ok(p) => p,
623623
Err(e) => {
624-
log::warn!("cannot canonicalize {:?}: {:?}", path, e);
624+
tracing::warn!("cannot canonicalize {:?}: {:?}", path, e);
625625
path.to_path_buf()
626626
}
627627
};

crates/cargo-util/src/process_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl ProcessBuilder {
449449
arg.push(tmp.path());
450450
let mut cmd = self.build_command_without_args();
451451
cmd.arg(arg);
452-
log::debug!("created argfile at {} for {self}", tmp.path().display());
452+
tracing::debug!("created argfile at {} for {self}", tmp.path().display());
453453

454454
let cap = self.get_args().map(|arg| arg.len() + 1).sum::<usize>();
455455
let mut buf = Vec::with_capacity(cap);
@@ -558,7 +558,7 @@ fn piped(cmd: &mut Command, pipe_stdin: bool) -> &mut Command {
558558

559559
fn close_tempfile_and_log_error(file: NamedTempFile) {
560560
file.close().unwrap_or_else(|e| {
561-
log::warn!("failed to close temporary file: {e}");
561+
tracing::warn!("failed to close temporary file: {e}");
562562
});
563563
}
564564

crates/xtask-bump-check/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ anyhow.workspace = true
99
cargo.workspace = true
1010
cargo-util.workspace = true
1111
clap.workspace = true
12-
env_logger.workspace = true
1312
git2.workspace = true
14-
log.workspace = true
13+
tracing.workspace = true
14+
tracing-subscriber.workspace = true

crates/xtask-bump-check/src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
mod xtask;
22

33
fn main() {
4-
env_logger::init_from_env("CARGO_LOG");
4+
setup_logger();
5+
56
let cli = xtask::cli();
67
let matches = cli.get_matches();
78

@@ -13,3 +14,13 @@ fn main() {
1314
cargo::exit_with_error(e, &mut config.shell())
1415
}
1516
}
17+
18+
// In sync with `src/bin/cargo/main.rs@setup_logger`.
19+
fn setup_logger() {
20+
let env = tracing_subscriber::EnvFilter::from_env("CARGO_LOG");
21+
22+
tracing_subscriber::fmt()
23+
.with_writer(std::io::stderr)
24+
.with_env_filter(env)
25+
.init();
26+
}

crates/xtask-bump-check/src/xtask.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn bump_check(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> Carg
126126
for referenced_member in checkout_ws(&ws, &repo, referenced_commit)?.members() {
127127
let Some(changed_member) = changed_members.get(referenced_member) else {
128128
let name = referenced_member.name().as_str();
129-
log::trace!("skipping {name}, may be removed or not published");
129+
tracing::trace!("skipping {name}, may be removed or not published");
130130
continue;
131131
};
132132

@@ -264,10 +264,10 @@ fn get_referenced_commit<'a>(
264264
let referenced_commit = if rev_id == stable_commit.id() {
265265
None
266266
} else if rev_id == beta_commit.id() {
267-
log::trace!("stable branch from `{}`", stable.name().unwrap().unwrap());
267+
tracing::trace!("stable branch from `{}`", stable.name().unwrap().unwrap());
268268
Some(stable_commit)
269269
} else {
270-
log::trace!("beta branch from `{}`", beta.name().unwrap().unwrap());
270+
tracing::trace!("beta branch from `{}`", beta.name().unwrap().unwrap());
271271
Some(beta_commit)
272272
};
273273

@@ -287,11 +287,11 @@ fn beta_and_stable_branch(repo: &git2::Repository) -> CargoResult<[git2::Branch<
287287
let (branch, _) = branch?;
288288
let name = branch.name()?.unwrap();
289289
let Some((_, version)) = name.split_once("/rust-") else {
290-
log::trace!("branch `{name}` is not in the format of `<remote>/rust-<semver>`");
290+
tracing::trace!("branch `{name}` is not in the format of `<remote>/rust-<semver>`");
291291
continue;
292292
};
293293
let Ok(version) = version.to_semver() else {
294-
log::trace!("branch `{name}` is not a valid semver: `{version}`");
294+
tracing::trace!("branch `{name}` is not a valid semver: `{version}`");
295295
continue;
296296
};
297297
release_branches.push((version, branch));
@@ -380,7 +380,7 @@ fn check_crates_io<'a>(
380380
}
381381
};
382382
if possibilities.is_empty() {
383-
log::trace!("dep `{name}` has no version greater than or equal to `{current}`");
383+
tracing::trace!("dep `{name}` has no version greater than or equal to `{current}`");
384384
} else {
385385
needs_bump.push(member);
386386
}

credential/cargo-credential/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ serde = { workspace = true, features = ["derive"] }
1212
serde_json.workspace = true
1313
thiserror.workspace = true
1414
time.workspace = true
15+
16+
[dev-dependencies]
17+
snapbox = { workspace = true, features = ["examples"] }
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//! Example credential provider that stores credentials in a JSON file.
2+
//! This is not secure
3+
4+
use cargo_credential::{
5+
Action, CacheControl, Credential, CredentialResponse, RegistryInfo, Secret,
6+
};
7+
use std::{collections::HashMap, fs::File, io::ErrorKind};
8+
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
9+
10+
struct FileCredential;
11+
12+
impl Credential for FileCredential {
13+
fn perform(
14+
&self,
15+
registry: &RegistryInfo,
16+
action: &Action,
17+
_args: &[&str],
18+
) -> Result<CredentialResponse, cargo_credential::Error> {
19+
if registry.index_url != "https://github.com/rust-lang/crates.io-index" {
20+
// Restrict this provider to only work for crates.io. Cargo will skip it and attempt
21+
// another provider for any other registry.
22+
//
23+
// If a provider supports any registry, then this check should be omitted.
24+
return Err(cargo_credential::Error::UrlNotSupported);
25+
}
26+
27+
// `Error::Other` takes a boxed `std::error::Error` type that causes Cargo to show the error.
28+
let mut creds = FileCredential::read().map_err(cargo_credential::Error::Other)?;
29+
30+
match action {
31+
Action::Get(_) => {
32+
// Cargo requested a token, look it up.
33+
if let Some(token) = creds.get(registry.index_url) {
34+
Ok(CredentialResponse::Get {
35+
token: token.clone(),
36+
cache: CacheControl::Session,
37+
operation_independent: true,
38+
})
39+
} else {
40+
// Credential providers should respond with `NotFound` when a credential can not be
41+
// found, allowing Cargo to attempt another provider.
42+
Err(cargo_credential::Error::NotFound)
43+
}
44+
}
45+
Action::Login(login_options) => {
46+
// The token for `cargo login` can come from the `login_options` parameter or i
47+
// interactively reading from stdin.
48+
//
49+
// `cargo_credential::read_token` automatically handles this.
50+
let token = cargo_credential::read_token(login_options, registry)?;
51+
creds.insert(registry.index_url.to_string(), token);
52+
53+
FileCredential::write(&creds).map_err(cargo_credential::Error::Other)?;
54+
55+
// Credentials were successfully stored.
56+
Ok(CredentialResponse::Login)
57+
}
58+
Action::Logout => {
59+
if creds.remove(registry.index_url).is_none() {
60+
// If the user attempts to log out from a registry that has no credentials
61+
// stored, then NotFound is the appropriate error.
62+
Err(cargo_credential::Error::NotFound)
63+
} else {
64+
// Credentials were successfully erased.
65+
Ok(CredentialResponse::Logout)
66+
}
67+
}
68+
// If a credential provider doesn't support a given operation, it should respond with `OperationNotSupported`.
69+
_ => Err(cargo_credential::Error::OperationNotSupported),
70+
}
71+
}
72+
}
73+
74+
impl FileCredential {
75+
fn read() -> Result<HashMap<String, Secret<String>>, Error> {
76+
match File::open("cargo-credentials.json") {
77+
Ok(f) => Ok(serde_json::from_reader(f)?),
78+
Err(e) if e.kind() == ErrorKind::NotFound => Ok(HashMap::new()),
79+
Err(e) => Err(e)?,
80+
}
81+
}
82+
fn write(value: &HashMap<String, Secret<String>>) -> Result<(), Error> {
83+
let file = File::create("cargo-credentials.json")?;
84+
Ok(serde_json::to_writer_pretty(file, value)?)
85+
}
86+
}
87+
88+
fn main() {
89+
cargo_credential::main(FileCredential);
90+
}

0 commit comments

Comments
 (0)