-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #12039 - epage:xtask, r=weihanglo
chore(xtask): Add `cargo xtask unpublished` ### What does this PR try to resolve? This tries to make it easy to see what existing versions have not been published. A future version of this could post to a PR what the current delta in version numbers for touched crates so reviewer have more context when deciding if they should ask for a crate version to be bumped ```console $ cargo unpublished Finished dev [unoptimized + debuginfo] target(s) in 0.12s Running `/home/epage/src/personal/cargo/target/debug/xtask unpublished` Updating crates.io index name published current ==== ========= ======= cargo-test-macro - 0.1.0 cargo-test-support - 0.1.0 cargo-util 0.2.3 0.2.4 mdman 0.0.0 0.1.0 resolver-tests - 0.1.0 cargo 0.70.0 0.71.0 cargo-credential 0.1.0 0.2.0 cargo-credential-1password 0.1.0 0.2.0 cargo-credential-gnome-secret 0.1.0 0.2.0 cargo-credential-macos-keychain 0.1.0 0.2.0 cargo-credential-wincred 0.1.0 0.2.0 benchsuite - 0.1.0 ``` Room for improvement - Aligning the start of each column - Filtering the list by a commit range - Adding this to an action to post to a review - Maybe sorting the output - Marking some our crates as `package.publish = false`, like benchsuite and resolver-tests ### How should we test and review this PR? This is broken down commit by commit for easier seeing of the building blocks for our first xtask
- Loading branch information
Showing
6 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[alias] | ||
unpublished = "run --package xtask-unpublished --" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
target | ||
Cargo.lock | ||
.cargo | ||
/config.stamp | ||
/Makefile | ||
/config.mk | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "xtask-unpublished" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
anyhow = "1.0.47" | ||
cargo = { path = "../.." } | ||
clap = "4.2.0" | ||
env_logger = "0.10.0" | ||
log = "0.4.17" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
mod xtask; | ||
|
||
fn main() { | ||
env_logger::init_from_env("CARGO_LOG"); | ||
let cli = xtask::cli(); | ||
let matches = cli.get_matches(); | ||
|
||
let mut config = cargo::util::config::Config::default().unwrap_or_else(|e| { | ||
let mut eval = cargo::core::shell::Shell::new(); | ||
cargo::exit_with_error(e.into(), &mut eval) | ||
}); | ||
if let Err(e) = xtask::exec(&matches, &mut config) { | ||
cargo::exit_with_error(e, &mut config.shell()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
use cargo::core::registry::PackageRegistry; | ||
use cargo::core::QueryKind; | ||
use cargo::core::Registry; | ||
use cargo::core::SourceId; | ||
use cargo::util::command_prelude::*; | ||
|
||
pub fn cli() -> clap::Command { | ||
clap::Command::new("xtask-unpublished") | ||
.arg( | ||
opt( | ||
"verbose", | ||
"Use verbose output (-vv very verbose/build.rs output)", | ||
) | ||
.short('v') | ||
.action(ArgAction::Count) | ||
.global(true), | ||
) | ||
.arg_quiet() | ||
.arg( | ||
opt("color", "Coloring: auto, always, never") | ||
.value_name("WHEN") | ||
.global(true), | ||
) | ||
.arg(flag("frozen", "Require Cargo.lock and cache are up to date").global(true)) | ||
.arg(flag("locked", "Require Cargo.lock is up to date").global(true)) | ||
.arg(flag("offline", "Run without accessing the network").global(true)) | ||
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true)) | ||
.arg( | ||
Arg::new("unstable-features") | ||
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") | ||
.short('Z') | ||
.value_name("FLAG") | ||
.action(ArgAction::Append) | ||
.global(true), | ||
) | ||
} | ||
|
||
pub fn exec(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> cargo::CliResult { | ||
config_configure(config, args)?; | ||
|
||
unpublished(args, config)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult { | ||
let verbose = args.verbose(); | ||
// quiet is unusual because it is redefined in some subcommands in order | ||
// to provide custom help text. | ||
let quiet = args.flag("quiet"); | ||
let color = args.get_one::<String>("color").map(String::as_str); | ||
let frozen = args.flag("frozen"); | ||
let locked = args.flag("locked"); | ||
let offline = args.flag("offline"); | ||
let mut unstable_flags = vec![]; | ||
if let Some(values) = args.get_many::<String>("unstable-features") { | ||
unstable_flags.extend(values.cloned()); | ||
} | ||
let mut config_args = vec![]; | ||
if let Some(values) = args.get_many::<String>("config") { | ||
config_args.extend(values.cloned()); | ||
} | ||
config.configure( | ||
verbose, | ||
quiet, | ||
color, | ||
frozen, | ||
locked, | ||
offline, | ||
&None, | ||
&unstable_flags, | ||
&config_args, | ||
)?; | ||
Ok(()) | ||
} | ||
|
||
fn unpublished(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> cargo::CliResult { | ||
let ws = args.workspace(config)?; | ||
let mut results = Vec::new(); | ||
{ | ||
let mut registry = PackageRegistry::new(config)?; | ||
let _lock = config.acquire_package_cache_lock()?; | ||
registry.lock_patches(); | ||
let source_id = SourceId::crates_io(config)?; | ||
|
||
for member in ws.members() { | ||
let name = member.name(); | ||
let current = member.version(); | ||
if member.publish() == &Some(vec![]) { | ||
log::trace!("skipping {name}, `publish = false`"); | ||
continue; | ||
} | ||
|
||
let version_req = format!("<={current}"); | ||
let query = cargo::core::dependency::Dependency::parse( | ||
name, | ||
Some(&version_req), | ||
source_id.clone(), | ||
)?; | ||
let possibilities = loop { | ||
// Exact to avoid returning all for path/git | ||
match registry.query_vec(&query, QueryKind::Exact) { | ||
std::task::Poll::Ready(res) => { | ||
break res?; | ||
} | ||
std::task::Poll::Pending => registry.block_until_ready()?, | ||
} | ||
}; | ||
if let Some(last) = possibilities.iter().map(|s| s.version()).max() { | ||
if last != current { | ||
results.push(( | ||
name.to_string(), | ||
Some(last.to_string()), | ||
current.to_string(), | ||
)); | ||
} else { | ||
log::trace!("{name} {current} is published"); | ||
} | ||
} else { | ||
results.push((name.to_string(), None, current.to_string())); | ||
} | ||
} | ||
} | ||
|
||
if !results.is_empty() { | ||
results.insert( | ||
0, | ||
( | ||
"name".to_owned(), | ||
Some("published".to_owned()), | ||
"current".to_owned(), | ||
), | ||
); | ||
results.insert( | ||
1, | ||
( | ||
"====".to_owned(), | ||
Some("=========".to_owned()), | ||
"=======".to_owned(), | ||
), | ||
); | ||
} | ||
for (name, last, current) in results { | ||
if let Some(last) = last { | ||
println!("{name} {last} {current}"); | ||
} else { | ||
println!("{name} - {current}"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn verify_cli() { | ||
cli().debug_assert(); | ||
} |