Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
feat: put generic behind a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Nov 7, 2023
1 parent 77242be commit 574debe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ name = "axoproject"
required-features = ["cli"]

[features]
default = ["cli", "cargo-projects", "npm-projects"]
default = ["cli", "generic-projects", "cargo-projects", "npm-projects"]
cli = ["axocli"]
cargo-projects = ["guppy"]
generic-projects = ["semver"]
cargo-projects = ["guppy", "semver"]
npm-projects = ["oro-common", "oro-package-spec", "node-semver"]

[dependencies]
Expand All @@ -37,7 +38,7 @@ guppy = { version = "0.17.1", optional = true }
tracing = "0.1.40"
oro-common = { version = "0.3.34", optional = true }
serde = "1.0.192"
semver = { version = "1.0.20", default-features = true, features = ["serde"] }
semver = { version = "1.0.20", optional = true, default-features = true, features = ["serde"] }
node-semver = { version = "2.1.0", optional = true }
oro-package-spec = { version = "0.3.34", optional = true }
thiserror = "1.0.50"
Expand Down
21 changes: 0 additions & 21 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,4 @@ pub enum AxoprojectError {
/// Version we were looking for
version: Version,
},

/// Indicates the package specification doesn't include the specified field.
/// Primarily occurs with generic packages, where this is manually specified
#[error("Manifest field {field} was not specified for this workspace!")]
ManifestFieldMissing {
/// Field name
field: String,
},

/// Incorrect type for a field when parsing dist.toml
#[error(
"Value in manifest field {field} has the wrong value; expected {expected}, got {actual}"
)]
ManifestWrongType {
/// Field name
field: String,
/// Expected type name
expected: String,
/// Actual type name
actual: String,
},
}
27 changes: 24 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub use guppy::PackageId;

pub mod changelog;
pub mod errors;
#[cfg(feature = "generic-projects")]
pub mod generic;
#[cfg(feature = "npm-projects")]
pub mod javascript;
Expand All @@ -36,6 +37,7 @@ use crate::repo::GithubRepoInput;
/// Information about various kinds of workspaces
pub struct Workspaces {
/// Info about the generic workspace
#[cfg(feature = "generic-projects")]
pub generic: WorkspaceSearch,
/// Info about the cargo/rust workspace
#[cfg(feature = "cargo-projects")]
Expand All @@ -54,6 +56,7 @@ impl Workspaces {
let mut max_depth = 0;
let mut projects = vec![];

#[cfg(feature = "generic-projects")]
projects.push(self.generic);

// FIXME: should we provide feedback/logging here?
Expand Down Expand Up @@ -102,6 +105,7 @@ pub enum WorkspaceSearch {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum WorkspaceKind {
/// generic cargo-dist compatible workspace
#[cfg(feature = "generic-projects")]
Generic,
/// cargo/rust workspace
#[cfg(feature = "cargo-projects")]
Expand Down Expand Up @@ -322,6 +326,7 @@ pub struct PackageIdx(pub usize);
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Version {
/// generic version (assumed to be semver)
#[cfg(feature = "generic-projects")]
Generic(semver::Version),
/// cargo version
#[cfg(feature = "cargo-projects")]
Expand All @@ -334,6 +339,7 @@ pub enum Version {
impl Display for Version {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
#[cfg(feature = "generic-projects")]
Version::Generic(v) => v.fmt(f),
#[cfg(feature = "cargo-projects")]
Version::Cargo(v) => v.fmt(f),
Expand All @@ -347,11 +353,23 @@ impl Version {
/// Assume it's a cargo Version
#[cfg(feature = "cargo-projects")]
pub fn cargo(&self) -> &semver::Version {
#[allow(irrefutable_let_patterns)]
if let Version::Cargo(v) = self {
v
} else {
panic!("Version wasn't in the cargo format")
}
}

/// Returns a semver-based Version
pub fn semver(&self) -> &semver::Version {
#[allow(unreachable_patterns)]
match self {
// For now treat generic versions as cargo versions
Version::Cargo(v) | Version::Generic(v) => v,
_ => panic!("Version wasn't in the cargo format"),
#[cfg(feature = "generic-projects")]
Version::Generic(v) => v,
#[cfg(feature = "cargo-projects")]
Version::Cargo(v) => v,
_ => panic!("Version wasn't in semver format"),
}
}

Expand All @@ -369,6 +387,7 @@ impl Version {
/// Returns whether the version is stable (no pre/build component)
pub fn is_stable(&self) -> bool {
match self {
#[cfg(feature = "generic-projects")]
Version::Generic(v) => v.pre.is_empty() && v.build.is_empty(),
#[cfg(feature = "cargo-projects")]
Version::Cargo(v) => v.pre.is_empty() && v.build.is_empty(),
Expand All @@ -380,6 +399,7 @@ impl Version {
/// Gets a copy of the version with only the stable parts (pre/build components stripped)
pub fn stable_part(&self) -> Self {
match self {
#[cfg(feature = "generic-projects")]
Version::Generic(v) => {
Version::Generic(semver::Version::new(v.major, v.minor, v.patch))
}
Expand Down Expand Up @@ -427,6 +447,7 @@ pub struct AutoIncludes {
/// the top level [`WorkspaceKind`][].
pub fn get_workspaces(start_dir: &Utf8Path, clamp_to_dir: Option<&Utf8Path>) -> Workspaces {
Workspaces {
#[cfg(feature = "generic-projects")]
generic: generic::get_workspace(start_dir, clamp_to_dir),
#[cfg(feature = "cargo-projects")]
rust: rust::get_workspace(start_dir, clamp_to_dir),
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn real_main(app: &axocli::CliApp<Cli>) -> Result<(), Report> {
}

fn print_searches(workspaces: Workspaces) {
#[cfg(feature = "generic-projects")]
print_search(workspaces.generic, "generic");
#[cfg(feature = "cargo-projects")]
print_search(workspaces.rust, "rust");
Expand Down Expand Up @@ -159,6 +160,7 @@ fn print_workspace(project: &WorkspaceInfo) {
fn print_searches_json(root: Option<&Utf8Path>, workspaces: Workspaces) {
let output = JsonOutput {
root: root.map(|p| p.to_owned()),
#[cfg(feature = "generic-projects")]
generic: JsonWorkspaceSearch::from_real(root, workspaces.generic),
#[cfg(feature = "cargo-projects")]
rust: JsonWorkspaceSearch::from_real(root, workspaces.rust),
Expand All @@ -172,6 +174,7 @@ fn print_searches_json(root: Option<&Utf8Path>, workspaces: Workspaces) {
#[derive(Serialize, Deserialize)]
struct JsonOutput {
root: Option<Utf8PathBuf>,
#[cfg(feature = "generic-projects")]
generic: JsonWorkspaceSearch,
#[cfg(feature = "cargo-projects")]
rust: JsonWorkspaceSearch,
Expand Down Expand Up @@ -361,6 +364,7 @@ impl JsonRelPath {
#[derive(Debug, Serialize, Deserialize)]
pub enum JsonWorkspaceKind {
/// generic workspace
#[cfg(feature = "generic-projects")]
#[serde(rename = "generic")]
Generic,
/// cargo/rust workspace
Expand All @@ -376,6 +380,7 @@ pub enum JsonWorkspaceKind {
impl JsonWorkspaceKind {
fn from_real(real: WorkspaceKind) -> Self {
match real {
#[cfg(feature = "generic-projects")]
WorkspaceKind::Generic => Self::Generic,
#[cfg(feature = "cargo-projects")]
WorkspaceKind::Rust => Self::Rust,
Expand Down

0 comments on commit 574debe

Please sign in to comment.