From 2f38472bca37e66a62e756680b9c9066469753e5 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 5 Nov 2021 17:23:31 +0100 Subject: [PATCH 1/5] Update to latest dependencies --- Cargo.lock | 202 +++++++++++++++++-------------------- Cargo.toml | 8 +- src/cli.rs | 110 +++++++++++--------- src/commands/check.rs | 25 +++-- src/commands/release.rs | 16 ++- src/commands/to_release.rs | 2 +- 6 files changed, 185 insertions(+), 178 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 780af5b..8775ff3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler" version = "0.2.3" @@ -121,19 +123,18 @@ checksum = "81a18687293a1546b67c246452202bbbf143d239cb43494cc163da14979082da" [[package]] name = "cargo" -version = "0.53.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca7e53bf83eb8f6254a37ac45822003c05f6053c09b58795de76a3d6c84eda8a" +checksum = "519db9ad1bc3bf61f2e753cc204ac37903cf0f33f551a03c260208271c1f875b" dependencies = [ "anyhow", "atty", "bytesize", "cargo-platform", + "cargo-util", "clap", - "core-foundation", "crates-io", "crossbeam-utils", - "crypto-hash", "curl", "curl-sys", "env_logger", @@ -148,6 +149,7 @@ dependencies = [ "humantime", "ignore", "im-rc", + "itertools", "jobserver", "lazy_static", "lazycell", @@ -155,14 +157,11 @@ dependencies = [ "libgit2-sys", "log", "memchr", - "miow", "num_cpus", "opener", "percent-encoding", - "rand 0.8.3", "rustc-workspace-hack", "rustfix", - "same-file", "semver", "serde", "serde_ignored", @@ -182,9 +181,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" dependencies = [ "serde", ] @@ -227,6 +226,28 @@ dependencies = [ "toml_edit", ] +[[package]] +name = "cargo-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2bf633f7ad4e022f63c4197085047af9606a08a3df17badbb7bd3644dc7faeb" +dependencies = [ + "anyhow", + "core-foundation", + "crypto-hash", + "filetime", + "hex 0.4.2", + "jobserver", + "libc", + "log", + "miow", + "same-file", + "shell-escape", + "tempfile", + "walkdir", + "winapi", +] + [[package]] name = "cc" version = "1.0.66" @@ -371,24 +392,24 @@ dependencies = [ [[package]] name = "curl" -version = "0.4.34" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e268162af1a5fe89917ae25ba3b0a77c8da752bdc58e7dbb4f15b91fbd33756e" +checksum = "877cc2f9b8367e32b6dabb9d581557e651cb3aa693a37f8679091bbf42687d5d" dependencies = [ "curl-sys", "libc", "openssl-probe", "openssl-sys", "schannel", - "socket2", + "socket2 0.4.2", "winapi", ] [[package]] name = "curl-sys" -version = "0.4.39+curl-7.74.0" +version = "0.4.50+curl-7.79.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07a8ce861e7b68a0b394e814d7ee9f1b2750ff8bd10372c6ad3bacc10e86f874" +checksum = "4856b76919dd599f31236bb18db5f5bd36e2ce131e64f857ca5c259665b76171" dependencies = [ "cc", "libc", @@ -420,9 +441,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "env_logger" -version = "0.8.2" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", @@ -539,22 +560,11 @@ dependencies = [ "wasi 0.9.0+wasi-snapshot-preview1", ] -[[package]] -name = "getrandom" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", -] - [[package]] name = "git2" -version = "0.13.19" +version = "0.13.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17929de7239dea9f68aa14f94b2ab4974e7b24c1314275ffcc12a7758172fa18" +checksum = "2a8057932925d3a9d9e4434ea016570d37420ddb1ceed45a174d577f24ed6700" dependencies = [ "bitflags", "libc", @@ -694,7 +704,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ca8957e71f04a205cb162508f9326aea04676c8dfd0711220190d6b83664f3f" dependencies = [ "bitmaps", - "rand_core 0.5.1", + "rand_core", "rand_xoshiro", "sized-chunks", "typenum", @@ -711,6 +721,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "itertools" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.7" @@ -719,9 +738,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "jobserver" -version = "0.1.21" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" dependencies = [ "libc", ] @@ -740,15 +759,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.81" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" +checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" [[package]] name = "libgit2-sys" -version = "0.12.20+1.1.0" +version = "0.12.24+1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e2f09917e00b9ad194ae72072bb5ada2cca16d8171a43e91ddba2afbb02664b" +checksum = "ddbd6021eef06fb289a8f54b3c2acfdd85ff2a585dfbb24b8576325373d2152c" dependencies = [ "cc", "libc", @@ -837,7 +856,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ - "socket2", + "socket2 0.3.19", "winapi", ] @@ -878,10 +897,11 @@ dependencies = [ [[package]] name = "opener" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13117407ca9d0caf3a0e74f97b490a7e64c0ae3aa90a8b7085544d0c37b6f3ae" +checksum = "4ea3ebcd72a54701f56345f16785a6d3ac2df7e986d273eb4395c0b01db17952" dependencies = [ + "bstr", "winapi", ] @@ -1023,23 +1043,11 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom 0.1.16", + "getrandom", "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - -[[package]] -name = "rand" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" -dependencies = [ - "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -1049,17 +1057,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", -] - -[[package]] -name = "rand_chacha" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -1068,16 +1066,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom 0.1.16", -] - -[[package]] -name = "rand_core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" -dependencies = [ - "getrandom 0.2.2", + "getrandom", ] [[package]] @@ -1086,16 +1075,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -1104,7 +1084,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004" dependencies = [ - "rand_core 0.5.1", + "rand_core", ] [[package]] @@ -1157,9 +1137,9 @@ checksum = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb" [[package]] name = "rustfix" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2c50b74badcddeb8f7652fa8323ce440b95286f8e4b64ebfd871c609672704e" +checksum = "6f0be05fc0675ef4f47119dc39cfc46636bb77d4fc4ef1bd851b9c3f7697f32a" dependencies = [ "anyhow", "log", @@ -1194,34 +1174,27 @@ dependencies = [ [[package]] name = "semver" -version = "0.10.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "394cec28fa623e00903caf7ba4fa6fb9a0e260280bb8cdbbba029611108a0190" +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" dependencies = [ - "semver-parser", "serde", ] -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" -version = "1.0.118" +version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.118" +version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" dependencies = [ "proc-macro2", "quote", @@ -1281,6 +1254,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "strip-ansi-escapes" version = "0.1.0" @@ -1322,9 +1305,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.57" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6" +checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" dependencies = [ "proc-macro2", "quote", @@ -1333,13 +1316,12 @@ dependencies = [ [[package]] name = "tar" -version = "0.4.30" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "489997b7557e9a43e192c527face4feacc78bfbe6eed67fd55c4c9e381cba290" +checksum = "d6f5515d3add52e0bbdcad7b83c388bb36ba7b754dda3b5f5bc2d38640cdba5c" dependencies = [ "filetime", "libc", - "redox_syscall", "xattr", ] @@ -1351,7 +1333,7 @@ checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ "cfg-if 0.1.10", "libc", - "rand 0.7.3", + "rand", "redox_syscall", "remove_dir_all", "winapi", @@ -1509,9 +1491,9 @@ dependencies = [ [[package]] name = "url" -version = "2.2.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", diff --git a/Cargo.toml b/Cargo.toml index 80b5889..62583e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,11 +29,11 @@ petgraph = "0.5.0" regex = "1.4.1" # CARGO VERSION BOUND dependencies -cargo = "0.53.0" +cargo = "0.57.0" flate2 = "1.0.3" -git2 = "0.13.10" -semver = "0.10.0" -tar = "0.4.26" +git2 = "0.13.23" +semver = "1.0.3" +tar = "0.4.35" # Optional dependencies cargo-readme = { version = "3.2", optional = true } diff --git a/src/cli.rs b/src/cli.rs index f6cc776..9421b01 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,7 +5,7 @@ use cargo::{ use flexi_logger::Logger; use log::trace; use regex::Regex; -use semver::{Identifier, Version}; +use semver::{Version, Prerelease, BuildMetadata}; use std::{error::Error, fs, path::PathBuf, str::FromStr}; use structopt::clap::arg_enum; use structopt::StructOpt; @@ -14,9 +14,6 @@ use toml_edit::Value; use crate::commands; use crate::util; -fn parse_identifiers(src: &str) -> Identifier { - Identifier::AlphaNumeric(src.to_owned()) -} fn parse_regex(src: &str) -> Result { Regex::new(src).map_err(|e| format!("Parsing Regex failed: {:}", e)) } @@ -49,8 +46,8 @@ pub struct PackageSelectOptions { /// Ignore version pre-releases /// /// Skip if the SemVer pre-release field is any of the listed. Mutually exclusive with `--package` - #[structopt(short, long, parse(from_str = parse_identifiers))] - pub ignore_pre_version: Vec, + #[structopt(short, long)] + pub ignore_pre_version: Vec, /// Ignore whether `publish` is set. /// /// If nothing else is specified, `publish = true` is assumed for every package. If publish @@ -104,8 +101,8 @@ pub enum VersionCommand { #[structopt(long)] force_update: bool, /// Use this identifier instead of `dev` for the pre-release - #[structopt(parse(from_str = parse_identifiers))] - pre_tag: Option, + #[structopt()] + pre_tag: Option, }, /// Increase the pre-release suffix, keep prefix, set to `.1` if no suffix is present BumpPre { @@ -164,8 +161,8 @@ pub enum VersionCommand { #[structopt(flatten)] pkg_opts: PackageSelectOptions, /// The string to set the pre-release to - #[structopt(parse(from_str = parse_identifiers))] - pre: Identifier, + #[structopt()] + pre: String, /// Force an update of dependencies /// /// Hard set to the new version, do not check whether the given one still matches @@ -177,8 +174,8 @@ pub enum VersionCommand { #[structopt(flatten)] pkg_opts: PackageSelectOptions, /// The specific metadata to set to - #[structopt(parse(from_str = parse_identifiers))] - meta: Identifier, + #[structopt()] + meta: String, /// Force an update of dependencies /// /// Hard set to the new version, do not check whether the given one still matches @@ -424,7 +421,7 @@ fn make_pkg_predicate( trace!("{:}.publish={}", p.name(), value); value }; - let check_version = move |p: &Package| return include_pre_deps && p.version().is_prerelease(); + let check_version = move |p: &Package| return include_pre_deps && !p.version().pre.is_empty(); let changed = if let Some(changed_since) = &changed_since { if !skip.is_empty() || !ignore_pre_version.is_empty() { @@ -457,11 +454,9 @@ fn make_pkg_predicate( if skip.iter().any(|r| r.is_match(&name)) { return false; } - if p.version().is_prerelease() { - for pre in &p.version().pre { - if ignore_pre_version.contains(&pre) { - return false; - } + if !p.version().pre.is_empty() { + if ignore_pre_version.contains(&p.version().pre.as_str().to_owned()) { + return false; } } } @@ -614,17 +609,27 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| { let mut v = p.version().clone(); if v.pre.is_empty() { - v.pre = vec![Identifier::Numeric(1)] + v.pre = Prerelease::new( "1").expect("Static will work"); } else { - match v.pre.pop() { - Some(Identifier::Numeric(num)) => { - v.pre.push(Identifier::Numeric(num + 1)) + if let Ok(num) = v.pre.as_str().parse::() { + v.pre = Prerelease::new(&format!("{}", num + 1)).expect("Knwon to work"); + } else { + let mut items = v.pre + .as_str() + .split(".") + .map(|s| s.to_string()) + .collect::>(); + if let Some(num) = items.last().and_then(|u| u.parse::().ok()) { + let _ = items.pop(); + items.push(format!("{}", num + 1).to_owned()); + } else { + items.push("1".to_owned()); } - Some(Identifier::AlphaNumeric(pre)) => { - v.pre.push(Identifier::AlphaNumeric(pre)); - v.pre.push(Identifier::Numeric(1)); + if let Ok(pre) = Prerelease::new(&items.join(".") ) { + v.pre = pre; + } else { + return None } - _ => unreachable!("There is a last item"), } } Some(v) @@ -642,8 +647,8 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.pre = Vec::new(); - v.increment_patch(); + v.pre = Prerelease::EMPTY; + v.patch += 1; Some(v) }, force_update, @@ -659,8 +664,9 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.pre = Vec::new(); - v.increment_minor(); + v.pre = Prerelease::EMPTY; + v.minor += 1; + v.patch = 0; Some(v) }, force_update, @@ -676,8 +682,10 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.pre = Vec::new(); - v.increment_major(); + v.pre = Prerelease::EMPTY; + v.major += 1; + v.minor = 0; + v.patch = 0; Some(v) }, force_update, @@ -693,19 +701,22 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.pre = Vec::new(); + v.pre = Prerelease::EMPTY; if v.major != 0 { - v.increment_major(); + v.major += 1; + v.minor = 0; + v.patch = 0; } else if v.minor != 0 { - v.increment_minor(); + v.minor += 1; + v.patch = 0; } else { // 0.0.x means each patch is breaking, see: // https://doc.rust-lang.org/cargo/reference/semver.html#change-categories v.patch += 1; // no helper, have to reset the metadata ourselves - v.build = Vec::new(); - v.pre = Vec::new(); + v.build = BuildMetadata::EMPTY; + v.pre = Prerelease::EMPTY; } Some(v) }, @@ -718,27 +729,30 @@ pub fn run(args: Opt) -> Result<(), Box> { pre_tag, } => { let predicate = make_pkg_predicate(&ws, pkg_opts)?; - let pre_val = - pre_tag.unwrap_or_else(|| Identifier::AlphaNumeric("dev".to_owned())); + let pre_val = pre_tag.unwrap_or_else(|| "dev".to_owned()); commands::set_version( &ws, |p| predicate(p), |p| { let mut v = p.version().clone(); if v.major != 0 { - v.increment_major(); + v.major += 1; + v.minor = 0; + v.patch = 0 } else if v.minor != 0 { - v.increment_minor(); + v.minor += 1; + v.patch = 0; } else { // 0.0.x means each patch is breaking, see: // https://doc.rust-lang.org/cargo/reference/semver.html#change-categories v.patch += 1; // no helper, have to reset the metadata ourselves - v.build = Vec::new(); + v.build = BuildMetadata::EMPTY; } // force the pre - v.pre = vec![pre_val.clone()]; + v.pre = Prerelease::new(&pre_val.clone()) + .expect("Static or expected to work"); Some(v) }, force_update, @@ -755,7 +769,8 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.pre = vec![pre.clone()]; + v.pre = Prerelease::new(&pre.clone()) + .expect("Static or expected to work"); Some(v) }, force_update, @@ -772,7 +787,8 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.build = vec![meta.clone()]; + v.build = BuildMetadata::new(&meta.clone()) + .expect("The meta you provided couldn't be parsed"); Some(v) }, force_update, @@ -788,8 +804,8 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.pre = vec![]; - v.build = vec![]; + v.pre = Prerelease::EMPTY; + v.build = BuildMetadata::EMPTY; Some(v) }, force_update, diff --git a/src/commands/check.rs b/src/commands/check.rs index c4c433d..3c85e7d 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -5,17 +5,17 @@ use crate::util::{edit_each_dep, DependencyAction, DependencyEntry}; use cargo::{ core::{ compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor}, + resolver::features::CliFeatures, manifest::ManifestMetadata, package::Package, Feature, SourceId, Workspace, }, ops::{self, package, PackageOpts}, sources::PathSource, - util::{paths, FileLock}, + util::{FileLock, OptVersionReq}, }; use flate2::read::GzDecoder; use log::error; -use semver::VersionReq; use std::{ collections::HashMap, error::Error, @@ -70,7 +70,7 @@ fn run_check<'a>( .parent() .join(&format!("{}-{}", pkg.name(), pkg.version())); if dst.exists() { - paths::remove_dir_all(&dst)?; + std::fs::remove_dir_all(&dst)?; } let mut archive = Archive::new(f); // We don't need to set the Modified Time, as it's not relevant to verification @@ -115,10 +115,8 @@ fn run_check<'a>( &ws, &ops::CompileOptions { build_config: BuildConfig::new(config, opts.jobs, &opts.targets, build_mode)?, - features: opts.features.clone(), - no_default_features: opts.no_default_features, - all_features: opts.all_features, spec: ops::Packages::Packages(Vec::new()), + cli_features: opts.cli_features.clone(), filter: ops::CompileFilter::Default { required_features_filterable: true, }, @@ -152,7 +150,7 @@ fn check_dependencies(package: &Package) -> Result<(), String> { let git_deps = package .dependencies() .iter() - .filter(|d| d.source_id().is_git() && d.version_req() == &VersionReq::any()) + .filter(|d| d.source_id().is_git() && d.version_req() == &OptVersionReq::Any) .map(|d| format!("{:}", d.package_name())) .collect::>(); if !git_deps.is_empty() { @@ -219,11 +217,14 @@ pub fn check<'a>( check_metadata: true, list: false, allow_dirty: true, - all_features: false, - no_default_features: false, jobs: None, + to_package: ops::Packages::Default, targets: Default::default(), - features: Default::default(), + cli_features: CliFeatures { + features: Default::default(), + all_features: false, + uses_default_features: true, + } }; c.shell().status("Checking", "Metadata & Dependencies")?; @@ -284,7 +285,9 @@ pub fn check<'a>( .status("Packing", &pkg) .map_err(|e| format!("{:}", e))?; match package(&pkg_ws, &opts) { - Ok(Some(rw_lock)) => Ok((pkg_ws, rw_lock)), + Ok(Some(mut rw_lock)) if rw_lock.len() == 1 => + Ok((pkg_ws, rw_lock.pop().expect("we checked the counter"))), + Ok(Some(_rw_lock)) => Err(format!("Packing {:} produced more than one package", pkg.name())), Ok(None) => Err(format!("Failure packing {:}", pkg.name())), Err(e) => { cargo::display_error(&e, &mut c.shell()); diff --git a/src/commands/release.rs b/src/commands/release.rs index 4fd4d64..863afae 100644 --- a/src/commands/release.rs +++ b/src/commands/release.rs @@ -1,7 +1,10 @@ use crate::commands::add_owner; use cargo::{ - core::{package::Package, Workspace}, - ops::{publish, PublishOpts}, + core::{ + package::Package, Workspace, + resolver::features::CliFeatures + }, + ops::{self, publish, PublishOpts}, }; use std::error::Error; use std::{thread, time::Duration}; @@ -20,13 +23,16 @@ pub fn release( dry_run, config: c, allow_dirty: true, - all_features: false, - no_default_features: false, index: None, jobs: None, + to_publish: ops::Packages::Default, targets: Default::default(), registry: None, - features: Default::default(), + cli_features: CliFeatures { + features: Default::default(), + all_features: false, + uses_default_features: true, + } }; let delay = { diff --git a/src/commands/to_release.rs b/src/commands/to_release.rs index 06a41ca..603736d 100644 --- a/src/commands/to_release.rs +++ b/src/commands/to_release.rs @@ -48,7 +48,7 @@ where .expect("Updating from remote registry failed :( ."); for m in members.iter() { - let dep = Dependency::parse_no_deprecated( + let dep = Dependency::parse( m.name(), Some(&m.version().to_string()), registry.source_id(), From 035753f2066e861821e10f654d23e443c66d6a06 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 5 Nov 2021 17:37:26 +0100 Subject: [PATCH 2/5] add changelog entry --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 9a64d22..6da35cc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog]. ## Unreleased +- Update to cargo 0.52 and semver 1.0 – support for `edition = "2021"` - New [version command now takes new `bump-to-dev`](https://github.com/paritytech/cargo-unleash/pull/47) that bumps to the next breaking version and appends a `-dev` pre-release value - Use saved credentials from `cargo login` - Do not fail if package selections turns up 0 (unless `--empty-is-failure` is given) From 25474884ce40c71903d0c5b720ff9400a939a333 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 5 Nov 2021 17:37:38 +0100 Subject: [PATCH 3/5] fixing style --- src/cli.rs | 24 ++++++++++++++---------- src/commands/check.rs | 14 +++++++++----- src/commands/release.rs | 7 ++----- tests/version_bumps.rs | 2 +- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 9421b01..6c8e99c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,7 +5,7 @@ use cargo::{ use flexi_logger::Logger; use log::trace; use regex::Regex; -use semver::{Version, Prerelease, BuildMetadata}; +use semver::{BuildMetadata, Prerelease, Version}; use std::{error::Error, fs, path::PathBuf, str::FromStr}; use structopt::clap::arg_enum; use structopt::StructOpt; @@ -609,26 +609,30 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| { let mut v = p.version().clone(); if v.pre.is_empty() { - v.pre = Prerelease::new( "1").expect("Static will work"); + v.pre = Prerelease::new("1").expect("Static will work"); } else { if let Ok(num) = v.pre.as_str().parse::() { - v.pre = Prerelease::new(&format!("{}", num + 1)).expect("Knwon to work"); + v.pre = Prerelease::new(&format!("{}", num + 1)) + .expect("Knwon to work"); } else { - let mut items = v.pre + let mut items = v + .pre .as_str() .split(".") .map(|s| s.to_string()) .collect::>(); - if let Some(num) = items.last().and_then(|u| u.parse::().ok()) { + if let Some(num) = + items.last().and_then(|u| u.parse::().ok()) + { let _ = items.pop(); items.push(format!("{}", num + 1).to_owned()); } else { items.push("1".to_owned()); } - if let Ok(pre) = Prerelease::new(&items.join(".") ) { + if let Ok(pre) = Prerelease::new(&items.join(".")) { v.pre = pre; - } else { - return None + } else { + return None; } } } @@ -769,8 +773,8 @@ pub fn run(args: Opt) -> Result<(), Box> { |p| predicate(p), |p| { let mut v = p.version().clone(); - v.pre = Prerelease::new(&pre.clone()) - .expect("Static or expected to work"); + v.pre = + Prerelease::new(&pre.clone()).expect("Static or expected to work"); Some(v) }, force_update, diff --git a/src/commands/check.rs b/src/commands/check.rs index 3c85e7d..378a002 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -5,9 +5,9 @@ use crate::util::{edit_each_dep, DependencyAction, DependencyEntry}; use cargo::{ core::{ compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor}, - resolver::features::CliFeatures, manifest::ManifestMetadata, package::Package, + resolver::features::CliFeatures, Feature, SourceId, Workspace, }, ops::{self, package, PackageOpts}, @@ -224,7 +224,7 @@ pub fn check<'a>( features: Default::default(), all_features: false, uses_default_features: true, - } + }, }; c.shell().status("Checking", "Metadata & Dependencies")?; @@ -285,9 +285,13 @@ pub fn check<'a>( .status("Packing", &pkg) .map_err(|e| format!("{:}", e))?; match package(&pkg_ws, &opts) { - Ok(Some(mut rw_lock)) if rw_lock.len() == 1 => - Ok((pkg_ws, rw_lock.pop().expect("we checked the counter"))), - Ok(Some(_rw_lock)) => Err(format!("Packing {:} produced more than one package", pkg.name())), + Ok(Some(mut rw_lock)) if rw_lock.len() == 1 => { + Ok((pkg_ws, rw_lock.pop().expect("we checked the counter"))) + } + Ok(Some(_rw_lock)) => Err(format!( + "Packing {:} produced more than one package", + pkg.name() + )), Ok(None) => Err(format!("Failure packing {:}", pkg.name())), Err(e) => { cargo::display_error(&e, &mut c.shell()); diff --git a/src/commands/release.rs b/src/commands/release.rs index 863afae..7517cc4 100644 --- a/src/commands/release.rs +++ b/src/commands/release.rs @@ -1,9 +1,6 @@ use crate::commands::add_owner; use cargo::{ - core::{ - package::Package, Workspace, - resolver::features::CliFeatures - }, + core::{package::Package, resolver::features::CliFeatures, Workspace}, ops::{self, publish, PublishOpts}, }; use std::error::Error; @@ -32,7 +29,7 @@ pub fn release( features: Default::default(), all_features: false, uses_default_features: true, - } + }, }; let delay = { diff --git a/tests/version_bumps.rs b/tests/version_bumps.rs index 034b4cf..9f3a1f5 100644 --- a/tests/version_bumps.rs +++ b/tests/version_bumps.rs @@ -62,7 +62,7 @@ fn bump_to_dev() -> Result<(), Box> { let (crate_c, _) = read_package(&temp_path.join("crateC").join("Cargo.toml"), source, &cfg)?; assert_eq!(crate_a.version(), &Version::parse("0.2.0-dev")?); assert_eq!(crate_b.version(), &Version::parse("3.0.0-dev")?); - assert_eq!(crate_c.version(), &Version::parse("4.0.0-dev")?); // wasn't selected + assert_eq!(crate_c.version(), &Version::parse("4.0.0-dev")?); temp.close()?; Ok(()) From 446c518746e8cf11a31577e3963cc54fddc521f8 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 5 Nov 2021 17:45:03 +0100 Subject: [PATCH 4/5] improved style --- src/cli.rs | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 6c8e99c..938b0de 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -454,10 +454,10 @@ fn make_pkg_predicate( if skip.iter().any(|r| r.is_match(&name)) { return false; } - if !p.version().pre.is_empty() { - if ignore_pre_version.contains(&p.version().pre.as_str().to_owned()) { - return false; - } + if !p.version().pre.is_empty() + && ignore_pre_version.contains(&p.version().pre.as_str().to_owned()) + { + return false; } } @@ -610,30 +610,27 @@ pub fn run(args: Opt) -> Result<(), Box> { let mut v = p.version().clone(); if v.pre.is_empty() { v.pre = Prerelease::new("1").expect("Static will work"); + } else if let Ok(num) = v.pre.as_str().parse::() { + v.pre = Prerelease::new(&format!("{}", num + 1)) + .expect("Knwon to work"); } else { - if let Ok(num) = v.pre.as_str().parse::() { - v.pre = Prerelease::new(&format!("{}", num + 1)) - .expect("Knwon to work"); + let mut items = v + .pre + .as_str() + .split(".") + .map(|s| s.to_string()) + .collect::>(); + if let Some(num) = items.last().and_then(|u| u.parse::().ok()) + { + let _ = items.pop(); + items.push(format!("{}", num + 1).to_owned()); + } else { + items.push("1".to_owned()); + } + if let Ok(pre) = Prerelease::new(&items.join(".")) { + v.pre = pre; } else { - let mut items = v - .pre - .as_str() - .split(".") - .map(|s| s.to_string()) - .collect::>(); - if let Some(num) = - items.last().and_then(|u| u.parse::().ok()) - { - let _ = items.pop(); - items.push(format!("{}", num + 1).to_owned()); - } else { - items.push("1".to_owned()); - } - if let Ok(pre) = Prerelease::new(&items.join(".")) { - v.pre = pre; - } else { - return None; - } + return None; } } Some(v) From 5bf0f06a1f63508ea42bb0ee911d966b47335913 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Fri, 5 Nov 2021 17:53:22 +0100 Subject: [PATCH 5/5] fixing clippy --- src/cli.rs | 8 ++++---- src/commands/check.rs | 6 +++--- src/commands/release.rs | 2 +- src/commands/rename.rs | 4 ++-- src/commands/to_release.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 938b0de..57efc15 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -430,7 +430,7 @@ fn make_pkg_predicate( .into(), ); } - Some(util::changed_packages(ws, &changed_since)?) + Some(util::changed_packages(ws, changed_since)?) } else { None }; @@ -537,7 +537,7 @@ pub fn run(args: Opt) -> Result<(), Box> { let predicate = make_pkg_predicate(&ws, pkg_opts)?; for pkg in ws.members().filter(|p| predicate(p)) { - commands::add_owner(ws.config(), &pkg, owner.clone(), t.clone())?; + commands::add_owner(ws.config(), pkg, owner.clone(), t.clone())?; } Ok(()) } @@ -617,13 +617,13 @@ pub fn run(args: Opt) -> Result<(), Box> { let mut items = v .pre .as_str() - .split(".") + .split('.') .map(|s| s.to_string()) .collect::>(); if let Some(num) = items.last().and_then(|u| u.parse::().ok()) { let _ = items.pop(); - items.push(format!("{}", num + 1).to_owned()); + items.push(format!("{}", num + 1)); } else { items.push("1".to_owned()); } diff --git a/src/commands/check.rs b/src/commands/check.rs index 378a002..a7577ac 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -178,7 +178,7 @@ fn check_metadata(metadata: &ManifestMetadata) -> Result<(), String> { _ => {} } match (metadata.license.as_ref(), metadata.license_file.as_ref()) { - (Some(ref s), None) | (None, Some(ref s)) if !s.is_empty() => {} + (Some(s), None) | (None, Some(s)) if !s.is_empty() => {} (Some(_), Some(_)) => bad_fields.push("You can't have license AND license_file"), _ => bad_fields.push("Neither license nor license_file is provided"), } @@ -255,7 +255,7 @@ pub fn check<'a>( if check_readme { c.shell().status("Checking", "Readme files")?; let errors = packages.iter().fold(Vec::new(), |mut res, pkg| { - if let Err(e) = self::check_readme(&ws, &pkg) { + if let Err(e) = self::check_readme(ws, pkg) { res.push(format!( "{:}: Checking Readme file failed with: {:}", pkg.name(), @@ -331,7 +331,7 @@ pub fn check<'a>( .current() .expect("We've build localised workspaces. qed"), )?; - let ws = run_check(&pkg_ws, &rw_lock, &opts, build_mode, &replaces)?; + let ws = run_check(pkg_ws, rw_lock, &opts, build_mode, &replaces)?; let new_pkg = ws.current().expect("Each workspace is for a package!"); replaces.insert( new_pkg.name().as_str().to_owned(), diff --git a/src/commands/release.rs b/src/commands/release.rs index 7517cc4..93ee1bd 100644 --- a/src/commands/release.rs +++ b/src/commands/release.rs @@ -56,7 +56,7 @@ pub fn release( c.shell().status("Publishing", &pkg)?; publish(&pkg_ws, &opts)?; if let Some(ref o) = owner { - add_owner(c, &pkg, o.clone(), token.clone())?; + add_owner(c, pkg, o.clone(), token.clone())?; } } Ok(()) diff --git a/src/commands/rename.rs b/src/commands/rename.rs index 0ea7b24..836a214 100644 --- a/src/commands/rename.rs +++ b/src/commands/rename.rs @@ -51,7 +51,7 @@ where let c = ws.config(); let updates = edit_each( - members_deep(&ws).iter().filter(|p| predicate(p)), + members_deep(ws).iter().filter(|p| predicate(p)), |p, doc| { Ok(mapper(p).map(|new_name| { c.shell() @@ -73,7 +73,7 @@ where } c.shell().status("Updating", "Dependency tree")?; - edit_each(members_deep(&ws).iter(), |p, doc| { + edit_each(members_deep(ws).iter(), |p, doc| { c.shell().status("Updating", p.name())?; let root = doc.as_table_mut(); let mut updates_count = 0; diff --git a/src/commands/to_release.rs b/src/commands/to_release.rs index 603736d..2ca94d2 100644 --- a/src/commands/to_release.rs +++ b/src/commands/to_release.rs @@ -21,7 +21,7 @@ where let mut graph = Graph::::new(); let members = members_deep(ws); - let (members, to_ignore): (Vec<_>, Vec<_>) = members.iter().partition(|m| predicate(&m)); + let (members, to_ignore): (Vec<_>, Vec<_>) = members.iter().partition(|m| predicate(m)); let ignored = to_ignore .into_iter() @@ -106,7 +106,7 @@ where let indices = petgraph::algo::toposort(&graph, None).map_err(|c| { format!( "Cycle detected: {:}", - graph.node_weight(c.node_id()).unwrap().name().to_string() + graph.node_weight(c.node_id()).unwrap().name() ) })?; let packages = indices