Skip to content

Commit

Permalink
feat: give libraries empty Releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Nov 22, 2023
1 parent 8ffe1b5 commit 442a920
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
36 changes: 19 additions & 17 deletions cargo-dist/src/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions cargo-dist/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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<String>) {
(LIB_SOME_IDX, vec![])
}

/// helper-bin 1.0.0 (has 2 binaries)
pub fn pkg_helper_bin() -> PackageInfo {
Expand All @@ -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<String>) {
(LIB_OTHER_IDX, vec![])
}

/// oddball-bin 0.1.0 (non-harmonious version)
pub fn pkg_oddball_bin() -> PackageInfo {
Expand Down
4 changes: 2 additions & 2 deletions cargo-dist/src/tests/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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()]);
}
12 changes: 11 additions & 1 deletion cargo-dist/tests/snapshots/lib_manifest.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -24,5 +35,4 @@ stdout:
}

stderr:
WARN You're trying to explicitly Release a library, only minimal functionality will work

12 changes: 11 additions & 1 deletion cargo-dist/tests/snapshots/lib_manifest_slash.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -24,5 +35,4 @@ stdout:
}

stderr:
WARN You're trying to explicitly Release a library, only minimal functionality will work

0 comments on commit 442a920

Please sign in to comment.