diff --git a/MIGRATING_v8_to_v9.md b/MIGRATING_v8_to_v9.md index 2c14c17c..1b09df79 100644 --- a/MIGRATING_v8_to_v9.md +++ b/MIGRATING_v8_to_v9.md @@ -21,10 +21,10 @@ use vergen::{ pub fn main() -> Result<()> { Emitter::default() - .add_instructions(&BuildBuilder::all_build()?)? - .add_instructions(&CargoBuilder::all_cargo()?)? - .add_instructions(&RustcBuilder::all_rustc()?)? - .add_instructions(&SysinfoBuilder::all_sysinfo()?)? + .add_instructions(&Build::all_build()?) + .add_instructions(&Cargo::all_cargo()?) + .add_instructions(&Rustc::all_rustc()?) + .add_instructions(&Sysinfo::all_sysinfo()?) .emit() } ``` @@ -54,11 +54,11 @@ use vergen_gix::{ pub fn main() -> Result<()> { Emitter::default() - .add_instructions(&BuildBuilder::all_build()?)? - .add_instructions(&CargoBuilder::all_cargo()?)? - .add_instructions(&GixBuilder::all_git()?)? - .add_instructions(&RustcBuilder::all_rustc()?)? - .add_instructions(&SysinfoBuilder::all_sysinfo()?)? + .add_instructions(&Build::all_build()?) + .add_instructions(&Cargo::all_cargo()?) + .add_instructions(&Gix::all_git()?) + .add_instructions(&Rustc::all_rustc()?) + .add_instructions(&Sysinfo::all_sysinfo()?) .emit() } ``` @@ -87,11 +87,11 @@ use vergen_gitcl::{ pub fn main() -> Result<()> { Emitter::default() - .add_instructions(&BuildBuilder::all_build()?)? - .add_instructions(&CargoBuilder::all_cargo()?)? - .add_instructions(&GitclBuilder::all_git()?)? - .add_instructions(&RustcBuilder::all_rustc()?)? - .add_instructions(&SysinfoBuilder::all_sysinfo()?)? + .add_instructions(&Build::all_build()?) + .add_instructions(&Cargo::all_cargo()?) + .add_instructions(&Gitcl::all_git()?) + .add_instructions(&Rustc::all_rustc()?) + .add_instructions(&Sysinfo::all_sysinfo()?) .emit() } ``` @@ -120,11 +120,11 @@ use vergen_git2::{ pub fn main() -> Result<()> { Emitter::default() - .add_instructions(&BuildBuilder::all_build()?)? - .add_instructions(&CargoBuilder::all_cargo()?)? - .add_instructions(&Git2Builder::all_git()?)? - .add_instructions(&RustcBuilder::all_rustc()?)? - .add_instructions(&SysinfoBuilder::all_sysinfo()?)? + .add_instructions(&Build::all_build()?) + .add_instructions(&Cargo::all_cargo()?) + .add_instructions(&Git2::all_git()?) + .add_instructions(&Rustc::all_rustc()?) + .add_instructions(&Sysinfo::all_sysinfo()?) .emit() } -``` \ No newline at end of file +``` diff --git a/vergen-git2/src/git2/mod.rs b/vergen-git2/src/git2/mod.rs index a9ba61ba..6e82f3b6 100644 --- a/vergen-git2/src/git2/mod.rs +++ b/vergen-git2/src/git2/mod.rs @@ -22,6 +22,7 @@ use time::{ format_description::{self, well_known::Iso8601}, OffsetDateTime, UtcOffset, }; +use vergen_lib::git_config::{Describe, Dirty, Sha}; use vergen_lib::{ add_default_map_entry, add_map_entry, constants::{ @@ -51,7 +52,7 @@ use vergen_lib::{ /// /// ``` /// # use anyhow::Result; -/// # use vergen_git2::{Emitter, Git2Builder}; +/// # use vergen_git2::{Emitter, Git2}; /// # /// # fn main() -> Result<()> { /// let git2 = Git2::all_git(); @@ -64,7 +65,7 @@ use vergen_lib::{ /// /// ``` /// # use anyhow::Result; -/// # use vergen_git2::{Emitter, Git2Builder}; +/// # use vergen_git2::{Emitter, Git2}; /// # /// # fn main() -> Result<()> { /// temp_env::with_var("VERGEN_GIT_BRANCH", Some("this is the branch I want output"), || { @@ -82,6 +83,11 @@ use vergen_lib::{ #[derive(Clone, Debug, bon::Builder, PartialEq)] #[allow(clippy::struct_excessive_bools)] pub struct Git2 { + /// Configures the default values. + /// If set to `true` all defaults are in "enabled" state. + /// If set to `false` all defaults are in "disabled" state. + #[builder(field)] + all: bool, /// An optional path to a repository. repo_path: Option, /// Emit the current git branch @@ -90,7 +96,7 @@ pub struct Git2 { /// cargo:rustc-env=VERGEN_GIT_BRANCH= /// ``` /// - #[builder(default)] + #[builder(default = all)] branch: bool, /// Emit the author email of the most recent commit /// @@ -98,7 +104,7 @@ pub struct Git2 { /// cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_EMAIL= /// ``` /// - #[builder(default)] + #[builder(default = all)] commit_author_name: bool, /// Emit the author name of the most recent commit /// @@ -106,14 +112,14 @@ pub struct Git2 { /// cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_NAME= /// ``` /// - #[builder(default)] + #[builder(default = all)] commit_author_email: bool, /// Emit the total commit count to HEAD /// /// ```text /// cargo:rustc-env=VERGEN_GIT_COMMIT_COUNT= /// ``` - #[builder(default)] + #[builder(default = all)] commit_count: bool, /// Emit the commit message of the latest commit /// @@ -121,7 +127,7 @@ pub struct Git2 { /// cargo:rustc-env=VERGEN_GIT_COMMIT_MESSAGE= /// ``` /// - #[builder(default)] + #[builder(default = all)] commit_message: bool, /// Emit the commit date of the latest commit /// @@ -129,7 +135,7 @@ pub struct Git2 { /// cargo:rustc-env=VERGEN_GIT_COMMIT_DATE= /// ``` /// - #[builder(default)] + #[builder(default = all)] commit_date: bool, /// Emit the commit timestamp of the latest commit /// @@ -137,7 +143,7 @@ pub struct Git2 { /// cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP= /// ``` /// - #[builder(default)] + #[builder(default = all)] commit_timestamp: bool, /// Emit the describe output /// @@ -156,10 +162,14 @@ pub struct Git2 { /// /// ## `match_pattern` /// Only consider tags matching the given glob pattern, excluding the "refs/tags/" prefix. - #[builder(with = |tags: bool, dirty: bool, match_pattern: Option<&'static str>| { - Git2Describe { tags, dirty, match_pattern } - })] - describe: Option, + #[builder( + required, + default = all.then(Describe::default), + with = |tags: bool, dirty: bool, match_pattern: Option<&'static str>| { + Some(Describe { tags, dirty, match_pattern }) + } + )] + describe: Option, /// Emit the SHA of the latest commit /// /// ```text @@ -171,9 +181,12 @@ pub struct Git2 { /// /// ## `short` /// Shortens the object name to a unique prefix - /// - #[builder(with = |short: bool| Git2Sha { short })] - sha: Option, + #[builder( + required, + default = all.then(Sha::default), + with = |short: bool| Some(Sha { short }) + )] + sha: Option, /// Emit the dirty state of the git repository /// ```text /// cargo:rustc-env=VERGEN_GIT_DIRTY=(true|false) @@ -183,8 +196,12 @@ pub struct Git2 { /// /// # `include_tracked` /// Should we include/ignore untracked files in deciding whether the repository is dirty. - #[builder(with = |include_untracked: bool| Git2Dirty { include_untracked })] - dirty: Option, + #[builder( + required, + default = all.then(Dirty::default), + with = |include_untracked: bool| Some(Dirty { include_untracked }) + )] + dirty: Option, /// Enable local offset date/timestamp output #[builder(default)] use_local: bool, @@ -194,104 +211,23 @@ pub struct Git2 { fail: bool, } -#[derive(Clone, Debug, PartialEq)] -struct Git2Describe { - tags: bool, - dirty: bool, - match_pattern: Option<&'static str>, -} - -#[derive(Clone, Debug, PartialEq)] -struct Git2Dirty { - include_untracked: bool, -} - -#[derive(Clone, Debug, PartialEq)] -struct Git2Sha { - short: bool, +impl Git2Builder { + /// Convenience method that switches the defaults of [`Git2Builder`] + /// to enable all of the `VERGEN_GIT_*` instructions. It can only be + /// called at the start of the building process, i.e. when no config + /// has been set yet to avoid overwrites. + pub fn all(mut self) -> Self { + self.all = true; + self + } } -#[bon::bon] impl Git2 { /// Emit all of the `VERGEN_GIT_*` instructions - /// - /// # Errors - /// The underlying build function can error - /// pub fn all_git() -> Self { - Self::builder() - .branch(true) - .commit_author_email(true) - .commit_author_name(true) - .commit_count(true) - .commit_date(true) - .commit_message(true) - .commit_timestamp(true) - .describe(false, false, None) - .sha(false) - .dirty(false) - .build() + Self::builder().all().build() } - /// Convenience method to setup the [`Git2Builder`] with all of the `VERGEN_GIT_*` instructions on - #[builder(builder_type = Git2AllBuilder, finish_fn = build)] - pub fn all_builder( - repo_path: Option, - #[builder(default = true)] branch: bool, - #[builder(default = true)] commit_author_name: bool, - #[builder(default = true)] commit_author_email: bool, - #[builder(default = true)] commit_count: bool, - #[builder(default = true)] commit_message: bool, - #[builder(default = true)] commit_date: bool, - #[builder(default = true)] commit_timestamp: bool, - - #[builder( - with = |tags: bool, dirty: bool, match_pattern: Option<&'static str>| { - Git2Describe { tags, dirty, match_pattern } - }, - default = Git2Describe { tags: false, dirty: false, match_pattern: None } - )] - describe: Git2Describe, - - #[builder( - with = |short: bool| Git2Sha { short }, - default = Git2Sha { short: false } - )] - sha: Git2Sha, - - #[builder( - with = |include_untracked: bool| Git2Dirty { include_untracked }, - default = Git2Dirty { include_untracked: false } - )] - dirty: Git2Dirty, - - #[builder(default)] use_local: bool, - - #[cfg(test)] - #[builder(default)] - fail: bool, - ) -> Self { - Self { - repo_path, - branch, - commit_author_email, - commit_author_name, - commit_count, - commit_date, - commit_message, - commit_timestamp, - describe: Some(describe), - sha: Some(sha), - dirty: Some(dirty), - use_local, - - #[cfg(test)] - fail, - } - } -} - -impl Git2 { fn any(&self) -> bool { self.branch || self.commit_author_email diff --git a/vergen-git2/src/lib.rs b/vergen-git2/src/lib.rs index f2703329..cf12fdc6 100644 --- a/vergen-git2/src/lib.rs +++ b/vergen-git2/src/lib.rs @@ -59,22 +59,22 @@ //! //! ``` //! # use anyhow::Result; -//! # use vergen_git2::{Emitter, Git2Builder}; -#![cfg_attr(feature = "build", doc = r"# use vergen_git2::BuildBuilder;")] -#![cfg_attr(feature = "cargo", doc = r"# use vergen_git2::CargoBuilder;")] -#![cfg_attr(feature = "rustc", doc = r"# use vergen_git2::RustcBuilder;")] -#![cfg_attr(feature = "si", doc = r"# use vergen_git2::SysinfoBuilder;")] +//! # use vergen_git2::{Emitter, Git2}; +#![cfg_attr(feature = "build", doc = r"# use vergen_git2::Build;")] +#![cfg_attr(feature = "cargo", doc = r"# use vergen_git2::Cargo;")] +#![cfg_attr(feature = "rustc", doc = r"# use vergen_git2::Rustc;")] +#![cfg_attr(feature = "si", doc = r"# use vergen_git2::Sysinfo;")] #![cfg_attr(feature = "cargo", doc = r"# use test_util::with_cargo_vars;")] //! # //! # pub fn main() -> Result<()> { #![cfg_attr(feature = "cargo", doc = r"# let result = with_cargo_vars(|| {")] //! // NOTE: This will output everything, and requires all features enabled. //! // NOTE: See the specific builder documentation for configuration options. -#![cfg_attr(feature = "build", doc = r"let build = BuildBuilder::all_build()?;")] -#![cfg_attr(feature = "cargo", doc = r"let cargo = CargoBuilder::all_cargo()?;")] -//! let git2 = Git2Builder::all_git()?; -#![cfg_attr(feature = "rustc", doc = r"let rustc = RustcBuilder::all_rustc()?;")] -#![cfg_attr(feature = "si", doc = r"let si = SysinfoBuilder::all_sysinfo()?;")] +#![cfg_attr(feature = "build", doc = r"let build = Build::all_build();")] +#![cfg_attr(feature = "cargo", doc = r"let cargo = Cargo::all_cargo();")] +//! let git2 = Git2::all_git(); +#![cfg_attr(feature = "rustc", doc = r"let rustc = Rustc::all_rustc();")] +#![cfg_attr(feature = "si", doc = r"let si = Sysinfo::all_sysinfo();")] //! //! Emitter::default() #![cfg_attr(feature = "build", doc = r" .add_instructions(&build)?")] @@ -137,11 +137,11 @@ //! //! ``` //! # use anyhow::Result; -//! # use vergen_git2::{Emitter, Git2Builder}; -#![cfg_attr(feature = "build", doc = r"# use vergen_git2::BuildBuilder;")] -#![cfg_attr(feature = "cargo", doc = r"# use vergen_git2::CargoBuilder;")] -#![cfg_attr(feature = "rustc", doc = r"# use vergen_git2::RustcBuilder;")] -#![cfg_attr(feature = "si", doc = r"# use vergen_git2::SysinfoBuilder;")] +//! # use vergen_git2::{Emitter, Git2}; +#![cfg_attr(feature = "build", doc = r"# use vergen_git2::Build;")] +#![cfg_attr(feature = "cargo", doc = r"# use vergen_git2::Cargo;")] +#![cfg_attr(feature = "rustc", doc = r"# use vergen_git2::Rustc;")] +#![cfg_attr(feature = "si", doc = r"# use vergen_git2::Sysinfo;")] #![cfg_attr(feature = "cargo", doc = r"# use test_util::with_cargo_vars;")] //! # //! # pub fn main() -> Result<()> { @@ -149,21 +149,21 @@ #![cfg_attr( feature = "build", doc = r"// NOTE: This will output only the instructions specified. -// NOTE: See the specific builder documentation for configuration options. -let build = BuildBuilder::default().build_timestamp(true).build()?;" +// NOTE: See the specific builder documentation for configuration options. +let build = Build::builder().build_timestamp(true).build();" )] #![cfg_attr( feature = "cargo", - doc = r"let cargo = CargoBuilder::default().opt_level(true).build()?;" + doc = r"let cargo = Cargo::builder().opt_level(true).build();" )] -//! let git2 = Git2Builder::default().commit_timestamp(true).build()?; +//! let git2 = Git2::builder().commit_timestamp(true).build(); #![cfg_attr( feature = "rustc", - doc = r"let rustc = RustcBuilder::default().semver(true).build()?;" + doc = r"let rustc = Rustc::builder().semver(true).build();" )] #![cfg_attr( feature = "si", - doc = r"let si = SysinfoBuilder::default().cpu_core_count(true).build()?;" + doc = r"let si = Sysinfo::builder().cpu_core_count(true).build();" )] //! //! Emitter::default() @@ -209,7 +209,7 @@ let build = BuildBuilder::default().build_timestamp(true).build()?;" //! ``` //! //! ## Features -//! `vergen-git2` has four main feature toggles allowing you to customize your output. No features are enabled by default. +//! `vergen-git2` has four main feature toggles allowing you to customize your output. No features are enabled by default. //! You **must** specifically enable the features you wish to use. //! //! | Feature | Enables | diff --git a/vergen-git2/tests/git_output.rs b/vergen-git2/tests/git_output.rs index d958d40c..84a9b505 100644 --- a/vergen-git2/tests/git_output.rs +++ b/vergen-git2/tests/git_output.rs @@ -174,7 +174,8 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_flags_test_repo() -> Result<()> { let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut git2 = Git2::all_builder() + let mut git2 = Git2::builder() + .all() .describe(true, false, None) .sha(true) .build(); @@ -194,7 +195,8 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_flags_test_repo_local() -> Result<()> { let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut git2 = Git2::all_builder() + let mut git2 = Git2::builder() + .all() .describe(true, false, None) .sha(true) .use_local(true) @@ -231,7 +233,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_output_test_repo() -> Result<()> { let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut git2 = Git2::all_builder().describe(true, false, None).build(); + let mut git2 = Git2::builder().all().describe(true, false, None).build(); let _ = git2.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&git2)? @@ -247,7 +249,8 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_describe_all_test_repo() -> Result<()> { let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut git2 = Git2::all_builder() + let mut git2 = Git2::builder() + .all() .describe(true, true, Some("0.1.0")) .build(); let _ = git2.at_path(repo.path()); @@ -264,7 +267,8 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_emit_at_test_repo() -> Result<()> { let repo = TestRepos::new(true, false, false)?; - let mut git2 = Git2::all_builder() + let mut git2 = Git2::builder() + .all() .describe(true, false, None) .sha(true) .build(); diff --git a/vergen-gitcl/Cargo.toml b/vergen-gitcl/Cargo.toml index 91bb8ad1..74ebfb5e 100644 --- a/vergen-gitcl/Cargo.toml +++ b/vergen-gitcl/Cargo.toml @@ -34,7 +34,7 @@ si = ["vergen/si"] [dependencies] anyhow = "1.0.95" -derive_builder = "0.20.2" +bon = "3.3.2" time = { version = "0.3.37", features = [ "formatting", "local-offset", diff --git a/vergen-gitcl/src/gitcl/mod.rs b/vergen-gitcl/src/gitcl/mod.rs index 27cfc7d4..33adb80f 100644 --- a/vergen-gitcl/src/gitcl/mod.rs +++ b/vergen-gitcl/src/gitcl/mod.rs @@ -7,7 +7,6 @@ // modified, or distributed except according to those terms. use anyhow::{anyhow, Error, Result}; -use derive_builder::Builder as DeriveBuilder; use std::{ env::{self, VarError}, path::PathBuf, @@ -21,6 +20,7 @@ use time::{ }, OffsetDateTime, UtcOffset, }; +use vergen_lib::git_config::{Describe, Dirty, Sha}; use vergen_lib::{ add_default_map_entry, add_map_entry, constants::{ @@ -112,10 +112,10 @@ const DIRTY: &str = dirty!(); /// /// ``` /// # use anyhow::Result; -/// # use vergen_gitcl::{Emitter, GitclBuilder}; +/// # use vergen_gitcl::{Emitter, Gitcl}; /// # /// # fn main() -> Result<()> { -/// let gitcl = GitclBuilder::all_git()?; +/// let gitcl = Gitcl::all_git(); /// Emitter::default().add_instructions(&gitcl)?.emit()?; /// # Ok(()) /// # } @@ -125,10 +125,10 @@ const DIRTY: &str = dirty!(); /// /// ``` /// # use anyhow::Result; -/// # use vergen_gitcl::{Emitter, GitclBuilder}; +/// # use vergen_gitcl::{Emitter, Gitcl}; /// # /// # fn main() -> Result<()> { -/// let gitcl = GitclBuilder::default().describe(true, false, None).build()?; +/// let gitcl = Gitcl::builder().describe(true, false, None).build(); /// Emitter::default().add_instructions(&gitcl)?.emit()?; /// # Ok(()) /// # } @@ -138,12 +138,12 @@ const DIRTY: &str = dirty!(); /// /// ``` /// # use anyhow::Result; -/// # use vergen_gitcl::{Emitter, GitclBuilder}; +/// # use vergen_gitcl::{Emitter, Gitcl}; /// # /// # fn main() -> Result<()> { /// temp_env::with_var("VERGEN_GIT_BRANCH", Some("this is the branch I want output"), || { /// let result = || -> Result<()> { -/// let gitcl = GitclBuilder::all_git()?; +/// let gitcl = Gitcl::all_git(); /// Emitter::default().add_instructions(&gitcl)?.emit()?; /// Ok(()) /// }(); @@ -160,12 +160,12 @@ const DIRTY: &str = dirty!(); /// /// ``` /// # use anyhow::Result; -/// # use vergen_gitcl::{Emitter, GitclBuilder}; +/// # use vergen_gitcl::{Emitter, Gitcl}; /// # /// # fn main() -> Result<()> { /// temp_env::with_var("SOURCE_DATE_EPOCH", Some("1671809360"), || { /// let result = || -> Result<()> { -/// let gitcl = GitclBuilder::all_git()?; +/// let gitcl = Gitcl::all_git(); /// Emitter::default().add_instructions(&gitcl)?.emit()?; /// Ok(()) /// }(); @@ -196,10 +196,10 @@ const DIRTY: &str = dirty!(); /// # Example /// ``` /// # use anyhow::Result; -/// # use vergen_gitcl::{Emitter, GitclBuilder}; +/// # use vergen_gitcl::{Emitter, Gitcl}; /// # /// # fn main() -> Result<()> { -/// let gitcl = GitclBuilder::all_git()?; +/// let gitcl = Gitcl::all_git(); /// Emitter::default().idempotent().add_instructions(&gitcl)?.emit()?; /// # Ok(()) /// # } @@ -231,11 +231,15 @@ const DIRTY: &str = dirty!(); /// cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH /// ``` /// -#[derive(Clone, Debug, DeriveBuilder, PartialEq)] +#[derive(Clone, Debug, bon::Builder, PartialEq)] #[allow(clippy::struct_excessive_bools)] pub struct Gitcl { + /// Configures the default values. + /// If set to `true` all defaults are in "enabled" state. + /// If set to `false` all defaults are in "disabled" state. + #[builder(field)] + all: bool, /// An optional path to a repository. - #[builder(default = "None")] repo_path: Option, /// Emit the current git branch /// @@ -243,7 +247,7 @@ pub struct Gitcl { /// cargo:rustc-env=VERGEN_GIT_BRANCH= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] branch: bool, /// Emit the author email of the most recent commit /// @@ -251,7 +255,7 @@ pub struct Gitcl { /// cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_EMAIL= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_author_name: bool, /// Emit the author name of the most recent commit /// @@ -259,14 +263,14 @@ pub struct Gitcl { /// cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_NAME= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_author_email: bool, /// Emit the total commit count to HEAD /// /// ```text /// cargo:rustc-env=VERGEN_GIT_COMMIT_COUNT= /// ``` - #[builder(default = "false")] + #[builder(default = all)] commit_count: bool, /// Emit the commit message of the latest commit /// @@ -274,7 +278,7 @@ pub struct Gitcl { /// cargo:rustc-env=VERGEN_GIT_COMMIT_MESSAGE= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_message: bool, /// Emit the commit date of the latest commit /// @@ -286,7 +290,7 @@ pub struct Gitcl { /// ```text #[doc = concat!(commit_date!())] /// ``` - #[builder(default = "false")] + #[builder(default = all)] commit_date: bool, /// Emit the commit timestamp of the latest commit /// @@ -294,7 +298,7 @@ pub struct Gitcl { /// cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_timestamp: bool, /// Emit the describe output /// @@ -305,17 +309,22 @@ pub struct Gitcl { /// Optionally, add the `dirty` or `tags` flag to describe. /// See [`git describe`](https://git-scm.com/docs/git-describe#_options) for more details /// - #[builder(default = "false", setter(custom))] - describe: bool, + /// ## `tags` /// Instead of using only the annotated tags, use any tag found in refs/tags namespace. - #[builder(default = "false", private)] - describe_tags: bool, + /// + /// ## `dirty` /// If the working tree has local modification "-dirty" is appended to it. - #[builder(default = "false", private)] - describe_dirty: bool, + /// + /// ## `match_pattern` /// Only consider tags matching the given glob pattern, excluding the "refs/tags/" prefix. - #[builder(default = "None", private)] - describe_match_pattern: Option<&'static str>, + #[builder( + required, + default = all.then(Describe::default), + with = |tags: bool, dirty: bool, match_pattern: Option<&'static str>| { + Some(Describe { tags, dirty, match_pattern }) + } + )] + describe: Option, /// Emit the SHA of the latest commit /// /// ```text @@ -325,11 +334,14 @@ pub struct Gitcl { /// Optionally, add the `short` flag to rev-parse. /// See [`git rev-parse`](https://git-scm.com/docs/git-rev-parse#_options_for_output) for more details. /// - #[builder(default = "false", setter(custom))] - sha: bool, + /// ## `short` /// Shortens the object name to a unique prefix - #[builder(default = "false", private)] - sha_short: bool, + #[builder( + required, + default = all.then(Sha::default), + with = |short: bool| Some(Sha { short }) + )] + sha: Option, /// Emit the dirty state of the git repository /// ```text /// cargo:rustc-env=VERGEN_GIT_DIRTY=(true|false) @@ -337,107 +349,38 @@ pub struct Gitcl { /// /// Optionally, include untracked files when determining the dirty status of the repository. /// - #[builder(default = "false", setter(custom))] - dirty: bool, + /// # `include_tracked` /// Should we include/ignore untracked files in deciding whether the repository is dirty. - #[builder(default = "false", private)] - dirty_include_untracked: bool, + #[builder( + required, + default = all.then(Dirty::default), + with = |include_untracked: bool| Some(Dirty { include_untracked }) + )] + dirty: Option, /// Enable local offset date/timestamp output - #[builder(default = "false")] + #[builder(default)] use_local: bool, /// Specify the git cmd you wish to use, i.e. `/usr/bin/git` - #[builder(default = "None")] git_cmd: Option<&'static str>, } impl GitclBuilder { - /// Emit all of the `VERGEN_GIT_*` instructions - /// - /// # Errors - /// The underlying build function can error - /// - pub fn all_git() -> Result { - Self::default() - .branch(true) - .commit_author_email(true) - .commit_author_name(true) - .commit_count(true) - .commit_date(true) - .commit_message(true) - .commit_timestamp(true) - .describe(false, false, None) - .sha(false) - .dirty(false) - .build() - .map_err(Into::into) - } - - /// Convenience method to setup the [`GitclBuilder`] with all of the `VERGEN_GIT_*` instructions on - pub fn all(&mut self) -> &mut Self { - self.branch(true) - .commit_author_email(true) - .commit_author_name(true) - .commit_count(true) - .commit_date(true) - .commit_message(true) - .commit_timestamp(true) - .describe(false, false, None) - .sha(false) - .dirty(false) - } - - /// Emit the describe output - /// - /// ```text - /// cargo:rustc-env=VERGEN_GIT_DESCRIBE= - /// ``` - /// - /// Optionally, add the `dirty` or `tags` flag to describe. - /// See [`git describe`](https://git-scm.com/docs/git-describe#_options) for more details - /// - pub fn describe( - &mut self, - tags: bool, - dirty: bool, - matches: Option<&'static str>, - ) -> &mut Self { - self.describe = Some(true); - let _ = self.describe_tags(tags); - let _ = self.describe_dirty(dirty); - let _ = self.describe_match_pattern(matches); - self - } - - /// Emit the dirty state of the git repository - /// ```text - /// cargo:rustc-env=VERGEN_GIT_DIRTY=(true|false) - /// ``` - /// - /// Optionally, include untracked files when determining the dirty status of the repository. - /// - pub fn dirty(&mut self, include_untracked: bool) -> &mut Self { - self.dirty = Some(true); - let _ = self.dirty_include_untracked(include_untracked); - self - } - - /// Emit the SHA of the latest commit - /// - /// ```text - /// cargo:rustc-env=VERGEN_GIT_SHA= - /// ``` - /// - /// Optionally, add the `short` flag to rev-parse. - /// See [`git rev-parse`](https://git-scm.com/docs/git-rev-parse#_options_for_output) for more details. - /// - pub fn sha(&mut self, short: bool) -> &mut Self { - self.sha = Some(true); - let _ = self.sha_short(short); + /// Convenience method that switches the defaults of [`GitclBuilder`] + /// to enable all of the `VERGEN_GIT_*` instructions. It can only be + /// called at the start of the building process, i.e. when no config + /// has been set yet to avoid overwrites. + pub fn all(mut self) -> Self { + self.all = true; self } } impl Gitcl { + /// Emit all of the `VERGEN_GIT_*` instructions + pub fn all_git() -> Self { + Self::builder().all().build() + } + fn any(&self) -> bool { self.branch || self.commit_author_email @@ -446,9 +389,9 @@ impl Gitcl { || self.commit_date || self.commit_message || self.commit_timestamp - || self.describe - || self.sha - || self.dirty + || self.describe.is_some() + || self.sha.is_some() + || self.dirty.is_some() } /// Run at the given path @@ -626,18 +569,18 @@ impl Gitcl { } } - if self.describe { + if let Some(describe) = &self.describe { if let Ok(_value) = env::var(GIT_DESCRIBE_NAME) { add_default_map_entry(VergenKey::GitDescribe, cargo_rustc_env, cargo_warning); } else { let mut describe_cmd = String::from(DESCRIBE); - if self.describe_dirty { + if describe.dirty { describe_cmd.push_str(" --dirty"); } - if self.describe_tags { + if describe.tags { describe_cmd.push_str(" --tags"); } - if let Some(pattern) = self.describe_match_pattern { + if let Some(pattern) = describe.match_pattern { describe_cmd.push_str(" --match \""); describe_cmd.push_str(pattern); describe_cmd.push('\"'); @@ -651,12 +594,12 @@ impl Gitcl { } } - if self.sha { + if let Some(sha) = &self.sha { if let Ok(_value) = env::var(GIT_SHA_NAME) { add_default_map_entry(VergenKey::GitSha, cargo_rustc_env, cargo_warning); } else { let mut sha_cmd = String::from(SHA); - if self.sha_short { + if sha.short { sha_cmd.push_str(" --short"); } sha_cmd.push_str(" HEAD"); @@ -669,12 +612,12 @@ impl Gitcl { } } - if self.dirty { + if let Some(dirty) = &self.dirty { if let Ok(_value) = env::var(GIT_DIRTY_NAME) { add_default_map_entry(VergenKey::GitDirty, cargo_rustc_env, cargo_warning); } else { let mut dirty_cmd = String::from(DIRTY); - if !self.dirty_include_untracked { + if !dirty.include_untracked { dirty_cmd.push_str(" --untracked-files=no"); } let output = Self::run_cmd(&dirty_cmd, self.repo_path.as_ref())?; @@ -940,13 +883,13 @@ impl AddEntries for Gitcl { cargo_warning, ); } - if self.describe { + if self.describe.is_some() { add_default_map_entry(VergenKey::GitDescribe, cargo_rustc_env_map, cargo_warning); } - if self.sha { + if self.sha.is_some() { add_default_map_entry(VergenKey::GitSha, cargo_rustc_env_map, cargo_warning); } - if self.dirty { + if self.dirty.is_some() { add_default_map_entry(VergenKey::GitDirty, cargo_rustc_env_map, cargo_warning); } Ok(()) @@ -956,7 +899,7 @@ impl AddEntries for Gitcl { #[cfg(test)] mod test { - use super::{Gitcl, GitclBuilder}; + use super::Gitcl; use crate::Emitter; use anyhow::Result; use serial_test::serial; @@ -968,7 +911,7 @@ mod test { #[serial] #[allow(clippy::clone_on_copy, clippy::redundant_clone)] fn gitcl_clone_works() -> Result<()> { - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let another = gitcl.clone(); assert_eq!(another, gitcl); Ok(()) @@ -977,7 +920,7 @@ mod test { #[test] #[serial] fn gitcl_debug_works() -> Result<()> { - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let mut buf = vec![]; write!(buf, "{gitcl:?}")?; assert!(!buf.is_empty()); @@ -987,7 +930,7 @@ mod test { #[test] #[serial] fn gix_default() -> Result<()> { - let gitcl = GitclBuilder::default().build()?; + let gitcl = Gitcl::builder().build(); let emitter = Emitter::default().add_instructions(&gitcl)?.test_emit(); assert_eq!(0, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -1043,7 +986,7 @@ mod test { #[test] #[serial] fn git_all_idempotent() -> Result<()> { - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let emitter = Emitter::default() .idempotent() .add_instructions(&gitcl)? @@ -1057,7 +1000,7 @@ mod test { #[test] #[serial] fn git_all_idempotent_no_warn() -> Result<()> { - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let emitter = Emitter::default() .idempotent() .quiet() @@ -1073,7 +1016,7 @@ mod test { #[serial] fn git_all_at_path() -> Result<()> { let repo = TestRepos::new(false, false, false)?; - let mut gitcl = GitclBuilder::all_git()?; + let mut gitcl = Gitcl::all_git(); let _ = gitcl.at_path(repo.path()); let emitter = Emitter::default().add_instructions(&gitcl)?.test_emit(); assert_eq!(10, emitter.cargo_rustc_env_map().len()); @@ -1085,7 +1028,7 @@ mod test { #[test] #[serial] fn git_all() -> Result<()> { - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let emitter = Emitter::default().add_instructions(&gitcl)?.test_emit(); assert_eq!(10, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -1097,7 +1040,7 @@ mod test { #[serial] fn git_all_shallow_clone() -> Result<()> { let repo = TestRepos::new(false, false, true)?; - let mut gitcl = GitclBuilder::all_git()?; + let mut gitcl = Gitcl::all_git(); let _ = gitcl.at_path(repo.path()); let emitter = Emitter::default().add_instructions(&gitcl)?.test_emit(); assert_eq!(10, emitter.cargo_rustc_env_map().len()); @@ -1109,11 +1052,11 @@ mod test { #[test] #[serial] fn git_all_dirty_tags_short() -> Result<()> { - let gitcl = GitclBuilder::default() + let gitcl = Gitcl::builder() .all() .describe(true, true, None) .sha(true) - .build()?; + .build(); let emitter = Emitter::default().add_instructions(&gitcl)?.test_emit(); assert_eq!(10, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -1124,7 +1067,7 @@ mod test { #[test] #[serial] fn fails_on_bad_git_command() -> Result<()> { - let mut gitcl = GitclBuilder::all_git()?; + let mut gitcl = Gitcl::all_git(); let _ = gitcl.git_cmd(Some("this_is_not_a_git_cmd")); assert!(Emitter::default() .fail_on_error() @@ -1136,7 +1079,7 @@ mod test { #[test] #[serial] fn defaults_on_bad_git_command() -> Result<()> { - let mut gitcl = GitclBuilder::all_git()?; + let mut gitcl = Gitcl::all_git(); let _ = gitcl.git_cmd(Some("this_is_not_a_git_cmd")); let emitter = Emitter::default().add_instructions(&gitcl)?.test_emit(); assert_eq!(10, emitter.cargo_rustc_env_map().len()); @@ -1150,7 +1093,7 @@ mod test { fn bad_timestamp_defaults() -> Result<()> { let mut map = BTreeMap::new(); let mut warnings = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); assert!(gitcl .add_git_timestamp_entries( "this_is_not_a_git_cmd", @@ -1171,10 +1114,10 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some("1671809360"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::default() + let gitcl = Gitcl::builder() .commit_date(true) .commit_timestamp(true) - .build()?; + .build(); _ = Emitter::new() .idempotent() .add_instructions(&gitcl)? @@ -1208,7 +1151,7 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::default().commit_date(true).build()?; + let gitcl = Gitcl::builder().commit_date(true).build(); Emitter::new() .idempotent() .fail_on_error() @@ -1231,7 +1174,7 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::default().commit_date(true).build()?; + let gitcl = Gitcl::builder().commit_date(true).build(); Emitter::new() .idempotent() .add_instructions(&gitcl)? @@ -1254,7 +1197,7 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::default().commit_date(true).build()?; + let gitcl = Gitcl::builder().commit_date(true).build(); Emitter::new() .fail_on_error() .idempotent() @@ -1278,7 +1221,7 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::default().commit_date(true).build()?; + let gitcl = Gitcl::builder().commit_date(true).build(); Emitter::new() .idempotent() .add_instructions(&gitcl)? diff --git a/vergen-gitcl/src/lib.rs b/vergen-gitcl/src/lib.rs index 02f7368d..99d42432 100644 --- a/vergen-gitcl/src/lib.rs +++ b/vergen-gitcl/src/lib.rs @@ -59,22 +59,22 @@ //! //! ``` //! # use anyhow::Result; -//! # use vergen_gitcl::{Emitter, GitclBuilder}; -#![cfg_attr(feature = "build", doc = r"# use vergen_gitcl::BuildBuilder;")] -#![cfg_attr(feature = "cargo", doc = r"# use vergen_gitcl::CargoBuilder;")] -#![cfg_attr(feature = "rustc", doc = r"# use vergen_gitcl::RustcBuilder;")] -#![cfg_attr(feature = "si", doc = r"# use vergen_gitcl::SysinfoBuilder;")] +//! # use vergen_gitcl::{Emitter, Gitcl}; +#![cfg_attr(feature = "build", doc = r"# use vergen_gitcl::Build;")] +#![cfg_attr(feature = "cargo", doc = r"# use vergen_gitcl::Cargo;")] +#![cfg_attr(feature = "rustc", doc = r"# use vergen_gitcl::Rustc;")] +#![cfg_attr(feature = "si", doc = r"# use vergen_gitcl::Sysinfo;")] #![cfg_attr(feature = "cargo", doc = r"# use test_util::with_cargo_vars;")] //! # //! # pub fn main() -> Result<()> { #![cfg_attr(feature = "cargo", doc = r"# let result = with_cargo_vars(|| {")] //! // NOTE: This will output everything, and requires all features enabled. //! // NOTE: See the specific builder documentation for configuration options. -#![cfg_attr(feature = "build", doc = r"let build = BuildBuilder::all_build()?;")] -#![cfg_attr(feature = "cargo", doc = r"let cargo = CargoBuilder::all_cargo()?;")] -//! let gitcl = GitclBuilder::all_git()?; -#![cfg_attr(feature = "rustc", doc = r"let rustc = RustcBuilder::all_rustc()?;")] -#![cfg_attr(feature = "si", doc = r"let si = SysinfoBuilder::all_sysinfo()?;")] +#![cfg_attr(feature = "build", doc = r"let build = Build::all_build();")] +#![cfg_attr(feature = "cargo", doc = r"let cargo = Cargo::all_cargo();")] +//! let gitcl = Gitcl::all_git(); +#![cfg_attr(feature = "rustc", doc = r"let rustc = Rustc::all_rustc();")] +#![cfg_attr(feature = "si", doc = r"let si = Sysinfo::all_sysinfo();")] //! //! Emitter::default() #![cfg_attr(feature = "build", doc = r" .add_instructions(&build)?")] @@ -137,11 +137,11 @@ //! //! ``` //! # use anyhow::Result; -//! # use vergen_gitcl::{Emitter, GitclBuilder}; -#![cfg_attr(feature = "build", doc = r"# use vergen_gitcl::BuildBuilder;")] -#![cfg_attr(feature = "cargo", doc = r"# use vergen_gitcl::CargoBuilder;")] -#![cfg_attr(feature = "rustc", doc = r"# use vergen_gitcl::RustcBuilder;")] -#![cfg_attr(feature = "si", doc = r"# use vergen_gitcl::SysinfoBuilder;")] +//! # use vergen_gitcl::{Emitter, Gitcl}; +#![cfg_attr(feature = "build", doc = r"# use vergen_gitcl::Build;")] +#![cfg_attr(feature = "cargo", doc = r"# use vergen_gitcl::Cargo;")] +#![cfg_attr(feature = "rustc", doc = r"# use vergen_gitcl::Rustc;")] +#![cfg_attr(feature = "si", doc = r"# use vergen_gitcl::Sysinfo;")] #![cfg_attr(feature = "cargo", doc = r"# use test_util::with_cargo_vars;")] //! # //! # pub fn main() -> Result<()> { @@ -149,21 +149,21 @@ #![cfg_attr( feature = "build", doc = r"// NOTE: This will output only the instructions specified. -// NOTE: See the specific builder documentation for configuration options. -let build = BuildBuilder::default().build_timestamp(true).build()?;" +// NOTE: See the specific builder documentation for configuration options. +let build = Build::builder().build_timestamp(true).build();" )] #![cfg_attr( feature = "cargo", - doc = r"let cargo = CargoBuilder::default().opt_level(true).build()?;" + doc = r"let cargo = Cargo::builder().opt_level(true).build();" )] -//! let gitcl = GitclBuilder::default().commit_timestamp(true).build()?; +//! let gitcl = Gitcl::builder().commit_timestamp(true).build(); #![cfg_attr( feature = "rustc", - doc = r"let rustc = RustcBuilder::default().semver(true).build()?;" + doc = r"let rustc = Rustc::builder().semver(true).build();" )] #![cfg_attr( feature = "si", - doc = r"let si = SysinfoBuilder::default().cpu_core_count(true).build()?;" + doc = r"let si = Sysinfo::builder().cpu_core_count(true).build();" )] //! //! Emitter::default() @@ -209,7 +209,7 @@ let build = BuildBuilder::default().build_timestamp(true).build()?;" //! ``` //! //! ## Features -//! `vergen-gitcl` has four main feature toggles allowing you to customize your output. No features are enabled by default. +//! `vergen-gitcl` has four main feature toggles allowing you to customize your output. No features are enabled by default. //! You **must** specifically enable the features you wish to use. //! //! | Feature | Enables | diff --git a/vergen-gitcl/tests/git_output.rs b/vergen-gitcl/tests/git_output.rs index 72b23453..423c7b16 100644 --- a/vergen-gitcl/tests/git_output.rs +++ b/vergen-gitcl/tests/git_output.rs @@ -5,7 +5,7 @@ mod test_git_git2 { use serial_test::serial; use std::env::temp_dir; use temp_env::with_var; - use vergen_gitcl::{Emitter, GitclBuilder}; + use vergen_gitcl::{Emitter, Gitcl}; use test_util::TestRepos; @@ -140,7 +140,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_all_output_idempotent() -> Result<()> { let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::all_git()?; + let mut gitcl = Gitcl::all_git(); let _ = gitcl.at_path(temp_dir()); let failed = Emitter::default() .add_instructions(&gitcl)? @@ -155,7 +155,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_all_output_default_dir() -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -171,11 +171,11 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_flags_test_repo() -> Result<()> { let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default() + let mut gitcl = Gitcl::builder() .all() .describe(true, false, None) .sha(true) - .build()?; + .build(); let _ = gitcl.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&gitcl)? @@ -191,12 +191,12 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_flags_test_repo_local() -> Result<()> { let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default() + let mut gitcl = Gitcl::builder() .all() .describe(true, false, None) .sha(true) .use_local(true) - .build()?; + .build(); let _ = gitcl.at_path(repo.path()); let result = || -> Result { let failed = Emitter::default() @@ -229,10 +229,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_output_test_repo() -> Result<()> { let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default() - .all() - .describe(true, false, None) - .build()?; + let mut gitcl = Gitcl::builder().all().describe(true, false, None).build(); let _ = gitcl.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&gitcl)? @@ -248,10 +245,10 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_describe_all_test_repo() -> Result<()> { let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default() + let mut gitcl = Gitcl::builder() .all() .describe(true, true, Some("0.1.0")) - .build()?; + .build(); let _ = gitcl.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&gitcl)? @@ -266,11 +263,11 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_emit_at_test_repo() -> Result<()> { let repo = TestRepos::new(true, false, false)?; - let mut gitcl = GitclBuilder::default() + let mut gitcl = Gitcl::builder() .all() .describe(true, false, None) .sha(true) - .build()?; + .build(); let _ = gitcl.at_path(repo.path()); assert!(Emitter::default().add_instructions(&gitcl)?.emit().is_ok()); Ok(()) @@ -280,7 +277,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; use anyhow::Result; use serial_test::serial; use test_util::TestRepos; - use vergen_gitcl::{Emitter, GitclBuilder}; + use vergen_gitcl::{Emitter, Gitcl}; const GIT_DIRTY_TRUE_OUTPUT: &str = r"cargo:rustc-env=VERGEN_GIT_DIRTY=true"; const GIT_DIRTY_FALSE_OUTPUT: &str = r"cargo:rustc-env=VERGEN_GIT_DIRTY=false"; @@ -302,7 +299,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(false, false, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(false).build()?; + let mut gitcl = Gitcl::builder().dirty(false).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -322,7 +319,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(false, false, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(true).build()?; + let mut gitcl = Gitcl::builder().dirty(true).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -342,7 +339,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(false).build()?; + let mut gitcl = Gitcl::builder().dirty(false).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -362,7 +359,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(true).build()?; + let mut gitcl = Gitcl::builder().dirty(true).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -382,7 +379,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(false, true, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(false).build()?; + let mut gitcl = Gitcl::builder().dirty(false).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -402,7 +399,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(false, true, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(true).build()?; + let mut gitcl = Gitcl::builder().dirty(true).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -422,7 +419,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(false).build()?; + let mut gitcl = Gitcl::builder().dirty(false).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -442,7 +439,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::default().dirty(true).build()?; + let mut gitcl = Gitcl::builder().dirty(true).build(); let _ = gitcl.at_path(repo.path()); let _emitter = Emitter::default() .add_instructions(&gitcl)? @@ -459,7 +456,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_all_idempotent_output() -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let failed = Emitter::default() .idempotent() .add_instructions(&gitcl)? @@ -475,7 +472,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_all_idempotent_output_quiet() -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let failed = Emitter::default() .idempotent() .quiet() @@ -494,7 +491,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_BRANCH", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -516,7 +513,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -543,7 +540,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -570,7 +567,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -591,7 +588,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_COMMIT_DATE", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -615,7 +612,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -639,7 +636,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -661,7 +658,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_DESCRIBE", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -680,7 +677,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_SHA", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -699,7 +696,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_DIRTY", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gitcl = GitclBuilder::all_git()?; + let gitcl = Gitcl::all_git(); let _failed = Emitter::default() .add_instructions(&gitcl)? .emit_to(&mut stdout_buf)?; @@ -716,7 +713,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_cmd_override_works() -> Result<()> { let mut stdout_buf = vec![]; - let mut gitcl = GitclBuilder::all_git()?; + let mut gitcl = Gitcl::all_git(); let _ = gitcl.git_cmd(Some("git -v")); let failed = Emitter::default() .add_instructions(&gitcl)? diff --git a/vergen-gix/Cargo.toml b/vergen-gix/Cargo.toml index 13ba7cd4..833d61dc 100644 --- a/vergen-gix/Cargo.toml +++ b/vergen-gix/Cargo.toml @@ -39,7 +39,7 @@ si = ["vergen/si"] [dependencies] anyhow = "1.0.95" -derive_builder = "0.20.2" +bon = "3.3.2" gix = { version = "0.69.1", default-features = false, features = [ "revision", "interrupt", diff --git a/vergen-gix/src/gix/mod.rs b/vergen-gix/src/gix/mod.rs index a7341d5b..b44e3e8c 100644 --- a/vergen-gix/src/gix/mod.rs +++ b/vergen-gix/src/gix/mod.rs @@ -7,7 +7,6 @@ // modified, or distributed except according to those terms. use anyhow::{anyhow, Error, Result}; -use derive_builder::Builder as DeriveBuilder; use gix::{commit::describe::SelectRef, discover, head::Kind, Commit, Head, Id, Repository}; use std::{ env::{self, VarError}, @@ -18,6 +17,7 @@ use time::{ format_description::{self, well_known::Iso8601}, OffsetDateTime, UtcOffset, }; +use vergen_lib::git_config::{Describe, Dirty, Sha}; use vergen_lib::{ add_default_map_entry, add_map_entry, constants::{ @@ -46,10 +46,10 @@ use vergen_lib::{ /// /// ``` /// # use anyhow::Result; -/// # use vergen_gix::{Emitter, GixBuilder}; +/// # use vergen_gix::{Emitter, Gix}; /// # /// # fn main() -> Result<()> { -/// let gix = GixBuilder::all_git()?; +/// let gix = Gix::all_git(); /// Emitter::default().add_instructions(&gix)?.emit()?; /// # Ok(()) /// # } @@ -60,12 +60,12 @@ use vergen_lib::{ /// ``` /// # use anyhow::Result; /// # use std::env; -/// # use vergen_gix::{Emitter, GixBuilder}; +/// # use vergen_gix::{Emitter, Gix}; /// # /// # fn main() -> Result<()> { /// temp_env::with_var("VERGEN_GIT_BRANCH", Some("this is the branch I want output"), || { /// let result = || -> Result<()> { -/// let gix = GixBuilder::all_git()?; +/// let gix = Gix::all_git(); /// Emitter::default().add_instructions(&gix)?.emit()?; /// Ok(()) /// }(); @@ -74,11 +74,15 @@ use vergen_lib::{ /// # } /// ``` /// -#[derive(Clone, Debug, DeriveBuilder, PartialEq)] +#[derive(Clone, Debug, bon::Builder, PartialEq)] #[allow(clippy::struct_excessive_bools)] pub struct Gix { + /// Configures the default values. + /// If set to `true` all defaults are in "enabled" state. + /// If set to `false` all defaults are in "disabled" state. + #[builder(field)] + all: bool, /// An optional path to a repository. - #[builder(default = "None")] repo_path: Option, /// Emit the current git branch /// @@ -86,7 +90,7 @@ pub struct Gix { /// cargo:rustc-env=VERGEN_GIT_BRANCH= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] branch: bool, /// Emit the author email of the most recent commit /// @@ -94,7 +98,7 @@ pub struct Gix { /// cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_EMAIL= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_author_name: bool, /// Emit the author name of the most recent commit /// @@ -102,14 +106,14 @@ pub struct Gix { /// cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR_NAME= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_author_email: bool, /// Emit the total commit count to HEAD /// /// ```text /// cargo:rustc-env=VERGEN_GIT_COMMIT_COUNT= /// ``` - #[builder(default = "false")] + #[builder(default = all)] commit_count: bool, /// Emit the commit message of the latest commit /// @@ -117,7 +121,7 @@ pub struct Gix { /// cargo:rustc-env=VERGEN_GIT_COMMIT_MESSAGE= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_message: bool, /// Emit the commit date of the latest commit /// @@ -125,7 +129,7 @@ pub struct Gix { /// cargo:rustc-env=VERGEN_GIT_COMMIT_DATE= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_date: bool, /// Emit the commit timestamp of the latest commit /// @@ -133,7 +137,7 @@ pub struct Gix { /// cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP= /// ``` /// - #[builder(default = "false")] + #[builder(default = all)] commit_timestamp: bool, /// Emit the describe output /// @@ -144,17 +148,22 @@ pub struct Gix { /// Optionally, add the `dirty` or `tags` flag to describe. /// See [`git describe`](https://git-scm.com/docs/git-describe#_options) for more details /// - #[builder(default = "false", setter(custom))] - describe: bool, + /// ## `tags` /// Instead of using only the annotated tags, use any tag found in refs/tags namespace. - #[builder(default = "false", private)] - describe_tags: bool, + /// + /// ## `dirty` /// If the working tree has local modification "-dirty" is appended to it. - #[builder(default = "false", private)] - describe_dirty: bool, + /// + /// ## `match_pattern` /// Only consider tags matching the given glob pattern, excluding the "refs/tags/" prefix. - #[builder(default = "None", private)] - describe_match_pattern: Option<&'static str>, + #[builder( + required, + default = all.then(Describe::default), + with = |tags: bool, dirty: bool, match_pattern: Option<&'static str>| { + Some(Describe { tags, dirty, match_pattern }) + } + )] + describe: Option, /// Emit the SHA of the latest commit /// /// ```text @@ -164,11 +173,14 @@ pub struct Gix { /// Optionally, add the `short` flag to rev-parse. /// See [`git rev-parse`](https://git-scm.com/docs/git-rev-parse#_options_for_output) for more details. /// - #[builder(default = "false", setter(custom))] - sha: bool, + /// ## `short` /// Shortens the object name to a unique prefix - #[builder(default = "false", private)] - sha_short: bool, + #[builder( + required, + default = all.then(Sha::default), + with = |short: bool| Some(Sha { short }) + )] + sha: Option, /// Emit the dirty state of the git repository /// ```text /// cargo:rustc-env=VERGEN_GIT_DIRTY=(true|false) @@ -176,104 +188,36 @@ pub struct Gix { /// /// Optionally, include untracked files when determining the dirty status of the repository. /// - #[builder(default = "false", setter(custom))] - dirty: bool, + /// # `include_tracked` /// Should we include/ignore untracked files in deciding whether the repository is dirty. - #[builder(default = "false", private)] - dirty_include_untracked: bool, + #[builder( + required, + default = all.then(Dirty::default), + with = |include_untracked: bool| Some(Dirty { include_untracked }) + )] + dirty: Option, /// Enable local offset date/timestamp output - #[builder(default = "false")] + #[builder(default)] use_local: bool, } impl GixBuilder { - /// Emit all of the `VERGEN_GIT_*` instructions - /// - /// # Errors - /// The underlying build function can error - /// - pub fn all_git() -> Result { - Self::default() - .branch(true) - .commit_author_email(true) - .commit_author_name(true) - .commit_count(true) - .commit_date(true) - .commit_message(true) - .commit_timestamp(true) - .describe(false, false, None) - .sha(false) - .dirty(false) - .build() - .map_err(Into::into) - } - - /// Convenience method to setup the [`GixBuilder`] with all of the `VERGEN_GIT_*` instructions on - pub fn all(&mut self) -> &mut Self { - self.branch(true) - .commit_author_email(true) - .commit_author_name(true) - .commit_count(true) - .commit_date(true) - .commit_message(true) - .commit_timestamp(true) - .describe(false, false, None) - .sha(false) - .dirty(false) - } - - /// Emit the describe output - /// - /// ```text - /// cargo:rustc-env=VERGEN_GIT_DESCRIBE= - /// ``` - /// - /// Optionally, add the `dirty` or `tags` flag to describe. - /// See [`git describe`](https://git-scm.com/docs/git-describe#_options) for more details - /// - pub fn describe( - &mut self, - tags: bool, - dirty: bool, - matches: Option<&'static str>, - ) -> &mut Self { - self.describe = Some(true); - let _ = self.describe_tags(tags); - let _ = self.describe_dirty(dirty); - let _ = self.describe_match_pattern(matches); - self - } - - /// Emit the dirty state of the git repository - /// ```text - /// cargo:rustc-env=VERGEN_GIT_DIRTY=(true|false) - /// ``` - /// - /// Optionally, include untracked files when determining the dirty status of the repository. - /// - pub fn dirty(&mut self, include_untracked: bool) -> &mut Self { - self.dirty = Some(true); - let _ = self.dirty_include_untracked(include_untracked); - self - } - - /// Emit the SHA of the latest commit - /// - /// ```text - /// cargo:rustc-env=VERGEN_GIT_SHA= - /// ``` - /// - /// Optionally, add the `short` flag to rev-parse. - /// See [`git rev-parse`](https://git-scm.com/docs/git-rev-parse#_options_for_output) for more details. - /// - pub fn sha(&mut self, short: bool) -> &mut Self { - self.sha = Some(true); - let _ = self.sha_short(short); + /// Convenience method that switches the defaults of [`Git2Builder`] + /// to enable all of the `VERGEN_GIT_*` instructions. It can only be + /// called at the start of the building process, i.e. when no config + /// has been set yet to avoid overwrites. + pub fn all(mut self) -> Self { + self.all = true; self } } impl Gix { + /// Emit all of the `VERGEN_GIT_*` instructions + pub fn all_git() -> Self { + Self::builder().all().build() + } + fn any(&self) -> bool { self.branch || self.commit_author_email @@ -282,8 +226,8 @@ impl Gix { || self.commit_date || self.commit_message || self.commit_timestamp - || self.describe - || self.sha + || self.describe.is_some() + || self.sha.is_some() } /// Run at the given path @@ -404,18 +348,18 @@ impl Gix { } } - if self.describe { + if let Some(describe) = &self.describe { if let Ok(_value) = env::var(GIT_DESCRIBE_NAME) { add_default_map_entry(VergenKey::GitDescribe, cargo_rustc_env, cargo_warning); } else { - let describe_refs = if self.describe_tags { + let describe_refs = if describe.tags { SelectRef::AllTags } else { SelectRef::AnnotatedTags }; let describe = if let Some(mut fmt) = commit.describe().names(describe_refs).try_format()? { - if fmt.depth > 0 && self.describe_dirty { + if fmt.depth > 0 && describe.dirty { fmt.dirty_suffix = Some("dirty".to_string()); } fmt.to_string() @@ -426,11 +370,11 @@ impl Gix { } } - if self.sha { + if let Some(sha) = &self.sha { if let Ok(_value) = env::var(GIT_SHA_NAME) { add_default_map_entry(VergenKey::GitSha, cargo_rustc_env, cargo_warning); } else { - let id = if self.sha_short { + let id = if sha.short { commit.short_id()?.to_string() } else { commit.id().to_string() @@ -650,12 +594,13 @@ impl AddEntries for Gix { cargo_warning, ); } - if self.describe { + if self.describe.is_some() { add_default_map_entry(VergenKey::GitDescribe, cargo_rustc_env_map, cargo_warning); } - if self.sha { + if self.sha.is_some() { add_default_map_entry(VergenKey::GitSha, cargo_rustc_env_map, cargo_warning); } + Ok(()) } } @@ -665,7 +610,7 @@ impl AddEntries for Gix { mod test { use std::env::temp_dir; - use super::GixBuilder; + use super::Gix; use anyhow::Result; use serial_test::serial; use std::io::Write; @@ -677,7 +622,7 @@ mod test { #[serial] #[allow(clippy::clone_on_copy, clippy::redundant_clone)] fn gix_clone_works() -> Result<()> { - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let another = gix.clone(); assert_eq!(another, gix); Ok(()) @@ -686,7 +631,7 @@ mod test { #[test] #[serial] fn gix_debug_works() -> Result<()> { - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let mut buf = vec![]; write!(buf, "{gix:?}")?; assert!(!buf.is_empty()); @@ -696,7 +641,7 @@ mod test { #[test] #[serial] fn gix_default() -> Result<()> { - let gix = GixBuilder::default().build()?; + let gix = Gix::builder().build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(0, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -707,7 +652,7 @@ mod test { #[test] #[serial] fn git_all_idempotent() -> Result<()> { - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let emitter = Emitter::default() .idempotent() .add_instructions(&gix)? @@ -721,7 +666,7 @@ mod test { #[test] #[serial] fn git_all_idempotent_no_warn() -> Result<()> { - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let emitter = Emitter::default() .idempotent() .quiet() @@ -736,7 +681,7 @@ mod test { #[test] #[serial] fn git_all() -> Result<()> { - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(9, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -747,7 +692,7 @@ mod test { #[test] #[serial] fn git_branch() -> Result<()> { - let gix = GixBuilder::default().branch(true).build()?; + let gix = Gix::builder().branch(true).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -758,7 +703,7 @@ mod test { #[test] #[serial] fn git_commit_author_name() -> Result<()> { - let gix = GixBuilder::default().commit_author_name(true).build()?; + let gix = Gix::builder().commit_author_name(true).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -769,7 +714,7 @@ mod test { #[test] #[serial] fn git_commit_author_email() -> Result<()> { - let gix = GixBuilder::default().commit_author_email(true).build()?; + let gix = Gix::builder().commit_author_email(true).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -780,7 +725,7 @@ mod test { #[test] #[serial] fn git_commit_count() -> Result<()> { - let gix = GixBuilder::default().commit_count(true).build()?; + let gix = Gix::builder().commit_count(true).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -791,7 +736,7 @@ mod test { #[test] #[serial] fn git_commit_message() -> Result<()> { - let gix = GixBuilder::default().commit_message(true).build()?; + let gix = Gix::builder().commit_message(true).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -802,7 +747,7 @@ mod test { #[test] #[serial] fn git_commit_date() -> Result<()> { - let gix = GixBuilder::default().commit_date(true).build()?; + let gix = Gix::builder().commit_date(true).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -814,10 +759,7 @@ mod test { #[test] #[serial] fn git_commit_date_local() -> Result<()> { - let gix = GixBuilder::default() - .commit_date(true) - .use_local(true) - .build()?; + let gix = Gix::builder().commit_date(true).use_local(true).build(); let emitter = Emitter::default() .fail_on_error() .add_instructions(&gix)? @@ -831,7 +773,7 @@ mod test { #[test] #[serial] fn git_commit_timestamp() -> Result<()> { - let gix = GixBuilder::default().commit_timestamp(true).build()?; + let gix = Gix::builder().commit_timestamp(true).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -842,7 +784,7 @@ mod test { #[test] #[serial] fn git_describe() -> Result<()> { - let gix = GixBuilder::default().describe(true, false, None).build()?; + let gix = Gix::builder().describe(true, false, None).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -853,7 +795,7 @@ mod test { #[test] #[serial] fn git_sha() -> Result<()> { - let gix = GixBuilder::default().sha(false).build()?; + let gix = Gix::builder().sha(false).build(); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(1, emitter.cargo_rustc_env_map().len()); assert_eq!(0, count_idempotent(emitter.cargo_rustc_env_map())); @@ -865,7 +807,7 @@ mod test { #[serial] fn git_all_at_path() -> Result<()> { let repo = TestRepos::new(false, false, false)?; - let mut gix = GixBuilder::all_git()?; + let mut gix = Gix::all_git(); let _ = gix.at_path(repo.path()); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(9, emitter.cargo_rustc_env_map().len()); @@ -878,7 +820,7 @@ mod test { #[serial] fn git_all_shallow_clone() -> Result<()> { let repo = TestRepos::new(false, false, true)?; - let mut gix = GixBuilder::all_git()?; + let mut gix = Gix::all_git(); let _ = gix.at_path(repo.path()); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(9, emitter.cargo_rustc_env_map().len()); @@ -890,7 +832,7 @@ mod test { #[test] #[serial] fn git_error_fails() -> Result<()> { - let mut gix = GixBuilder::all_git()?; + let mut gix = Gix::all_git(); let _ = gix.at_path(temp_dir()); assert!(Emitter::default() .fail_on_error() @@ -902,7 +844,7 @@ mod test { #[test] #[serial] fn git_error_defaults() -> Result<()> { - let mut gix = GixBuilder::all_git()?; + let mut gix = Gix::all_git(); let _ = gix.at_path(temp_dir()); let emitter = Emitter::default().add_instructions(&gix)?.test_emit(); assert_eq!(9, emitter.cargo_rustc_env_map().len()); @@ -917,10 +859,10 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some("1671809360"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::default() + let gix = Gix::builder() .commit_date(true) .commit_timestamp(true) - .build()?; + .build(); _ = Emitter::new() .idempotent() .add_instructions(&gix)? @@ -953,7 +895,7 @@ mod test { let os_str = OsStr::from_bytes(&source[..]); temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result<()> { - let gix = GixBuilder::default().commit_date(true).build()?; + let gix = Gix::builder().commit_date(true).build(); Emitter::new() .idempotent() .fail_on_error() @@ -976,7 +918,7 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result { let mut stdout_buf = vec![]; - let gix = GixBuilder::default().commit_date(true).build()?; + let gix = Gix::builder().commit_date(true).build(); Emitter::new() .idempotent() .add_instructions(&gix)? @@ -999,7 +941,7 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result { let mut stdout_buf = vec![]; - let gix = GixBuilder::default().commit_date(true).build()?; + let gix = Gix::builder().commit_date(true).build(); Emitter::default() .fail_on_error() .idempotent() @@ -1023,7 +965,7 @@ mod test { temp_env::with_var("SOURCE_DATE_EPOCH", Some(os_str), || { let result = || -> Result { let mut stdout_buf = vec![]; - let gix = GixBuilder::default().commit_date(true).build()?; + let gix = Gix::builder().commit_date(true).build(); Emitter::default() .idempotent() .add_instructions(&gix)? diff --git a/vergen-gix/src/lib.rs b/vergen-gix/src/lib.rs index 439c1101..e2b363f9 100644 --- a/vergen-gix/src/lib.rs +++ b/vergen-gix/src/lib.rs @@ -59,22 +59,22 @@ //! //! ``` //! # use anyhow::Result; -//! # use vergen_gix::{Emitter, GixBuilder}; -#![cfg_attr(feature = "build", doc = r"# use vergen_gix::BuildBuilder;")] -#![cfg_attr(feature = "cargo", doc = r"# use vergen_gix::CargoBuilder;")] -#![cfg_attr(feature = "rustc", doc = r"# use vergen_gix::RustcBuilder;")] -#![cfg_attr(feature = "si", doc = r"# use vergen_gix::SysinfoBuilder;")] +//! # use vergen_gix::{Emitter, Gix}; +#![cfg_attr(feature = "build", doc = r"# use vergen_gix::Build;")] +#![cfg_attr(feature = "cargo", doc = r"# use vergen_gix::Cargo;")] +#![cfg_attr(feature = "rustc", doc = r"# use vergen_gix::Rustc;")] +#![cfg_attr(feature = "si", doc = r"# use vergen_gix::Sysinfo;")] #![cfg_attr(feature = "cargo", doc = r"# use test_util::with_cargo_vars;")] //! # //! # pub fn main() -> Result<()> { #![cfg_attr(feature = "cargo", doc = r"# let result = with_cargo_vars(|| {")] //! // NOTE: This will output everything, and requires all features enabled. //! // NOTE: See the specific builder documentation for configuration options. -#![cfg_attr(feature = "build", doc = r"let build = BuildBuilder::all_build()?;")] -#![cfg_attr(feature = "cargo", doc = r"let cargo = CargoBuilder::all_cargo()?;")] -//! let gitcl = GixBuilder::all_git()?; -#![cfg_attr(feature = "rustc", doc = r"let rustc = RustcBuilder::all_rustc()?;")] -#![cfg_attr(feature = "si", doc = r"let si = SysinfoBuilder::all_sysinfo()?;")] +#![cfg_attr(feature = "build", doc = r"let build = Build::all_build();")] +#![cfg_attr(feature = "cargo", doc = r"let cargo = Cargo::all_cargo();")] +//! let gitcl = Gix::all_git(); +#![cfg_attr(feature = "rustc", doc = r"let rustc = Rustc::all_rustc();")] +#![cfg_attr(feature = "si", doc = r"let si = Sysinfo::all_sysinfo();")] //! //! Emitter::default() #![cfg_attr(feature = "build", doc = r" .add_instructions(&build)?")] @@ -138,10 +138,10 @@ //! ``` //! # use anyhow::Result; //! # use vergen_gix::{Emitter, GixBuilder}; -#![cfg_attr(feature = "build", doc = r"# use vergen_gix::BuildBuilder;")] -#![cfg_attr(feature = "cargo", doc = r"# use vergen_gix::CargoBuilder;")] -#![cfg_attr(feature = "rustc", doc = r"# use vergen_gix::RustcBuilder;")] -#![cfg_attr(feature = "si", doc = r"# use vergen_gix::SysinfoBuilder;")] +#![cfg_attr(feature = "build", doc = r"# use vergen_gix::Build;")] +#![cfg_attr(feature = "cargo", doc = r"# use vergen_gix::Cargo;")] +#![cfg_attr(feature = "rustc", doc = r"# use vergen_gix::Rustc;")] +#![cfg_attr(feature = "si", doc = r"# use vergen_gix::Sysinfo;")] #![cfg_attr(feature = "cargo", doc = r"# use test_util::with_cargo_vars;")] //! # //! # pub fn main() -> Result<()> { @@ -149,21 +149,21 @@ #![cfg_attr( feature = "build", doc = r"// NOTE: This will output only the instructions specified. -// NOTE: See the specific builder documentation for configuration options. -let build = BuildBuilder::default().build_timestamp(true).build()?;" +// NOTE: See the specific builder documentation for configuration options. +let build = Build::builder().build_timestamp(true).build();" )] #![cfg_attr( feature = "cargo", - doc = r"let cargo = CargoBuilder::default().opt_level(true).build()?;" + doc = r"let cargo = Cargo::builder().opt_level(true).build();" )] -//! let gitcl = GixBuilder::default().commit_timestamp(true).build()?; +//! let gitcl = Gix::builder().commit_timestamp(true).build(); #![cfg_attr( feature = "rustc", - doc = r"let rustc = RustcBuilder::default().semver(true).build()?;" + doc = r"let rustc = Rustc::builder().semver(true).build();" )] #![cfg_attr( feature = "si", - doc = r"let si = SysinfoBuilder::default().cpu_core_count(true).build()?;" + doc = r"let si = Sysinfo::builder().cpu_core_count(true).build();" )] //! //! Emitter::default() @@ -209,7 +209,7 @@ let build = BuildBuilder::default().build_timestamp(true).build()?;" //! ``` //! //! ## Features -//! `vergen-gix` has four main feature toggles allowing you to customize your output. No features are enabled by default. +//! `vergen-gix` has four main feature toggles allowing you to customize your output. No features are enabled by default. //! You **must** specifically enable the features you wish to use. //! //! | Feature | Enables | @@ -459,9 +459,9 @@ mod gix; pub use crate::gix::Gix; pub use crate::gix::GixBuilder; #[cfg(feature = "build")] -pub use vergen::BuildBuilder; +pub use vergen::{Build, BuildBuilder}; #[cfg(feature = "cargo")] -pub use vergen::CargoBuilder; +pub use vergen::{Cargo, CargoBuilder}; #[cfg(feature = "si")] pub use vergen::CpuRefreshKind; #[cfg(feature = "cargo")] @@ -473,9 +473,9 @@ pub use vergen::ProcessRefreshKind; #[cfg(feature = "si")] pub use vergen::RefreshKind; #[cfg(feature = "rustc")] -pub use vergen::RustcBuilder; +pub use vergen::{Rustc, RustcBuilder}; #[cfg(feature = "si")] -pub use vergen::SysinfoBuilder; +pub use vergen::{Sysinfo, SysinfoBuilder}; pub use vergen_lib::AddCustomEntries; pub use vergen_lib::CargoRerunIfChanged; pub use vergen_lib::CargoWarning; diff --git a/vergen-gix/tests/git_output.rs b/vergen-gix/tests/git_output.rs index e2d04d5b..e8e44b32 100644 --- a/vergen-gix/tests/git_output.rs +++ b/vergen-gix/tests/git_output.rs @@ -6,7 +6,7 @@ mod test_git_gix { use std::env::{self, temp_dir}; use temp_env::with_var; use vergen::Emitter; - use vergen_gix::GixBuilder; + use vergen_gix::Gix; use test_util::TestRepos; @@ -134,7 +134,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_all_output_idempotent() -> Result<()> { let mut stdout_buf = vec![]; - let mut gix = GixBuilder::all_git()?; + let mut gix = Gix::all_git(); let _ = gix.at_path(temp_dir()); let failed = Emitter::default() .add_instructions(&gix)? @@ -149,7 +149,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_all_output_default_dir() -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -165,11 +165,11 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_flags_test_repo() -> Result<()> { let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut gix = GixBuilder::default() + let mut gix = Gix::builder() .all() .describe(true, false, None) .sha(true) - .build()?; + .build(); let _ = gix.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&gix)? @@ -185,12 +185,12 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_flags_test_repo_local() -> Result<()> { let repo = TestRepos::new(true, false, false)?; let mut stdout_buf = vec![]; - let mut gix = GixBuilder::default() + let mut gix = Gix::builder() .all() .describe(true, false, None) .sha(true) .use_local(true) - .build()?; + .build(); let _ = gix.at_path(repo.path()); let result = || -> Result { let failed = Emitter::default() @@ -223,7 +223,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; fn git_all_output_test_repo() -> Result<()> { let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut gix = GixBuilder::all_git()?; + let mut gix = Gix::all_git(); let _ = gix.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&gix)? @@ -240,10 +240,10 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; let repo = TestRepos::new(true, true, false)?; let mut stdout_buf = vec![]; - let mut gix = GixBuilder::default() + let mut gix = Gix::builder() .all() .describe(false, true, Some("0.1.0")) // Include only annotated tags - .build()?; + .build(); let _ = gix.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&gix)? @@ -255,10 +255,10 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; stdout_buf.clear(); - let mut gix = GixBuilder::default() + let mut gix = Gix::builder() .all() .describe(true, true, Some("0.2.0-rc1")) // Include both annotated and lightweight tags - .build()?; + .build(); let _ = gix.at_path(repo.path()); let failed = Emitter::default() .add_instructions(&gix)? @@ -275,11 +275,11 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_emit_at_test_repo() -> Result<()> { let repo = TestRepos::new(true, false, false)?; - let mut gix = GixBuilder::default() + let mut gix = Gix::builder() .all() .describe(true, false, None) .sha(true) - .build()?; + .build(); let _ = gix.at_path(repo.path()); assert!(Emitter::default().add_instructions(&gix)?.emit().is_ok()); Ok(()) @@ -289,7 +289,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial] fn git_all_idempotent_output() -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let failed = Emitter::default() .idempotent() .add_instructions(&gix)? @@ -305,7 +305,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; #[serial_test::serial] fn git_all_idempotent_output_quiet() -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let failed = Emitter::default() .idempotent() .quiet() @@ -324,7 +324,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_BRANCH", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -346,7 +346,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -373,7 +373,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -400,7 +400,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -421,7 +421,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_COMMIT_DATE", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -445,7 +445,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -469,7 +469,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -491,7 +491,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_DESCRIBE", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; @@ -510,7 +510,7 @@ cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"; with_var("VERGEN_GIT_SHA", Some("this is a bad date"), || { let result = || -> Result<()> { let mut stdout_buf = vec![]; - let gix = GixBuilder::all_git()?; + let gix = Gix::all_git(); let _failed = Emitter::default() .add_instructions(&gix)? .emit_to(&mut stdout_buf)?; diff --git a/vergen-lib/Cargo.toml b/vergen-lib/Cargo.toml index 9950358b..2f8a68cb 100644 --- a/vergen-lib/Cargo.toml +++ b/vergen-lib/Cargo.toml @@ -40,7 +40,7 @@ si = [] [dependencies] anyhow = "1.0.95" -derive_builder = "0.20.2" +bon = "3.3.2" [build-dependencies] rustversion = "1.0.19" diff --git a/vergen-lib/src/entries.rs b/vergen-lib/src/entries.rs index 20931576..e227c65d 100644 --- a/vergen-lib/src/entries.rs +++ b/vergen-lib/src/entries.rs @@ -118,11 +118,11 @@ pub trait Add { /// ## Then in [`build.rs`] /// /// ```will_not_compile -/// let build = BuildBuilder::all_build()?; -/// let cargo = CargoBuilder::all_cargo()?; -/// let gix = GixBuilder::all_git()?; -/// let rustc = RustcBuilder::all_rustc()?; -/// let si = SysinfoBuilder::all_sysinfo()?; +/// let build = Build::all_build(); +/// let cargo = Cargo::all_cargo(); +/// let gix = Gix::all_git(); +/// let rustc = Rustc::all_rustc(); +/// let si = Sysinfo::all_sysinfo(); /// Emitter::default() /// .add_instructions(&build)? /// .add_instructions(&cargo)? @@ -175,11 +175,10 @@ pub trait AddCustom + Ord, V: Into> { pub(crate) mod test_gen { use crate::{AddCustomEntries, CargoRerunIfChanged, CargoWarning}; use anyhow::{anyhow, Result}; - use derive_builder::Builder; use std::collections::BTreeMap; #[doc(hidden)] - #[derive(Builder, Clone, Copy, Debug, Default)] + #[derive(Clone, Copy, Debug, Default, bon::Builder)] pub struct CustomInsGen { fail: bool, } diff --git a/vergen-lib/src/git_config.rs b/vergen-lib/src/git_config.rs new file mode 100644 index 00000000..1a6cde46 --- /dev/null +++ b/vergen-lib/src/git_config.rs @@ -0,0 +1,18 @@ +//! Shared git configuration for different git libraries + +#[derive(Clone, Debug, PartialEq, Default)] +pub struct Describe { + pub tags: bool, + pub dirty: bool, + pub match_pattern: Option<&'static str>, +} + +#[derive(Clone, Debug, PartialEq, Default)] +pub struct Dirty { + pub include_untracked: bool, +} + +#[derive(Clone, Debug, PartialEq, Default)] +pub struct Sha { + pub short: bool, +} diff --git a/vergen-lib/src/lib.rs b/vergen-lib/src/lib.rs index 63f7e973..11da5142 100644 --- a/vergen-lib/src/lib.rs +++ b/vergen-lib/src/lib.rs @@ -220,6 +220,7 @@ use {temp_env as _, test_util as _}; pub mod constants; mod emitter; mod entries; +pub mod git_config; mod keys; mod utils; diff --git a/vergen-pretty/Cargo.toml b/vergen-pretty/Cargo.toml index c453b8b6..f758a6bc 100644 --- a/vergen-pretty/Cargo.toml +++ b/vergen-pretty/Cargo.toml @@ -42,7 +42,7 @@ __vergen_empty_test = ["vergen-gix", "vergen-gix/unstable"] anyhow = "1.0.95" console = { version = "0.15.10", optional = true } convert_case = "0.6.0" -derive_builder = "0.20.2" +bon = "3.3.2" lazy_static = { version = "1.5.0", optional = true } rand = { version = "0.8.5", optional = true } serde = { version = "1.0.217", features = ["derive"], optional = true } diff --git a/vergen-pretty/build.rs b/vergen-pretty/build.rs index c4aca42a..a68780fe 100644 --- a/vergen-pretty/build.rs +++ b/vergen-pretty/build.rs @@ -6,8 +6,8 @@ use vergen_gix::Emitter; use { std::collections::BTreeMap, vergen_gix::{ - AddCustomEntries, BuildBuilder, CargoBuilder, CargoRerunIfChanged, CargoWarning, - DefaultConfig, Emitter, GixBuilder, RustcBuilder, SysinfoBuilder, + AddCustomEntries, Build, Cargo, CargoRerunIfChanged, CargoWarning, + DefaultConfig, Emitter, Gix, Rustc, Sysinfo, }, }; @@ -68,11 +68,11 @@ impl AddCustomEntries<&str, &str> for Custom { #[cfg(all(feature = "__vergen_test", not(feature = "__vergen_empty_test")))] fn emit() -> Result<()> { println!("cargo:warning=VERGEN TEST ENABLED!"); - let build = BuildBuilder::all_build()?; - let cargo = CargoBuilder::all_cargo()?; - let gix = GixBuilder::all_git()?; - let rustc = RustcBuilder::all_rustc()?; - let si = SysinfoBuilder::all_sysinfo()?; + let build = Build::all_build(); + let cargo = Cargo::all_cargo(); + let gix = Gix::all_git(); + let rustc = Rustc::all_rustc(); + let si = Sysinfo::all_sysinfo(); Emitter::default() .add_instructions(&build)? .add_instructions(&cargo)? diff --git a/vergen-pretty/src/header/mod.rs b/vergen-pretty/src/header/mod.rs index cd0757cf..8fce4960 100644 --- a/vergen-pretty/src/header/mod.rs +++ b/vergen-pretty/src/header/mod.rs @@ -8,11 +8,11 @@ // Header -use crate::{Prefix, PrefixBuilder, PrettyBuilder, Suffix, SuffixBuilder}; +use crate::{Prefix, Pretty, Suffix}; use anyhow::Result; use console::Style; -use derive_builder::Builder; +use bon::Builder; #[cfg(feature = "color")] use rand::Rng; use std::{collections::BTreeMap, io::Write}; @@ -39,17 +39,17 @@ pub type Env = BTreeMap<&'static str, Option<&'static str>>; /// # Example /// ``` /// # use anyhow::Result; -/// # use vergen_pretty::{ConfigBuilder, header, vergen_pretty_env}; +/// # use vergen_pretty::{Config, header, vergen_pretty_env}; #[cfg_attr(feature = "color", doc = r"use vergen_pretty::Style;")] /// # /// # pub fn main() -> Result<()> { /// let mut buf = vec![]; -/// let config = ConfigBuilder::default() +/// let config = Config::builder() #[cfg_attr(feature = "color", doc = r" .style(Style::new().green())")] /// .prefix("HEADER_PREFIX") /// .env(vergen_pretty_env!()) /// .suffix("HEADER_SUFFIX") -/// .build()?; +/// .build(); /// assert!(header(&config, Some(&mut buf)).is_ok()); /// assert!(!buf.is_empty()); /// # Ok(()) @@ -63,16 +63,13 @@ pub struct Config { /// Use a random [`Style`] color for the output random_style: bool, #[cfg(feature = "color")] - #[builder(setter(into, strip_option), default)] /// Use the given [`Style`] for the output (mutually exclusive with `random_style`) style: Option