Skip to content

Commit

Permalink
Added enabled flag to feature config, to turn off feature programma…
Browse files Browse the repository at this point in the history
…tically (#67)

* added enabled flag to config, to turn off feature programmatically

* added serial to cargo tests to ensure env variable viability

* code coverage for has_enabled branches

* hopefully only one workflow on pull_request push

* ignore all tags

* ignore all tags
  • Loading branch information
CraZySacX authored Apr 24, 2021
1 parent f4f39d5 commit 179d804
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 14 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
on: [push, pull_request]
on:
# Trigger the workflow on push to master or any pull request
# Ignore all tags
push:
branches:
- master
tags-ignore: '*'
pull_request:
branches:
- '*'
tags-ignore: '*'

name: CI

Expand Down
27 changes: 26 additions & 1 deletion src/feature/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ vergen(config)?;
#[derive(Clone, Copy, Debug, Getters, MutGetters)]
#[getset(get = "pub(crate)", get_mut = "pub")]
pub struct Build {
/// Enable/Disable the build output
enabled: bool,
/// Enable/Disable the `VERGEN_BUILD_DATE`, `VERGEN_BUILD_TIME`, and `VERGEN_BUILD_TIMESTAMP` instructions.
timestamp: bool,
/// The timezone to use for the date/time instructions.
Expand All @@ -78,6 +80,7 @@ pub struct Build {
impl Default for Build {
fn default() -> Self {
Self {
enabled: true,
timestamp: true,
timezone: TimeZone::Utc,
kind: TimestampKind::Timestamp,
Expand All @@ -89,7 +92,7 @@ impl Default for Build {
#[cfg(feature = "build")]
impl Build {
pub(crate) fn has_enabled(self) -> bool {
self.timestamp || self.semver
self.enabled && (self.timestamp || self.semver)
}
}

Expand Down Expand Up @@ -195,6 +198,28 @@ mod test {
*config.build_mut().kind_mut() = TimestampKind::All;
assert_eq!(config.build().kind(), &TimestampKind::All);
}

#[test]
fn not_enabled() {
let mut config = Instructions::default();
*config.build_mut().enabled_mut() = false;
assert!(!config.build().has_enabled());
}

#[test]
fn no_timestamp() {
let mut config = Instructions::default();
*config.build_mut().timestamp_mut() = false;
assert!(config.build().has_enabled());
}

#[test]
fn nothing() {
let mut config = Instructions::default();
*config.build_mut().timestamp_mut() = false;
*config.build_mut().semver_mut() = false;
assert!(!config.build().has_enabled());
}
}

#[cfg(all(test, not(feature = "build")))]
Expand Down
36 changes: 35 additions & 1 deletion src/feature/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ vergen(config)?;
#[derive(Clone, Copy, Debug, Getters, MutGetters)]
#[getset(get = "pub(crate)", get_mut = "pub")]
pub struct Cargo {
/// Enable/Disable the cargo output
enabled: bool,
/// Enable/Disable the `VERGEN_CARGO_FEATURES` instruction
features: bool,
/// Enable/Disable the `VERGEN_CARGO_PROFILE` instruction
Expand All @@ -68,6 +70,7 @@ pub struct Cargo {
impl Default for Cargo {
fn default() -> Self {
Self {
enabled: true,
features: true,
profile: true,
target_triple: true,
Expand All @@ -78,7 +81,7 @@ impl Default for Cargo {
#[cfg(feature = "cargo")]
impl Cargo {
pub(crate) fn has_enabled(self) -> bool {
self.features || self.profile || self.target_triple
self.enabled && (self.features || self.profile || self.target_triple)
}
}

Expand Down Expand Up @@ -164,6 +167,37 @@ mod test {
assert!(!config.cargo().features);
teardown();
}

#[test]
fn not_enabled() {
let mut config = Instructions::default();
*config.cargo_mut().enabled_mut() = false;
assert!(!config.cargo().has_enabled());
}

#[test]
fn no_features() {
let mut config = Instructions::default();
*config.cargo_mut().features_mut() = false;
assert!(config.cargo().has_enabled());
}

#[test]
fn no_profile() {
let mut config = Instructions::default();
*config.cargo_mut().features_mut() = false;
*config.cargo_mut().profile_mut() = false;
assert!(config.cargo().has_enabled());
}

#[test]
fn nothing() {
let mut config = Instructions::default();
*config.cargo_mut().features_mut() = false;
*config.cargo_mut().profile_mut() = false;
*config.cargo_mut().target_triple_mut() = false;
assert!(!config.cargo().has_enabled());
}
}

#[cfg(all(test, not(feature = "cargo")))]
Expand Down
62 changes: 61 additions & 1 deletion src/feature/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ vergen(config)?;
#[derive(Clone, Copy, Debug, Getters, MutGetters)]
#[getset(get = "pub(crate)", get_mut = "pub")]
pub struct Git {
/// Enable/Disable the git output
enabled: bool,
/// Enable/Disable the `VERGEN_GIT_BRANCH` instruction
branch: bool,
/// Enable/Disable the `VERGEN_GIT_COMMIT_DATE`, `VERGEN_GIT_COMMIT_TIME`, and `VERGEN_GIT_COMMIT_TIMESTAMP` instructions
Expand All @@ -128,6 +130,7 @@ pub struct Git {
impl Default for Git {
fn default() -> Self {
Self {
enabled: true,
branch: true,
commit_timestamp: true,
commit_timestamp_timezone: feature::TimeZone::Utc,
Expand All @@ -144,7 +147,12 @@ impl Default for Git {
#[cfg(feature = "git")]
impl Git {
pub(crate) fn has_enabled(&self) -> bool {
self.branch || self.commit_timestamp || self.rerun_on_head_change || self.semver || self.sha
self.enabled
&& (self.branch
|| self.commit_timestamp
|| self.rerun_on_head_change
|| self.semver
|| self.sha)
}
}

Expand Down Expand Up @@ -374,6 +382,58 @@ mod test {
config.git_mut().commit_timestamp_kind = TimestampKind::All;
assert_eq!(config.git().commit_timestamp_kind, TimestampKind::All);
}

#[test]
fn not_enabled() {
let mut config = Instructions::default();
*config.git_mut().enabled_mut() = false;
assert!(!config.git().has_enabled());
}

#[test]
fn no_branch() {
let mut config = Instructions::default();
*config.git_mut().branch_mut() = false;
assert!(config.git().has_enabled());
}

#[test]
fn no_timestamp() {
let mut config = Instructions::default();
*config.git_mut().branch_mut() = false;
*config.git_mut().commit_timestamp_mut() = false;
assert!(config.git().has_enabled());
}

#[test]
fn no_rerun_on_head_change() {
let mut config = Instructions::default();
*config.git_mut().branch_mut() = false;
*config.git_mut().commit_timestamp_mut() = false;
*config.git_mut().rerun_on_head_change_mut() = false;
assert!(config.git().has_enabled());
}

#[test]
fn no_semver() {
let mut config = Instructions::default();
*config.git_mut().branch_mut() = false;
*config.git_mut().commit_timestamp_mut() = false;
*config.git_mut().rerun_on_head_change_mut() = false;
*config.git_mut().semver_mut() = false;
assert!(config.git().has_enabled());
}

#[test]
fn nothing() {
let mut config = Instructions::default();
*config.git_mut().branch_mut() = false;
*config.git_mut().commit_timestamp_mut() = false;
*config.git_mut().rerun_on_head_change_mut() = false;
*config.git_mut().semver_mut() = false;
*config.git_mut().sha_mut() = false;
assert!(!config.git().has_enabled());
}
}

#[cfg(all(test, not(feature = "git")))]
Expand Down
63 changes: 62 additions & 1 deletion src/feature/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ vergen(config)?;
#[cfg(feature = "rustc")]
#[derive(Clone, Copy, Debug, Getters, MutGetters)]
#[getset(get = "pub(crate)", get_mut = "pub")]
#[allow(clippy::struct_excessive_bools)]
pub struct Rustc {
/// Enable/Disable the rustc output
enabled: bool,
/// Enable/Disable the `VERGEN_RUSTC_CHANNEL` instruction
channel: bool,
/// Enable/Disable the `VERGEN_RUSTC_COMMIT_DATE` instruction
Expand All @@ -82,6 +85,7 @@ pub struct Rustc {
impl Default for Rustc {
fn default() -> Self {
Self {
enabled: true,
channel: true,
commit_date: true,
host_triple: true,
Expand All @@ -95,7 +99,12 @@ impl Default for Rustc {
#[cfg(feature = "rustc")]
impl Rustc {
pub(crate) fn has_enabled(self) -> bool {
self.channel || self.commit_date || self.host_triple || self.llvm_version || self.sha
self.enabled
&& (self.channel
|| self.commit_date
|| self.host_triple
|| self.llvm_version
|| self.sha)
}
}

Expand Down Expand Up @@ -186,6 +195,58 @@ mod test {
config.rustc_mut().host_triple = false;
assert!(!config.rustc().host_triple);
}

#[test]
fn not_enabled() {
let mut config = Instructions::default();
*config.rustc_mut().enabled_mut() = false;
assert!(!config.rustc().has_enabled());
}

#[test]
fn no_channel() {
let mut config = Instructions::default();
*config.rustc_mut().channel_mut() = false;
assert!(config.rustc().has_enabled());
}

#[test]
fn no_commit_date() {
let mut config = Instructions::default();
*config.rustc_mut().channel_mut() = false;
*config.rustc_mut().commit_date_mut() = false;
assert!(config.rustc().has_enabled());
}

#[test]
fn no_host_triple() {
let mut config = Instructions::default();
*config.rustc_mut().channel_mut() = false;
*config.rustc_mut().commit_date_mut() = false;
*config.rustc_mut().host_triple_mut() = false;
assert!(config.rustc().has_enabled());
}

#[test]
fn no_llvm_version() {
let mut config = Instructions::default();
*config.rustc_mut().channel_mut() = false;
*config.rustc_mut().commit_date_mut() = false;
*config.rustc_mut().host_triple_mut() = false;
*config.rustc_mut().llvm_version_mut() = false;
assert!(config.rustc().has_enabled());
}

#[test]
fn nothing() {
let mut config = Instructions::default();
*config.rustc_mut().channel_mut() = false;
*config.rustc_mut().commit_date_mut() = false;
*config.rustc_mut().host_triple_mut() = false;
*config.rustc_mut().llvm_version_mut() = false;
*config.rustc_mut().sha_mut() = false;
assert!(!config.rustc().has_enabled());
}
}

#[cfg(all(test, not(feature = "rustc")))]
Expand Down
Loading

0 comments on commit 179d804

Please sign in to comment.