Skip to content

Commit

Permalink
Merge branch 'master' into nocapture_test_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
stupendoussuperpowers authored Aug 8, 2023
2 parents 294a589 + 2b3554f commit 1509634
Show file tree
Hide file tree
Showing 144 changed files with 1,667 additions and 1,071 deletions.
276 changes: 160 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ crates-io = { version = "0.38.0", path = "crates/crates-io" }
criterion = { version = "0.5.1", features = ["html_reports"] }
curl = "0.4.44"
curl-sys = "0.4.65"
env_logger = "0.10.0"
filetime = "0.2.21"
flate2 = { version = "1.0.26", default-features = false, features = ["zlib"] }
fwdansi = "1.1.0"
Expand All @@ -58,9 +57,8 @@ lazy_static = "1.4.0"
lazycell = "1.3.0"
libc = "0.2.147"
libgit2-sys = "0.15.2"
log = "0.4.19"
memchr = "2.5.0"
miow = "0.5.0"
miow = "0.6.0"
opener = "0.6.1"
openssl ="0.10.55"
os_info = "3.7.0"
Expand All @@ -69,7 +67,6 @@ pathdiff = "0.2"
percent-encoding = "2.3"
pkg-config = "0.3.27"
pretty_assertions = "1.4.0"
pretty_env_logger = "0.5.0"
proptest = "1.2.0"
pulldown-cmark = { version = "0.9.3", default-features = false }
rand = "0.8.5"
Expand All @@ -94,6 +91,8 @@ thiserror = "1.0.44"
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
toml = "0.7.6"
toml_edit = "0.19.14"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
unicase = "2.6.0"
unicode-width = "0.1.10"
unicode-xid = "0.2.4"
Expand Down Expand Up @@ -132,7 +131,6 @@ clap = { workspace = true, features = ["wrap_help"] }
crates-io.workspace = true
curl = { workspace = true, features = ["http2"] }
curl-sys.workspace = true
env_logger.workspace = true
filetime.workspace = true
flate2.workspace = true
git2.workspace = true
Expand All @@ -153,13 +151,11 @@ jobserver.workspace = true
lazycell.workspace = true
libc.workspace = true
libgit2-sys.workspace = true
log.workspace = true
memchr.workspace = true
opener.workspace = true
os_info.workspace = true
pasetors.workspace = true
pathdiff.workspace = true
pretty_env_logger = { workspace = true, optional = true }
pulldown-cmark.workspace = true
rand.workspace = true
rustfix.workspace = true
Expand All @@ -178,6 +174,8 @@ termcolor.workspace = true
time.workspace = true
toml.workspace = true
toml_edit.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
unicase.workspace = true
unicode-width.workspace = true
unicode-xid.workspace = true
Expand Down Expand Up @@ -218,6 +216,5 @@ doc = false
[features]
vendored-openssl = ["openssl/vendored"]
vendored-libgit2 = ["libgit2-sys/vendored"]
pretty-env-logger = ["pretty_env_logger"]
# This is primarily used by rust-lang/rust distributing cargo the executable.
all-static = ['vendored-openssl', 'curl/static-curl', 'curl/force-system-lib-on-osx']
2 changes: 1 addition & 1 deletion crates/cargo-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ filetime.workspace = true
hex.workspace = true
jobserver.workspace = true
libc.workspace = true
log.workspace = true
same-file.workspace = true
shell-escape.workspace = true
tempfile.workspace = true
tracing.workspace = true
walkdir.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
20 changes: 10 additions & 10 deletions crates/cargo-util/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
Err(e) => {
// Ignore errors while walking. If Cargo can't access it, the
// build script probably can't access it, either.
log::debug!("failed to determine mtime while walking directory: {}", e);
tracing::debug!("failed to determine mtime while walking directory: {}", e);
None
}
})
Expand All @@ -252,7 +252,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
// I'm not sure when this is really possible (maybe a
// race with unlinking?). Regardless, if Cargo can't
// read it, the build script probably can't either.
log::debug!(
tracing::debug!(
"failed to determine mtime while fetching symlink metadata of {}: {}",
e.path().display(),
err
Expand All @@ -271,7 +271,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
// Can't access the symlink target. If Cargo can't
// access it, the build script probably can't access
// it either.
log::debug!(
tracing::debug!(
"failed to determine mtime of symlink target for {}: {}",
e.path().display(),
err
Expand All @@ -286,7 +286,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
// I'm not sure when this is really possible (maybe a
// race with unlinking?). Regardless, if Cargo can't
// read it, the build script probably can't either.
log::debug!(
tracing::debug!(
"failed to determine mtime while fetching metadata of {}: {}",
e.path().display(),
err
Expand Down Expand Up @@ -314,7 +314,7 @@ pub fn set_invocation_time(path: &Path) -> Result<FileTime> {
"This file has an mtime of when this was started.",
)?;
let ft = mtime(&timestamp)?;
log::debug!("invocation time for {:?} is {}", path, ft);
tracing::debug!("invocation time for {:?} is {}", path, ft);
Ok(ft)
}

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

fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
log::debug!("linking {} to {}", src.display(), dst.display());
tracing::debug!("linking {} to {}", src.display(), dst.display());
if same_file::is_same_file(src, dst).unwrap_or(false) {
return Ok(());
}
Expand Down Expand Up @@ -567,7 +567,7 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
};
link_result
.or_else(|err| {
log::debug!("link failed {}. falling back to fs::copy", err);
tracing::debug!("link failed {}. falling back to fs::copy", err);
fs::copy(src, dst).map(|_| ())
})
.with_context(|| {
Expand Down Expand Up @@ -598,8 +598,8 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
pub fn set_file_time_no_err<P: AsRef<Path>>(path: P, time: FileTime) {
let path = path.as_ref();
match filetime::set_file_times(path, time, time) {
Ok(()) => log::debug!("set file mtime {} to {}", path.display(), time),
Err(e) => log::warn!(
Ok(()) => tracing::debug!("set file mtime {} to {}", path.display(), time),
Err(e) => tracing::warn!(
"could not set mtime of {} to {}: {:?}",
path.display(),
time,
Expand All @@ -621,7 +621,7 @@ pub fn strip_prefix_canonical<P: AsRef<Path>>(
let safe_canonicalize = |path: &Path| match path.canonicalize() {
Ok(p) => p,
Err(e) => {
log::warn!("cannot canonicalize {:?}: {:?}", path, e);
tracing::warn!("cannot canonicalize {:?}: {:?}", path, e);
path.to_path_buf()
}
};
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-util/src/process_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl ProcessBuilder {
arg.push(tmp.path());
let mut cmd = self.build_command_without_args();
cmd.arg(arg);
log::debug!("created argfile at {} for {self}", tmp.path().display());
tracing::debug!("created argfile at {} for {self}", tmp.path().display());

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

fn close_tempfile_and_log_error(file: NamedTempFile) {
file.close().unwrap_or_else(|e| {
log::warn!("failed to close temporary file: {e}");
tracing::warn!("failed to close temporary file: {e}");
});
}

Expand Down
4 changes: 2 additions & 2 deletions crates/xtask-bump-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ anyhow.workspace = true
cargo.workspace = true
cargo-util.workspace = true
clap.workspace = true
env_logger.workspace = true
git2.workspace = true
log.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
13 changes: 12 additions & 1 deletion crates/xtask-bump-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod xtask;

fn main() {
env_logger::init_from_env("CARGO_LOG");
setup_logger();

let cli = xtask::cli();
let matches = cli.get_matches();

Expand All @@ -13,3 +14,13 @@ fn main() {
cargo::exit_with_error(e, &mut config.shell())
}
}

// In sync with `src/bin/cargo/main.rs@setup_logger`.
fn setup_logger() {
let env = tracing_subscriber::EnvFilter::from_env("CARGO_LOG");

tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter(env)
.init();
}
12 changes: 6 additions & 6 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn bump_check(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> Carg
for referenced_member in checkout_ws(&ws, &repo, referenced_commit)?.members() {
let Some(changed_member) = changed_members.get(referenced_member) else {
let name = referenced_member.name().as_str();
log::trace!("skipping {name}, may be removed or not published");
tracing::trace!("skipping {name}, may be removed or not published");
continue;
};

Expand Down Expand Up @@ -264,10 +264,10 @@ fn get_referenced_commit<'a>(
let referenced_commit = if rev_id == stable_commit.id() {
None
} else if rev_id == beta_commit.id() {
log::trace!("stable branch from `{}`", stable.name().unwrap().unwrap());
tracing::trace!("stable branch from `{}`", stable.name().unwrap().unwrap());
Some(stable_commit)
} else {
log::trace!("beta branch from `{}`", beta.name().unwrap().unwrap());
tracing::trace!("beta branch from `{}`", beta.name().unwrap().unwrap());
Some(beta_commit)
};

Expand All @@ -287,11 +287,11 @@ fn beta_and_stable_branch(repo: &git2::Repository) -> CargoResult<[git2::Branch<
let (branch, _) = branch?;
let name = branch.name()?.unwrap();
let Some((_, version)) = name.split_once("/rust-") else {
log::trace!("branch `{name}` is not in the format of `<remote>/rust-<semver>`");
tracing::trace!("branch `{name}` is not in the format of `<remote>/rust-<semver>`");
continue;
};
let Ok(version) = version.to_semver() else {
log::trace!("branch `{name}` is not a valid semver: `{version}`");
tracing::trace!("branch `{name}` is not a valid semver: `{version}`");
continue;
};
release_branches.push((version, branch));
Expand Down Expand Up @@ -380,7 +380,7 @@ fn check_crates_io<'a>(
}
};
if possibilities.is_empty() {
log::trace!("dep `{name}` has no version greater than or equal to `{current}`");
tracing::trace!("dep `{name}` has no version greater than or equal to `{current}`");
} else {
needs_bump.push(member);
}
Expand Down
3 changes: 3 additions & 0 deletions credential/cargo-credential/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
thiserror.workspace = true
time.workspace = true

[dev-dependencies]
snapbox = { workspace = true, features = ["examples"] }
90 changes: 90 additions & 0 deletions credential/cargo-credential/examples/file-provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//! Example credential provider that stores credentials in a JSON file.
//! This is not secure
use cargo_credential::{
Action, CacheControl, Credential, CredentialResponse, RegistryInfo, Secret,
};
use std::{collections::HashMap, fs::File, io::ErrorKind};
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

struct FileCredential;

impl Credential for FileCredential {
fn perform(
&self,
registry: &RegistryInfo,
action: &Action,
_args: &[&str],
) -> Result<CredentialResponse, cargo_credential::Error> {
if registry.index_url != "https://github.com/rust-lang/crates.io-index" {
// Restrict this provider to only work for crates.io. Cargo will skip it and attempt
// another provider for any other registry.
//
// If a provider supports any registry, then this check should be omitted.
return Err(cargo_credential::Error::UrlNotSupported);
}

// `Error::Other` takes a boxed `std::error::Error` type that causes Cargo to show the error.
let mut creds = FileCredential::read().map_err(cargo_credential::Error::Other)?;

match action {
Action::Get(_) => {
// Cargo requested a token, look it up.
if let Some(token) = creds.get(registry.index_url) {
Ok(CredentialResponse::Get {
token: token.clone(),
cache: CacheControl::Session,
operation_independent: true,
})
} else {
// Credential providers should respond with `NotFound` when a credential can not be
// found, allowing Cargo to attempt another provider.
Err(cargo_credential::Error::NotFound)
}
}
Action::Login(login_options) => {
// The token for `cargo login` can come from the `login_options` parameter or i
// interactively reading from stdin.
//
// `cargo_credential::read_token` automatically handles this.
let token = cargo_credential::read_token(login_options, registry)?;
creds.insert(registry.index_url.to_string(), token);

FileCredential::write(&creds).map_err(cargo_credential::Error::Other)?;

// Credentials were successfully stored.
Ok(CredentialResponse::Login)
}
Action::Logout => {
if creds.remove(registry.index_url).is_none() {
// If the user attempts to log out from a registry that has no credentials
// stored, then NotFound is the appropriate error.
Err(cargo_credential::Error::NotFound)
} else {
// Credentials were successfully erased.
Ok(CredentialResponse::Logout)
}
}
// If a credential provider doesn't support a given operation, it should respond with `OperationNotSupported`.
_ => Err(cargo_credential::Error::OperationNotSupported),
}
}
}

impl FileCredential {
fn read() -> Result<HashMap<String, Secret<String>>, Error> {
match File::open("cargo-credentials.json") {
Ok(f) => Ok(serde_json::from_reader(f)?),
Err(e) if e.kind() == ErrorKind::NotFound => Ok(HashMap::new()),
Err(e) => Err(e)?,
}
}
fn write(value: &HashMap<String, Secret<String>>) -> Result<(), Error> {
let file = File::create("cargo-credentials.json")?;
Ok(serde_json::to_writer_pretty(file, value)?)
}
}

fn main() {
cargo_credential::main(FileCredential);
}
Loading

0 comments on commit 1509634

Please sign in to comment.