From 442a9205e9747c40abeab72e7cae872637b47c42 Mon Sep 17 00:00:00 2001 From: Aria Beingessner Date: Wed, 22 Nov 2023 08:39:45 -0500 Subject: [PATCH] feat: give libraries empty Releases --- cargo-dist/src/announce.rs | 36 ++++++++++--------- cargo-dist/src/tasks.rs | 6 ++++ cargo-dist/src/tests/mock.rs | 8 +++++ cargo-dist/src/tests/tag.rs | 4 +-- cargo-dist/tests/snapshots/lib_manifest.snap | 12 ++++++- .../tests/snapshots/lib_manifest_slash.snap | 12 ++++++- 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/cargo-dist/src/announce.rs b/cargo-dist/src/announce.rs index 15de771cc..88c5ceac9 100644 --- a/cargo-dist/src/announce.rs +++ b/cargo-dist/src/announce.rs @@ -8,7 +8,7 @@ use axotag::{parse_tag, Package, PartialAnnouncementTag, ReleaseType}; use cargo_dist_schema::DistManifest; use itertools::Itertools; use semver::Version; -use tracing::{info, warn}; +use tracing::info; use crate::{ errors::{DistError, DistResult}, @@ -185,22 +185,16 @@ pub(crate) fn select_tag( // Don't proceed if the conclusions don't make sense if rust_releases.is_empty() { - // It's ok for there to be no selected binaries if the user explicitly requested an - // announcement for a library with `--tag=my-lib-1.0.0` - if matches!(announcing.release, ReleaseType::Package(_)) { - warn!("You're trying to explicitly Release a library, only minimal functionality will work"); - } else { - // No binaries were selected, and they weren't trying to announce a library, - // we've gotta bail out, this is too weird. - // - // To get better help messages, we explore a hypothetical world where they didn't pass - // `--tag` so we can get all the options for a good help message. - let announcing = PartialAnnouncementTag::default(); - let rust_releases = select_packages(graph, &announcing); - let versions = possible_tags(graph, rust_releases.iter().map(|(idx, _)| *idx)); - let help = tag_help(graph, versions, "You may need to pass the current version as --tag, or need to give all your packages the same version"); - return Err(DistError::NothingToRelease { help }); - } + // No binaries were selected, and they weren't trying to announce a library, + // we've gotta bail out, this is too weird. + // + // To get better help messages, we explore a hypothetical world where they didn't pass + // `--tag` so we can get all the options for a good help message. + let announcing = PartialAnnouncementTag::default(); + let rust_releases = select_packages(graph, &announcing); + let versions = possible_tags(graph, rust_releases.iter().map(|(idx, _)| *idx)); + let help = tag_help(graph, versions, "You may need to pass the current version as --tag, or need to give all your packages the same version"); + return Err(DistError::NothingToRelease { help }); } // If we don't have a tag yet we MUST successfully select one here or fail @@ -298,6 +292,14 @@ fn select_packages( } info!(""); + // If no binaries were selected but we are trying to specifically release One Package, + // add that package as a release still, on the assumption it's a Library + if rust_releases.is_empty() { + if let ReleaseType::Package(idx) = announcing.release { + rust_releases.push((PackageIdx(idx), vec![])); + } + } + rust_releases } diff --git a/cargo-dist/src/tasks.rs b/cargo-dist/src/tasks.rs index 8ae68dd8a..54f1ec513 100644 --- a/cargo-dist/src/tasks.rs +++ b/cargo-dist/src/tasks.rs @@ -1997,6 +1997,12 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { // Create a Release for this binary let release = self.add_release(*pkg_idx); + // Don't bother with any of this without binaries + // (releases a library, nothing to Build) + if binaries.is_empty() { + continue; + } + // Tell the Release to include these binaries for binary in binaries { self.add_binary(release, *pkg_idx, (*binary).clone()); diff --git a/cargo-dist/src/tests/mock.rs b/cargo-dist/src/tests/mock.rs index d57514175..5b0b66e4d 100644 --- a/cargo-dist/src/tests/mock.rs +++ b/cargo-dist/src/tests/mock.rs @@ -14,6 +14,7 @@ pub const BIN_AXO_IDX: PackageIdx = PackageIdx(0); pub const LIB_SOME_NAME: &str = "some-lib"; pub const LIB_SOME_VER: &str = BIN_AXO_VER; +pub const LIB_SOME_IDX: PackageIdx = PackageIdx(1); pub const BIN_HELPER_NAME: &str = "helper-bin"; pub const BIN_HELPER_NAME2: &str = "helper-bin-utils"; @@ -22,6 +23,7 @@ pub const BIN_HELPER_IDX: PackageIdx = PackageIdx(2); pub const LIB_OTHER_NAME: &str = "other-lib"; pub const LIB_OTHER_VER: &str = "0.5.0"; +pub const LIB_OTHER_IDX: PackageIdx = PackageIdx(3); pub const BIN_ODDBALL_NAME: &str = "oddball-bin"; pub const BIN_ODDBALL_VER: &str = "0.1.0"; @@ -118,6 +120,9 @@ pub fn pkg_some_lib() -> PackageInfo { ..mock_package(LIB_SOME_NAME, LIB_SOME_VER) } } +pub fn entry_some_lib() -> (PackageIdx, Vec) { + (LIB_SOME_IDX, vec![]) +} /// helper-bin 1.0.0 (has 2 binaries) pub fn pkg_helper_bin() -> PackageInfo { @@ -139,6 +144,9 @@ pub fn pkg_other_lib() -> PackageInfo { ..mock_package(LIB_OTHER_NAME, LIB_OTHER_VER) } } +pub fn entry_other_lib() -> (PackageIdx, Vec) { + (LIB_OTHER_IDX, vec![]) +} /// oddball-bin 0.1.0 (non-harmonious version) pub fn pkg_oddball_bin() -> PackageInfo { diff --git a/cargo-dist/src/tests/tag.rs b/cargo-dist/src/tests/tag.rs index 755396a79..23c7d1b37 100644 --- a/cargo-dist/src/tests/tag.rs +++ b/cargo-dist/src/tests/tag.rs @@ -319,7 +319,7 @@ fn parse_unified_lib() { assert!(!announcing.prerelease); assert_eq!(announcing.tag, tag); assert_eq!(announcing.version, None); - assert_eq!(announcing.rust_releases, vec![]); + assert_eq!(announcing.rust_releases, vec![entry_some_lib()]); } #[test] @@ -394,5 +394,5 @@ fn parse_disjoint_lib() { assert!(!announcing.prerelease); assert_eq!(announcing.tag, tag); assert_eq!(announcing.version, None); - assert_eq!(announcing.rust_releases, vec![]); + assert_eq!(announcing.rust_releases, vec![entry_other_lib()]); } diff --git a/cargo-dist/tests/snapshots/lib_manifest.snap b/cargo-dist/tests/snapshots/lib_manifest.snap index 7c6a654b9..b9f6829c6 100644 --- a/cargo-dist/tests/snapshots/lib_manifest.snap +++ b/cargo-dist/tests/snapshots/lib_manifest.snap @@ -13,6 +13,17 @@ stdout: "system_info": { "cargo_version_line": "CENSORED" }, + "releases": [ + { + "app_name": "cargo-dist-schema", + "app_version": "1.0.0-FAKEVERSION", + "hosting": { + "github": { + "artifact_download_url": "https://github.com/axodotdev/cargo-dist/releases/download/cargo-dist-schema-v1.0.0-FAKEVERSION" + } + } + } + ], "publish_prereleases": false, "ci": { "github": { @@ -24,5 +35,4 @@ stdout: } stderr: - WARN You're trying to explicitly Release a library, only minimal functionality will work diff --git a/cargo-dist/tests/snapshots/lib_manifest_slash.snap b/cargo-dist/tests/snapshots/lib_manifest_slash.snap index 7c6a654b9..b07c1764e 100644 --- a/cargo-dist/tests/snapshots/lib_manifest_slash.snap +++ b/cargo-dist/tests/snapshots/lib_manifest_slash.snap @@ -13,6 +13,17 @@ stdout: "system_info": { "cargo_version_line": "CENSORED" }, + "releases": [ + { + "app_name": "cargo-dist-schema", + "app_version": "1.0.0-FAKEVERSION", + "hosting": { + "github": { + "artifact_download_url": "https://github.com/axodotdev/cargo-dist/releases/download/cargo-dist-schema/v1.0.0-FAKEVERSION" + } + } + } + ], "publish_prereleases": false, "ci": { "github": { @@ -24,5 +35,4 @@ stdout: } stderr: - WARN You're trying to explicitly Release a library, only minimal functionality will work